org.bdware.client.Main Maven / Gradle / Ivy
The newest version!
package org.bdware.client;
import com.google.gson.JsonObject;
import org.bdware.client.ws.Action;
import org.zz.gmhelper.SM2KeyPair;
import org.zz.gmhelper.SM2Util;
public class Main {
public static void main(String[] args) throws InterruptedException {
if (args.length == 0 || args[0].equals("-h") || args[0].equals("--help")) {
printUsage(null);
return;
}
int port = 18000;
String ip = "127.0.0.1";
SM2KeyPair key = SM2Util.generateSM2KeyPair(null);
for (int i = 0; i < args.length; i += 2) {
if (i > args.length - 1) {
printUsage("Option parse error");
}
switch (args[i]) {
case "-port":
case "-p":
port = Integer.parseInt(args[i + 1]);
break;
case "-ip":
ip = (args[i + 1].replaceAll("ws://", ""));
break;
case "-generateSm2KeyPair":
case "-g":
System.out.println(SM2Util.generateSM2KeyPair(null).toJson());
break;
case "-k":
case "-sm2keypair":
key = SM2KeyPair.fromJson(args[i + 1]);
break;
}
}
String addr = "ws://" + ip + ":" + port + "/SCIDE/SCExecutor";
System.out.println("connect to:" + addr + " using pubKey:" + key.getPublicKeyStr());
SmartContractClient client =
new SmartContractClient(addr, key) {
@Override
public void onListContractProcess(JsonObject obj) {
System.exit(0);
}
@Action
public void onChangeNodeName(JsonObject obj) {
System.out.println(obj.toString());
}
@Action
public void onChangeNodeCenter(JsonObject obj) {
System.out.println(obj.toString());
}
@Action
public void onUpdateConfig(JsonObject obj) {
System.out.println(obj.toString());
}
};
client.waitForConnect();
client.login();
Thread.sleep(1000);
System.out.println("[Connected]");
for (int i = 0; i < args.length; i += 2) {
switch (args[i]) {
case "-setName":
client.setName(args[i + 1]);
break;
case "-setCluster":
client.setClusterAddress(args[i + 1]);
break;
case "-setMasterAddress":
client.setMasterAddress(args[i + 1]);
break;
case "-setBDLedger":
client.setBDLedger(args[i + 1]);
break;
case "-execute":
ContractRequest cr = new ContractRequest();
cr.setContractID(args[i + 1]);
cr.setAction(args[i + 2]);
cr.setArg(args[i + 3]);
JsonObject json = client.executeContractSync(cr);
System.out.println(json.toString());
break;
}
}
Thread.sleep(1000);
client.listContractProcess();
}
private static void printUsage(String msg) {
if (msg != null) {
System.out.println("Error: " + msg);
System.exit(1);
return;
}
System.out.println(
"Usage: java -cp \"./libs/:java-client.jar\" org.bdware.client.Main [-ip <127.0.0.1>] [-port/-p ] [-generateSm2KeyPair/-g ] [-sm2keypair/-k ] [-setName ] [-setCluster ] [-execute ]");
System.exit(1);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy