Skip to content

Commit

Permalink
implementing [#9]
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsonLazarin committed Dec 16, 2024
1 parent 231eae9 commit 539fd5c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 96 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>com.github.chon-group</groupId>
<artifactId>velluscinum</artifactId>
<version>24.8.27</version>
<version>24.12.16</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
64 changes: 21 additions & 43 deletions src/main/java/group/chon/velluscinum/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ public static void stampTransaction_CLI(String[] args){
KeyManagement keyManagement = new KeyManagement();
Transaction transaction = TransactionsApi.getTransactionById(args[4]);
result = bigchainDBDriver.stampTransaction(args[1],
keyManagement.importKeyFromFile(args[2]),
keyManagement.importKeyFromFile(args[3]),
keyManagement.importKeyFromFileOrContent(args[2]),
keyManagement.importKeyFromFileOrContent(args[3]),
transaction);
}catch (Exception ex){
System.out.println(ex);
Expand Down Expand Up @@ -423,28 +423,7 @@ private static void buildTransfer_CLI(String[] args){
}
transferInfo.transferToFile(args[1]+".transfer");
}
// private void buildTransfer(String[] args){
// Asset transferInfo = new Asset();
// if(args[2].length()!=0){
// String transferInfoStr = args[2];
// String[] pairKeyValueTransfer = transferInfoStr.split(";");
// for(int i=0; i< pairKeyValueTransfer.length; i++){
// String[] key_value = pairKeyValueTransfer[i].split(":");
// if(key_value.length==2){
// if(i==0){
// transferInfo.buildTransfer(key_value[0],key_value[1]);
// }else{
// transferInfo.addTransferInformation(key_value[0],key_value[1]);
// }
// }else{
// showManpage();
// }
// }
// }else{
// showManpage();
// }
// transferInfo.transferToFile(args[1]+".transfer");
// }


/**
* Creates two files with an ECDSA keyset in Base58
Expand Down Expand Up @@ -481,15 +460,16 @@ public static String[] buildWallet(){
* @param args [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE] [NFT-FILE]
*/
private static void deployNFT_CLI(String[] args) {
//[SERVER] [PRIVATEKEY-FILE] [PUBLICKEY-FILE] [NFT-FILE]
BigchainDBDriver bigchainDBDriver = new BigchainDBDriver();
KeyManagement keyManagement = new KeyManagement();
Asset asset = new Asset();
String strPrivateKey = keyManagement.importKeyFromFile(args[2]);
//[SERVER] [PRIVATEKEY-FILE] [PUBLICKEY-FILE] [NFT-FILE]
String strPrivateKey = keyManagement.importKeyFromFileOrContent(args[2]);

bigchainDBDriver.deployNFT(
args[1],
keyManagement.importKeyFromFile(args[2]),
keyManagement.importKeyFromFile(args[3]),
keyManagement.importKeyFromFileOrContent(args[2]),
keyManagement.importKeyFromFileOrContent(args[3]),
asset.importAssetFromFile(args[4]).toString());
}

Expand All @@ -502,12 +482,12 @@ private static void deployToken_CLI(String[] args){
BigchainDBDriver bigchainDBDriver = new BigchainDBDriver();
KeyManagement keyManagement = new KeyManagement();
Asset asset = new Asset();
String strPrivateKey = keyManagement.importKeyFromFile(args[2]);
//String strPrivateKey = keyManagement.importKeyFromFileOrContent(args[2]);
//[SERVER] [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE] [TOKEN-FILE] [AMOUNT]
String tokenId = bigchainDBDriver.deployToken(
args[1],
keyManagement.importKeyFromFile(args[2]),
keyManagement.importKeyFromFile(args[3]),
keyManagement.importKeyFromFileOrContent(args[2]),
keyManagement.importKeyFromFileOrContent(args[3]),
asset.importTransferFromFile(args[4]).toString(),
Long.parseLong(args[5])
);
Expand All @@ -526,11 +506,11 @@ private static void transferNFT_CLI(String[] args){
//[SERVER] [PRIVATEKEY-FILE] [PUBLICKEY-FILE] [ASSET-ID] [METADATA] [PUBLIC_DEST_KEY-FILE]
bigchainDBDriver.transferNFT(
args[1],
keyManagement.importKeyFromFile(args[2]),
keyManagement.importKeyFromFile(args[3]),
keyManagement.importKeyFromFileOrContent(args[2]),
keyManagement.importKeyFromFileOrContent(args[3]),
args[4],
transferAsset.importTransferFromFile(args[5]).toString(),
keyManagement.importKeyFromFile(args[6]));
keyManagement.importKeyFromFileOrContent(args[6]));
}

/**
Expand All @@ -540,15 +520,15 @@ private static void transferNFT_CLI(String[] args){
*/
private static void transferToken_CLI(String[] args){
BigchainDBDriver bigchainDBDriver = new BigchainDBDriver();
Asset transferAsset = new Asset();
//Asset transferAsset = new Asset();
KeyManagement keyManagement = new KeyManagement();
//[SERVER] [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE] [ASSET-ID] [DEST-PUBLIC-KEY-FILE] [AMOUNT]
bigchainDBDriver.transferToken(
args[1],
keyManagement.importKeyFromFile(args[2]),
keyManagement.importKeyFromFile(args[3]),
keyManagement.importKeyFromFileOrContent(args[2]),
keyManagement.importKeyFromFileOrContent(args[3]),
args[4],
keyManagement.importKeyFromFile(args[5]),
keyManagement.importKeyFromFileOrContent(args[5]),
Long.parseLong(args[6]));
}

Expand All @@ -560,14 +540,12 @@ private static void transferToken_CLI(String[] args){
*/
private static void walletBalance_CLI(String[] args){
KeyManagement keyManagement = new KeyManagement();

Wallet wallet = new Wallet();
ArrayList<WalletContent> walletContents = wallet.getMyTokens(
args[1],
keyManagement.importKeyFromFile(args[2]),
keyManagement.importKeyFromFile(args[3]));

System.out.println("Wallet Balance of: "+keyManagement.importKeyFromFile(args[3]));
keyManagement.importKeyFromFileOrContent(args[2]),
keyManagement.importKeyFromFileOrContent(args[3]));
System.out.println("Wallet Balance of: "+keyManagement.importKeyFromFileOrContent(args[2]));
System.out.println("T/NFT\tAsset QTD");
for(int i=0; i<walletContents.size(); i++){
System.out.println(walletContents.get(i).getType()+"\t"+walletContents.get(i).getToken()+" "+walletContents.get(i).getAmountAsString());
Expand Down
36 changes: 34 additions & 2 deletions src/main/java/group/chon/velluscinum/core/KeyManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.i2p.crypto.eddsa.KeyPairGenerator;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.spec.InvalidKeySpecException;
Expand Down Expand Up @@ -201,12 +202,43 @@ public EdDSAPublicKey stringToEdDSAPublicKey(String strPublicKey,
*
* @return A Key (Public OR Private) in String Base format.
*/
public String importKeyFromFile(String filePath){
private String importKeyFromFile(String filePath){
try {
return new String(Files.readAllBytes(Paths.get(filePath)));
String key = new String(Files.readAllBytes(Paths.get(filePath)));
if(isValidKey(key)){
return key;
}else{
throw new IllegalArgumentException("Invalid Key into file: " + filePath);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public String importKeyFromFileOrContent(String input) {
Path filePath = Paths.get(input);
if (Files.exists(filePath)) {
return importKeyFromFile(input);
} else if(isValidKey(input)) {
return input;
}else{
throw new IllegalArgumentException("Invalid argument: " + input);
}
}

private boolean isValidKey(String input) {
if(stringToEdDSAPrivateKey(input,BASE58)!=null){
return true;
}else if(stringToEdDSAPublicKey(input,BASE58)!=null){
return true;
}else if(stringToEdDSAPrivateKey(input,BASE64)!=null){
return true;
} else if(stringToEdDSAPublicKey(input,BASE64)!=null){
return true;
}else{
System.out.println("The Key "+input+" is wrong!!!!");
return false;
}
}

}
49 changes: 1 addition & 48 deletions src/main/resources/manpage.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,3 @@
*********************************************************************************
[Velluscinum] Using version 24.7.23
For more information
Look the User Manual at https://github.com/chon-group/Velluscinum/wiki
*********************************************************************************

* How to build an Asset?
java -jar velluscinum.jar buildAsset [FILENAME] [Immutable:Data] [Additional:Information]
example:
java -jar velluscinum.jar buildAsset pieceOfArt "name:Meninas;author:Diego_Velázquez;year:1656" "value_eur:25000000;owner:Bob"

* How to build a Transfer?
java -jar velluscinum.jar buildTransfer [FILENAME] [Transfer:Information]
example:
java -jar velluscinum.jar buildTransfer sale "value_eur:27500000;new owner:Alice"

* How to build a Wallet?
java -jar velluscinum.jar buildWallet [FILENAME]
example:
java -jar velluscinum.jar buildWallet bob

* How to CREATE a Non-Fungible-Token?
java -jar velluscinum.jar deployNFT [SERVER] [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE] [NFT-FILE]
example:
java -jar velluscinum.jar deployNFT "http://testchain.chon.group:9984" bob.privateKey bob.publicKey pieceOfArt.asset

* How to CREATE a Token?
java -jar velluscinum.jar deployToken [SERVER] [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE] [TOKEN-FILE] [AMOUNT]
example:
java -jar velluscinum.jar deployToken "http://testchain.chon.group:9984" bob.privateKey bob.publicKey myCoin.asset 1000

* How to TRANSFER a Non-Fungible-Token?
java -jar velluscinum.jar transferNFT [SERVER] [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE] [ASSET-ID] [TRANSFER-FILE] [DEST-PUBLIC-KEY-FILE]
example:
java -jar velluscinum.jar transferNFT "http://testchain.chon.group:9984" bob.privateKey bob.publicKey 76159024d31feacb0936be45a4b4100cafebbe988fbaab2bedc39d01e4d35b5f sale.transfer alice.publicKey

* How to TRANSFER a Token?
java -jar velluscinum.jar transferToken [SERVER] [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE] [ASSET-ID] [DEST-PUBLIC-KEY-FILE] [AMOUNT]
example:
java -jar velluscinum.jar transferToken "http://testchain.chon.group:9984" bob.privateKey bob.publicKey e5aa229ed58fb62c39908ace614be6d91b95cadeb2e66b47bc0858b06895110d alice.publicKey 50

* How to consult the balance of a Wallet?
java -jar velluscinum.jar walletBalance [SERVER] [PRIVATE-KEY-FILE] [PUBLIC-KEY-FILE]
example:
java -jar velluscinum.jar walletBalance "http://testchain.chon.group:9984" bob.privateKey bob.publicKey

* How to consult an Asset ?
java -jar velluscinum.jar showToken [SERVER] [ASSETID]
example:
java -jar velluscinum.jar showToken "http://testchain.chon.group:9984" "a415dbc28fe18f45227e5016601e23c34d27c9951380d9fe8b8a46520441b038"
*********************************************************************************

0 comments on commit 539fd5c

Please sign in to comment.