build: config spotless plugin and reformat code

This commit is contained in:
Frank.R.Wu 2023-06-15 11:31:11 +08:00
parent d8c3d1753b
commit dc30a32a34
18 changed files with 263 additions and 320 deletions

View File

@ -4,6 +4,9 @@ plugins {
id 'maven-publish' id 'maven-publish'
id 'signing' id 'signing'
} }
apply from: '../spotless.gradle'
group 'org.bdware.bdcontract' group 'org.bdware.bdcontract'
version '1.0.2' version '1.0.2'
sourceCompatibility = 1.8 sourceCompatibility = 1.8

View File

@ -5,11 +5,13 @@ import org.zz.gmhelper.SM2KeyPair;
public class AutoRegister { public class AutoRegister {
public static void main(String[] args) { public static void main(String[] args) {
String keyPairStr = "{\"privateKey\":\"347caf3393482440cf5a79995b2c83f567644dfa9b4804755bd093141542db96\",\"publicKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\"}"; String keyPairStr =
// "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"; "{\"privateKey\":\"347caf3393482440cf5a79995b2c83f567644dfa9b4804755bd093141542db96\",\"publicKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\"}";
//; "{\"privateKey\":\"b1f6223a49b9e0943016505e932a17ea0bfe357f3b23cae28f847db9566d30cf\",\"publicKey\":\"0469344c29715c32f0f45765f9446c6208eb1f9ce2c2b765a1c6a7f50e0f8fdb904be2acbaa41898e25144aa5740f5c1dfccdd8bc7fff193dee94269853b1d476b\"}"; // "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
// ;
// "{\"privateKey\":\"b1f6223a49b9e0943016505e932a17ea0bfe357f3b23cae28f847db9566d30cf\",\"publicKey\":\"0469344c29715c32f0f45765f9446c6208eb1f9ce2c2b765a1c6a7f50e0f8fdb904be2acbaa41898e25144aa5740f5c1dfccdd8bc7fff193dee94269853b1d476b\"}";
SM2KeyPair keyPair = SM2KeyPair.fromJson(keyPairStr); SM2KeyPair keyPair = SM2KeyPair.fromJson(keyPairStr);
String[] ips = new String[]{"10.10.133.38", "10.10.133.55", "10.10.133.56", "10.10.133.5"}; String[] ips = new String[] {"10.10.133.38", "10.10.133.55", "10.10.133.56", "10.10.133.5"};
for (String ip : ips) { for (String ip : ips) {
initialize(ip, 21030, keyPair); initialize(ip, 21030, keyPair);
} }
@ -19,28 +21,27 @@ public class AutoRegister {
String local = "ws://" + ip + ":" + port + "/SCIDE/SCExecutor"; String local = "ws://" + ip + ":" + port + "/SCIDE/SCExecutor";
System.out.println("config:" + ip + ":" + port); System.out.println("config:" + ip + ":" + port);
SmartContractClient testClient = SmartContractClient testClient = new SmartContractClient(local, keyPair) {
new SmartContractClient(local, keyPair) { public void onListContractProcess(JsonObject obj) {
public void onListContractProcess(JsonObject obj) { super.onListContractProcess(obj);
super.onListContractProcess(obj); }
}
public void onLogin(JsonObject obj) { public void onLogin(JsonObject obj) {
this.setName("Node_" + port); this.setName("Node_" + port);
this.setBDLedger("127.0.0.1:18030"); this.setBDLedger("127.0.0.1:18030");
this.setMasterAddress(ip + ":" + (port + 1)); this.setMasterAddress(ip + ":" + (port + 1));
String apply = String apply =
"{\"action\":\"applyNodeRole\",\"role\":\"_ROLE_\",\"pubKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"; "{\"action\":\"applyNodeRole\",\"role\":\"_ROLE_\",\"pubKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
this.sendMsg(apply.replaceAll("_ROLE_", "ContractProvider")); this.sendMsg(apply.replaceAll("_ROLE_", "ContractProvider"));
this.sendMsg(apply.replaceAll("_ROLE_", "ContractUser")); this.sendMsg(apply.replaceAll("_ROLE_", "ContractUser"));
this.sendMsg(apply.replaceAll("_ROLE_", "ContractInstanceManager")); this.sendMsg(apply.replaceAll("_ROLE_", "ContractInstanceManager"));
String auth = String auth =
"{\"action\":\"authNodeRole\",\"pubKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\",\"isAccept\":true}"; "{\"action\":\"authNodeRole\",\"pubKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\",\"isAccept\":true}";
this.sendMsg(auth); this.sendMsg(auth);
this.setClusterAddress("ws://10.10.133.38:18002"); this.setClusterAddress("ws://10.10.133.38:18002");
this.listContractProcess(); this.listContractProcess();
} }
}; };
testClient.waitForConnect(); testClient.waitForConnect();
testClient.login(); testClient.login();
try { try {

View File

@ -4,6 +4,7 @@ import com.google.gson.JsonObject;
import org.bdware.client.ws.Action; import org.bdware.client.ws.Action;
import org.zz.gmhelper.SM2KeyPair; import org.zz.gmhelper.SM2KeyPair;
import org.zz.gmhelper.SM2Util; import org.zz.gmhelper.SM2Util;
public class Main { public class Main {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
if (args.length == 0 || args[0].equals("-h") || args[0].equals("--help")) { if (args.length == 0 || args[0].equals("-h") || args[0].equals("--help")) {
@ -37,28 +38,27 @@ public class Main {
} }
String addr = "ws://" + ip + ":" + port + "/SCIDE/SCExecutor"; String addr = "ws://" + ip + ":" + port + "/SCIDE/SCExecutor";
System.out.println("connect to:" + addr + " using pubKey:" + key.getPublicKeyStr()); System.out.println("connect to:" + addr + " using pubKey:" + key.getPublicKeyStr());
SmartContractClient client = SmartContractClient client = new SmartContractClient(addr, key) {
new SmartContractClient(addr, key) { @Override
@Override public void onListContractProcess(JsonObject obj) {
public void onListContractProcess(JsonObject obj) { System.exit(0);
System.exit(0); }
}
@Action @Action
public void onChangeNodeName(JsonObject obj) { public void onChangeNodeName(JsonObject obj) {
System.out.println(obj.toString()); System.out.println(obj.toString());
} }
@Action @Action
public void onChangeNodeCenter(JsonObject obj) { public void onChangeNodeCenter(JsonObject obj) {
System.out.println(obj.toString()); System.out.println(obj.toString());
} }
@Action @Action
public void onUpdateConfig(JsonObject obj) { public void onUpdateConfig(JsonObject obj) {
System.out.println(obj.toString()); System.out.println(obj.toString());
} }
}; };
client.waitForConnect(); client.waitForConnect();
client.login(); client.login();
Thread.sleep(1000); Thread.sleep(1000);

View File

@ -134,13 +134,9 @@ public class ContractRequest extends SM2Verifiable
@Override @Override
public String getContentStr() { public String getContentStr() {
return String.format( return String.format("%s|%s|%s%s|%s",
"%s|%s|%s%s|%s",
(contractDOI != null && contractDOI.length() > 0) ? contractDOI : contractID, (contractDOI != null && contractDOI.length() > 0) ? contractDOI : contractID,
action, action, parseArg(), gasLimit > 0 ? "|" + gasLimit : "", requester);
parseArg(),
gasLimit > 0 ? "|" + gasLimit : "",
requester);
} }
private String parseArg() { private String parseArg() {

View File

@ -4,10 +4,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.bdware.client.ws.BaseClient; import org.bdware.client.ws.BaseClient;
import org.bdware.client.ws.Handler; import org.bdware.client.ws.Handler;
import org.bouncycastle.crypto.CryptoException;
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
import org.zz.gmhelper.SM2KeyPair;
import org.zz.gmhelper.SM2Util;
import javax.websocket.ClientEndpointConfig; import javax.websocket.ClientEndpointConfig;
import javax.websocket.ContainerProvider; import javax.websocket.ContainerProvider;
@ -24,9 +20,8 @@ public class EventSubscriberClient implements Handler {
public EventSubscriberClient(String uri) { public EventSubscriberClient(String uri) {
try { try {
bc = new BaseClient(this); bc = new BaseClient(this);
ContainerProvider.getWebSocketContainer() ContainerProvider.getWebSocketContainer().connectToServer(bc,
.connectToServer( ClientEndpointConfig.Builder.create().build(), URI.create(uri));
bc, ClientEndpointConfig.Builder.create().build(), URI.create(uri));
} catch (DeploymentException | IOException e) { } catch (DeploymentException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -46,23 +41,23 @@ public class EventSubscriberClient implements Handler {
e.printStackTrace(); e.printStackTrace();
} }
} }
// Map<String, String> setNodeID = new HashMap<>(); // Map<String, String> setNodeID = new HashMap<>();
// setNodeID.put("action", "setNodeID"); // setNodeID.put("action", "setNodeID");
// SM2KeyPair keyPair = SM2Util.generateSM2KeyPair(null); // SM2KeyPair keyPair = SM2Util.generateSM2KeyPair(null);
// setNodeID.put("id", keyPair.getPublicKeyStr()); // setNodeID.put("id", keyPair.getPublicKeyStr());
// //
// byte[] sig; // byte[] sig;
// try { // try {
// sig = // sig =
// SM2Util.sign( // SM2Util.sign(
// keyPair.getPrivateKeyParameter(), keyPair.getPublicKeyStr().getBytes()); // keyPair.getPrivateKeyParameter(), keyPair.getPublicKeyStr().getBytes());
// setNodeID.put("signature", ByteUtils.toHexString(sig)); // setNodeID.put("signature", ByteUtils.toHexString(sig));
// //
// } catch (CryptoException e) { // } catch (CryptoException e) {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// setNodeID.put("nodeName", "[LiteClient_" + System.currentTimeMillis() + "]"); // setNodeID.put("nodeName", "[LiteClient_" + System.currentTimeMillis() + "]");
// bc.sendText(new Gson().toJson(setNodeID)); // bc.sendText(new Gson().toJson(setNodeID));
} }
public void subscribeEvent(String contractID, String topic) { public void subscribeEvent(String contractID, String topic) {

View File

@ -29,10 +29,8 @@ public abstract class SM2Verifiable {
try { try {
setPublicKey(pair.getPublicKeyStr()); setPublicKey(pair.getPublicKeyStr());
signature = signature = ByteUtils.toHexString(
ByteUtils.toHexString( SM2Util.sign(pair.getPrivateKeyParameter(), getContentStr().getBytes()));
SM2Util.sign(
pair.getPrivateKeyParameter(), getContentStr().getBytes()));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -41,11 +39,10 @@ public abstract class SM2Verifiable {
public boolean verifySignature() { public boolean verifySignature() {
try { try {
String verifiedStr = getContentStr(); String verifiedStr = getContentStr();
ECPublicKeyParameters pubKey = ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyFromStrParameters(
BCECUtil.createECPublicKeyFromStrParameters( getPublicKey(), SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
getPublicKey(), SM2Util.CURVE, SM2Util.DOMAIN_PARAMS); return SM2Util.verify(pubKey, verifiedStr.getBytes(),
return SM2Util.verify( ByteUtils.fromHexString(signature));
pubKey, verifiedStr.getBytes(), ByteUtils.fromHexString(signature));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -38,9 +38,8 @@ public class SmartContractClient extends SmartContractHandler {
keyPair = pair; keyPair = pair;
bc = new BaseClient(this); bc = new BaseClient(this);
this.uri = uri; this.uri = uri;
ContainerProvider.getWebSocketContainer() ContainerProvider.getWebSocketContainer().connectToServer(bc,
.connectToServer( ClientEndpointConfig.Builder.create().build(), URI.create(uri));
bc, ClientEndpointConfig.Builder.create().build(), URI.create(uri));
} catch (DeploymentException | IOException e) { } catch (DeploymentException | IOException e) {
e.printStackTrace(); e.printStackTrace();
System.err.println("[Connect failed]:" + uri); System.err.println("[Connect failed]:" + uri);
@ -145,9 +144,8 @@ public class SmartContractClient extends SmartContractHandler {
String msg = "{\"action\":\"login\",\"signature\":\""; String msg = "{\"action\":\"login\",\"signature\":\"";
String signature = null; String signature = null;
try { try {
signature = signature = ByteUtils.toHexString(
ByteUtils.toHexString( SM2Util.sign(keyPair.getPrivateKeyParameter(), session.getBytes()));
SM2Util.sign(keyPair.getPrivateKeyParameter(), session.getBytes()));
} catch (CryptoException e) { } catch (CryptoException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -236,32 +234,17 @@ public class SmartContractClient extends SmartContractHandler {
} }
public String getExecuteUrl(ContractRequest cr) { public String getExecuteUrl(ContractRequest cr) {
return uri.replaceFirst("ws://", "http://") return uri.replaceFirst("ws://", "http://").replaceFirst("/SCIDE/SCExecutor",
.replaceFirst("/SCIDE/SCExecutor", "/SCIDE/CMManager?") "/SCIDE/CMManager?") + "action=executeContract" + "&contractID="
+ "action=executeContract" + cr.getContractID() + "&pubkey=" + cr.getPublicKey() + "&operation="
+ "&contractID=" + cr.getAction() + "&arg=" + cr.getArg() + "&signature=" + cr.signature;
+ cr.getContractID()
+ "&pubkey="
+ cr.getPublicKey()
+ "&operation="
+ cr.getAction()
+ "&arg="
+ cr.getArg()
+ "&signature="
+ cr.signature;
} }
public String getExecuteUrlNoSign(ContractRequest cr) { public String getExecuteUrlNoSign(ContractRequest cr) {
return uri.replaceFirst("ws://", "http://") return uri.replaceFirst("ws://", "http://").replaceFirst("/SCIDE/SCExecutor",
.replaceFirst("/SCIDE/SCExecutor", "/SCIDE/CMManager") "/SCIDE/CMManager") + "?action=executeContract" + "&contractID="
+ "?action=executeContract" + cr.getContractID() + "&operation=" + cr.getAction() + "&arg=" + cr.getArg();
+ "&contractID="
+ cr.getContractID()
+ "&operation="
+ cr.getAction()
+ "&arg="
+ cr.getArg();
} }
public void setClusterAddress(String addr) { public void setClusterAddress(String addr) {

View File

@ -17,17 +17,14 @@ public abstract class SmartContractHandler implements Handler {
public SmartContractHandler() { public SmartContractHandler() {
methodMap = new HashMap<>(); methodMap = new HashMap<>();
for (Class<?> clz = this.getClass(); for (Class<?> clz = this.getClass(); clz != null && clz != Object.class; clz =
clz != null && clz != Object.class; clz.getSuperclass()) {
clz = clz.getSuperclass()) {
for (Method m : clz.getDeclaredMethods()) { for (Method m : clz.getDeclaredMethods()) {
String actionName = getActionName(clz, m); String actionName = getActionName(clz, m);
if (actionName != null && !methodMap.containsKey(actionName)) { if (actionName != null && !methodMap.containsKey(actionName)) {
m.setAccessible(true); m.setAccessible(true);
LOGGER.debug( LOGGER.debug(String.format("addAction: %s %s.%s", actionName,
String.format( clz.getCanonicalName(), m.getName()));
"addAction: %s %s.%s",
actionName, clz.getCanonicalName(), m.getName()));
methodMap.put(actionName, m); methodMap.put(actionName, m);
} }
} }
@ -51,8 +48,10 @@ public abstract class SmartContractHandler implements Handler {
} }
} }
if (action != null) { if (action != null) {
if (action.name().length() > 0) return action.name(); if (action.name().length() > 0)
else return m.getName(); return action.name();
else
return m.getName();
} }
return null; return null;
} }
@ -93,7 +92,7 @@ public abstract class SmartContractHandler implements Handler {
@Override @Override
public void handle(JsonObject obj) { public void handle(JsonObject obj) {
try { try {
// LOGGER.info("receive:" + obj); // LOGGER.info("receive:" + obj);
if (!obj.has("action")) { if (!obj.has("action")) {
LOGGER.warn("can't handle message without action: " + obj); LOGGER.warn("can't handle message without action: " + obj);
} }

View File

@ -35,19 +35,16 @@ public class SmartContractHttpClient {
public static String getExecuteUrl(String ip, int port, ContractRequest cr) { public static String getExecuteUrl(String ip, int port, ContractRequest cr) {
try { try {
String str; String str;
if (cr.getArg() == null) str = ""; if (cr.getArg() == null)
str = "";
else if (cr.getArg().isJsonPrimitive()) else if (cr.getArg().isJsonPrimitive())
str = cr.getArg().getAsString(); str = cr.getArg().getAsString();
else str = cr.getArg().toString(); else
str = cr.getArg().toString();
return String.format( return String.format(
"http://%s:%d/SCIDE/CMManager?action=executeContract&contractID=%s&operation=%s&arg=%s&pubkey=%s&signature=%s", "http://%s:%d/SCIDE/CMManager?action=executeContract&contractID=%s&operation=%s&arg=%s&pubkey=%s&signature=%s",
ip, ip, port, cr.getContractID(), cr.getAction(), URLEncoder.encode(str, "utf-8"),
port, cr.getPublicKey(), cr.signature);
cr.getContractID(),
cr.getAction(),
URLEncoder.encode(str, "utf-8"),
cr.getPublicKey(),
cr.signature);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;

View File

@ -15,11 +15,13 @@ public class TimeoutUtil {
@Override @Override
public Object call() throws Exception { public Object call() throws Exception {
Class clz = Class.forName("org.bdware.sc.boundry.JavaScriptEntry"); Class clz = Class.forName("org.bdware.sc.boundry.JavaScriptEntry");
Class scriptFunction = Class.forName("wrp.jdk.nashorn.internal.runtime.ScriptFunction"); Class scriptFunction =
Class.forName("wrp.jdk.nashorn.internal.runtime.ScriptFunction");
Class sco = Class.forName("wrp.jdk.nashorn.api.scripting.ScriptObjectMirror"); Class sco = Class.forName("wrp.jdk.nashorn.api.scripting.ScriptObjectMirror");
Field field = sco.getDeclaredField("sobj"); Field field = sco.getDeclaredField("sobj");
field.setAccessible(true); field.setAccessible(true);
Method method = clz.getDeclaredMethod("executeFunction", scriptFunction, Object.class); Method method =
clz.getDeclaredMethod("executeFunction", scriptFunction, Object.class);
return method.invoke(null, field.get(callback), arg); return method.invoke(null, field.get(callback), arg);
} }
}; };

View File

@ -9,4 +9,4 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
public @interface Action { public @interface Action {
String name() default ""; String name() default "";
} }

View File

@ -8,45 +8,45 @@ import javax.websocket.EndpointConfig;
import javax.websocket.Session; import javax.websocket.Session;
public class BaseClient extends Endpoint { public class BaseClient extends Endpoint {
private Session session; private Session session;
private boolean isConnected; private boolean isConnected;
private WSHandler handler; private WSHandler handler;
public BaseClient(Handler client) { public BaseClient(Handler client) {
isConnected = false; isConnected = false;
handler = new WSHandler(client); handler = new WSHandler(client);
} }
@Override @Override
public void onOpen(Session session, EndpointConfig config) { public void onOpen(Session session, EndpointConfig config) {
this.session = session; this.session = session;
// session.getBasicRemote().sendText("Session ID: " + this.session.getId()); // session.getBasicRemote().sendText("Session ID: " + this.session.getId());
session.addMessageHandler(handler); session.addMessageHandler(handler);
isConnected = true; isConnected = true;
} }
@Override @Override
public void onClose(Session session, CloseReason config) { public void onClose(Session session, CloseReason config) {
this.session = null; this.session = null;
isConnected = false; isConnected = false;
} }
@Override @Override
public void onError(Session session, Throwable config) { public void onError(Session session, Throwable config) {
this.session = null; this.session = null;
isConnected = false; isConnected = false;
} }
public void sendText(String text) { public void sendText(String text) {
try { try {
this.session.getBasicRemote().sendText(text); this.session.getBasicRemote().sendText(text);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public boolean connected() { public boolean connected() {
return isConnected; return isConnected;
} }
} }

View File

@ -3,5 +3,5 @@ package org.bdware.client.ws;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
public interface Handler { public interface Handler {
public void handle(JsonObject obj); public void handle(JsonObject obj);
} }

View File

@ -10,21 +10,21 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
public class WSHandler implements MessageHandler.Whole<String> { public class WSHandler implements MessageHandler.Whole<String> {
LinkedList<String> receivedMsg = new LinkedList<>(); LinkedList<String> receivedMsg = new LinkedList<>();
LinkedHashMap<String, List<Object>> waitList; LinkedHashMap<String, List<Object>> waitList;
Handler h; Handler h;
public WSHandler(Handler h) { public WSHandler(Handler h) {
this.h = h; this.h = h;
} }
@Override @Override
public void onMessage(String arg0) { public void onMessage(String arg0) {
synchronized (receivedMsg) { synchronized (receivedMsg) {
JsonObject json = new JsonParser().parse(arg0).getAsJsonObject(); JsonObject json = new JsonParser().parse(arg0).getAsJsonObject();
// System.out.println("[WSHandler] onMessage:" + arg0); // System.out.println("[WSHandler] onMessage:" + arg0);
if (h != null) if (h != null)
h.handle(json); h.handle(json);
} }
} }
} }

View File

@ -15,9 +15,7 @@ public class EventClientTest {
System.out.println("WaitForConnect"); System.out.println("WaitForConnect");
testClient.waitForConnect(); testClient.waitForConnect();
testClient.subscribeEvent( testClient.subscribeEvent("BDCoinAt162", "Transfer");
"BDCoinAt162",
"Transfer");
try { try {
Thread.sleep(10000); Thread.sleep(10000);
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -59,9 +59,8 @@ public class SM2Test {
String keyStr = String keyStr =
"{\"publicKey\":\"04bbc40ff490a71a1fe2e8d76b49dd73ef3b19fd90b5cf2fc4a9b2f02bdb3c55a58f32ded81c508fc894dac32e0afe5703879c059ed2e6999f17d5a4172549f0b4\",\"privateKey\":\"cc62de3037d0944854c6f3fabea078b1e92c5c2404f5421e929827a481ac4cc5\"}"; "{\"publicKey\":\"04bbc40ff490a71a1fe2e8d76b49dd73ef3b19fd90b5cf2fc4a9b2f02bdb3c55a58f32ded81c508fc894dac32e0afe5703879c059ed2e6999f17d5a4172549f0b4\",\"privateKey\":\"cc62de3037d0944854c6f3fabea078b1e92c5c2404f5421e929827a481ac4cc5\"}";
SM2KeyPair pair = SM2KeyPair.fromJson(keyStr); SM2KeyPair pair = SM2KeyPair.fromJson(keyStr);
String signature = String signature = ByteUtils
ByteUtils.toHexString( .toHexString(SM2Util.sign(pair.getPrivateKeyParameter(), strSign.getBytes()));
SM2Util.sign(pair.getPrivateKeyParameter(), strSign.getBytes()));
System.out.println("[Signature]" + signature); System.out.println("[Signature]" + signature);
} catch (CryptoException e) { } catch (CryptoException e) {
@ -75,9 +74,8 @@ public class SM2Test {
"3046022100ced6cab1c3f93b8768f14a5f69d493ba54619221375897613b6182dfd0fe2a6b02210091454953b42d8c5e07d2552b5d02c6df04d35c5c09703df41d7043953c38f71b"; "3046022100ced6cab1c3f93b8768f14a5f69d493ba54619221375897613b6182dfd0fe2a6b02210091454953b42d8c5e07d2552b5d02c6df04d35c5c09703df41d7043953c38f71b";
String pubKeyStr = String pubKeyStr =
"04bbc40ff490a71a1fe2e8d76b49dd73ef3b19fd90b5cf2fc4a9b2f02bdb3c55a58f32ded81c508fc894dac32e0afe5703879c059ed2e6999f17d5a4172549f0b4"; "04bbc40ff490a71a1fe2e8d76b49dd73ef3b19fd90b5cf2fc4a9b2f02bdb3c55a58f32ded81c508fc894dac32e0afe5703879c059ed2e6999f17d5a4172549f0b4";
ECPublicKeyParameters pubKey = ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyFromStrParameters(pubKeyStr,
BCECUtil.createECPublicKeyFromStrParameters( SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
pubKeyStr, SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
boolean b = SM2Util.plainStrVerify(pubKeyStr, strSign, signature); boolean b = SM2Util.plainStrVerify(pubKeyStr, strSign, signature);
System.out.println("[verifySignature] verify result:" + b); System.out.println("[verifySignature] verify result:" + b);
} }
@ -115,10 +113,8 @@ public class SM2Test {
SM2KeyPair pair = SM2KeyPair.fromJson(key); SM2KeyPair pair = SM2KeyPair.fromJson(key);
String encrypted = String encrypted =
"fa68b741a21e5cb63e9bffab8e1bfa8af6b89172fa0b656c2e557df6dac5858a7a0f47273a1d457421f76510d872db9f0a3e7bd1f294c3fe0e8e524f6bf4957f3a930c2c83980593cb3875421e03116adb4c6106522d0c366affd430b8371fbc6818a7"; "fa68b741a21e5cb63e9bffab8e1bfa8af6b89172fa0b656c2e557df6dac5858a7a0f47273a1d457421f76510d872db9f0a3e7bd1f294c3fe0e8e524f6bf4957f3a930c2c83980593cb3875421e03116adb4c6106522d0c366affd430b8371fbc6818a7";
String str = String str = new String(org.zz.gmhelper.SM2Util.decrypt(pair.getPrivateKeyParameter(),
new String( ByteUtils.fromHexString(encrypted)));
org.zz.gmhelper.SM2Util.decrypt(
pair.getPrivateKeyParameter(), ByteUtils.fromHexString(encrypted)));
System.out.println(str); System.out.println(str);
} }

View File

@ -20,6 +20,7 @@ public class SmartClientTest {
isLogin = true; isLogin = true;
System.out.println("[SmartClientTest] --> login:" + jo.toString()); System.out.println("[SmartClientTest] --> login:" + jo.toString());
} }
// !!!!!Important!!!! // !!!!!Important!!!!
// if you want to handle onXXX message, just use @Action annotation // if you want to handle onXXX message, just use @Action annotation
// there are more onXXX actions described in // there are more onXXX actions described in
@ -36,7 +37,8 @@ public class SmartClientTest {
System.out.println("WaitForConnect"); System.out.println("WaitForConnect");
testClient.waitForConnect(); testClient.waitForConnect();
testClient.login(); testClient.login();
for (; !isLogin; ) Thread.yield(); for (; !isLogin;)
Thread.yield();
testClient.listContractProcess(); testClient.listContractProcess();
System.out.println("Connected!"); System.out.println("Connected!");
} }
@ -58,17 +60,15 @@ public class SmartClientTest {
ContractRequest cr = new ContractRequest(); ContractRequest cr = new ContractRequest();
cr.setContractID("ScoreCollector"); cr.setContractID("ScoreCollector");
cr.setAction("getAllScore"); cr.setAction("getAllScore");
testClient.executeContract( testClient.executeContract(cr, new ResultCallback() {
cr, @Override
new ResultCallback() { public void onResult(JsonObject r) {
@Override System.out.println("[Async] --> " + r.toString());
public void onResult(JsonObject r) { synchronized (cr) {
System.out.println("[Async] --> " + r.toString()); cr.notify();
synchronized (cr) { }
cr.notify(); }
} });
}
});
synchronized (cr) { synchronized (cr) {
try { try {
cr.wait(); cr.wait();

View File

@ -18,40 +18,33 @@ import java.util.Random;
public class SmartContractHttpClientTest { public class SmartContractHttpClientTest {
@Test @Test
public void test() { public void test() {
SmartContractHttpClient client = SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
new SmartContractHttpClient( "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
SM2KeyPair.fromJson( "47.99.93.24", 21030);
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
"47.99.93.24",
21030);
System.out.println(client.executeContractAsString("AccessControlManager", "getGlobal", "")); System.out.println(client.executeContractAsString("AccessControlManager", "getGlobal", ""));
} }
@Test @Test
public void test2() throws Exception { public void test2() throws Exception {
SmartContractHttpClient client = SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
new SmartContractHttpClient( "{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
SM2KeyPair.fromJson( "021.node.internetapi.cn", 21030);
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
"021.node.internetapi.cn",
21030);
String pubkey = String pubkey =
"047ff4ec3f6b1d70e1435c2e129884f8e8af412b76a187b0a1a7fb406f0c0800d625f9e0b2b9881c8e2298db06c197d66820136f552c555b0ddbdf4603ded55c7d"; "047ff4ec3f6b1d70e1435c2e129884f8e8af412b76a187b0a1a7fb406f0c0800d625f9e0b2b9881c8e2298db06c197d66820136f552c555b0ddbdf4603ded55c7d";
String data = "11112121122fddtoEncrypedDaddtaaaadaaa"; String data = "11112121122fddtoEncrypedDaddtaaaadaaa";
String encryped = String encryped = ByteUtils.toHexString(
ByteUtils.toHexString( SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
System.out.println( System.out.println(
client.getExecuteUrl("TrustedStorage", "encryptedTextTransmission", encryped)); client.getExecuteUrl("TrustedStorage", "encryptedTextTransmission", encryped));
System.out.println( System.out.println(client.executeContractAsString("TrustedStorage",
client.executeContractAsString( "encryptedTextTransmission", encryped));
"TrustedStorage", "encryptedTextTransmission", encryped));
} }
String randStr(int len) { String randStr(int len) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Random r = new SecureRandom(); Random r = new SecureRandom();
for (int i = 0; i < len; i++) sb.append(Math.abs(r.nextInt() % 10)); for (int i = 0; i < len; i++)
sb.append(Math.abs(r.nextInt() % 10));
return sb.toString(); return sb.toString();
} }
@ -59,9 +52,8 @@ public class SmartContractHttpClientTest {
public void largeGetAndPost() throws Exception { public void largeGetAndPost() throws Exception {
String keyPair = String keyPair =
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"; "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
SmartContractHttpClient client = SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(keyPair),
new SmartContractHttpClient( "127.0.0.1", 18000, "POST");
SM2KeyPair.fromJson(keyPair), "127.0.0.1", 18000, "POST");
// //
// "{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"), // "{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
// "021.node.internetapi.cn", // "021.node.internetapi.cn",
@ -70,10 +62,10 @@ public class SmartContractHttpClientTest {
"047ff4ec3f6b1d70e1435c2e129884f8e8af412b76a187b0a1a7fb406f0c0800d625f9e0b2b9881c8e2298db06c197d66820136f552c555b0ddbdf4603ded55c7d"; "047ff4ec3f6b1d70e1435c2e129884f8e8af412b76a187b0a1a7fb406f0c0800d625f9e0b2b9881c8e2298db06c197d66820136f552c555b0ddbdf4603ded55c7d";
String data = randStr(9 * 1024 * 1024); String data = randStr(9 * 1024 * 1024);
// String encryped = // String encryped =
// ByteUtils.toHexString( // ByteUtils.toHexString(
// SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes())); // SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
// System.out.println( // System.out.println(
// client.getExecuteUrl("Hello", "encryptedTextTransmission", data)); // client.getExecuteUrl("Hello", "encryptedTextTransmission", data));
System.out.println( System.out.println(
client.executeContractAsString("Hello", "encryptedTextTransmission", data)); client.executeContractAsString("Hello", "encryptedTextTransmission", data));
} }
@ -84,95 +76,86 @@ public class SmartContractHttpClientTest {
r.nextBytes(ret); r.nextBytes(ret);
return ret; return ret;
} }
@Test @Test
public void encryptTrans2() throws Exception { public void encryptTrans2() throws Exception {
//初始化客户端用户传入自己的sm2密钥对 使用"POST"方式可以传输3MB大小的内容 // 初始化客户端用户传入自己的sm2密钥对 使用"POST"方式可以传输3MB大小的内容
SmartContractHttpClient client = SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
new SmartContractHttpClient( "{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
SM2KeyPair.fromJson( "023.node.internetapi.cn", 21030, "POST");
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
"023.node.internetapi.cn",
21030,"POST");
//--------示例1 传输加密上链 // --------示例1 传输加密上链
//使用本合约的公钥也可直接保存下来 // 使用本合约的公钥也可直接保存下来
String pubkey = String pubkey =
"04786622f5a3fcc5c811ea34f19e81f05945f689bb6e5ecec2581cf6d16b4360c1eb3439fdc0620d14f3f2814be1cb39b5e408d345952305d9953563b16d0a53a3"; "04786622f5a3fcc5c811ea34f19e81f05945f689bb6e5ecec2581cf6d16b4360c1eb3439fdc0620d14f3f2814be1cb39b5e408d345952305d9953563b16d0a53a3";
//String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage", "getPubkey", "")) // String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage",
// .getAsJsonObject() // "getPubkey", ""))
// .get("result") // .getAsJsonObject()
// .getAsString(); // .get("result")
// .getAsString();
String data = "汉字123abc"; String data = "汉字123abc";
//计算加密数据 // 计算加密数据
String encryped = String encryped = ByteUtils.toHexString(
ByteUtils.toHexString( // publickeyStr2ECPoint
//publickeyStr2ECPoint SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes())); // 获取上链的链接
//获取上链的链接
System.out.println(client.getExecuteUrl("TrustedPlain0923", "encryptedTextTransmission", encryped));
System.out.println( System.out.println(
client.executeContractAsString("TrustedPlain0923", "encryptedTextTransmission", encryped)); client.getExecuteUrl("TrustedPlain0923", "encryptedTextTransmission", encryped));
//------示例2 明文传输上链 System.out.println(client.executeContractAsString("TrustedPlain0923",
// System.out.println( "encryptedTextTransmission", encryped));
// client.executeContractAsString("TrustedPlain0923", "plainTextTransmission", data)); // ------示例2 明文传输上链
//------示例3 查询链上哈希值 // System.out.println(
String hash="7f57c634be867ab79bb81926354c007aad4c312a"; // client.executeContractAsString("TrustedPlain0923", "plainTextTransmission", data));
System.out.println( // ------示例3 查询链上哈希值
client.executeContractAsString("TrustedPlain0923", "queryByHash", hash)); String hash = "7f57c634be867ab79bb81926354c007aad4c312a";
System.out.println(client.executeContractAsString("TrustedPlain0923", "queryByHash", hash));
} }
@Test @Test
public void encryptTrans() throws Exception { public void encryptTrans() throws Exception {
//初始化客户端用户传入自己的sm2密钥对 使用"POST"方式可以传输3MB大小的内容 // 初始化客户端用户传入自己的sm2密钥对 使用"POST"方式可以传输3MB大小的内容
SmartContractHttpClient client = SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
new SmartContractHttpClient( "{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
SM2KeyPair.fromJson( "023.node.internetapi.cn", 21030, "POST");
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
"023.node.internetapi.cn",
21030,"POST");
//--------示例1 传输加密上链 // --------示例1 传输加密上链
//使用本合约的公钥也可直接保存下来 // 使用本合约的公钥也可直接保存下来
String pubkey = String pubkey =
"045c9ae29614371378206399242fc051a8599ac10d43ae51e051d698a1e14bc6f0c3b79e602865a370066d990038c14f029ae6fbc13c272ac43d19108674299dbc"; "045c9ae29614371378206399242fc051a8599ac10d43ae51e051d698a1e14bc6f0c3b79e602865a370066d990038c14f029ae6fbc13c272ac43d19108674299dbc";
//String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage", "getPubkey", "")) // String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage",
// .getAsJsonObject() // "getPubkey", ""))
// .get("result") // .getAsJsonObject()
// .getAsString(); // .get("result")
// .getAsString();
String data = "汉字123abc"; String data = "汉字123abc";
//计算加密数据 // 计算加密数据
String encryped = String encryped = ByteUtils.toHexString(
ByteUtils.toHexString( SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes())); // 获取上链的链接
//获取上链的链接
System.out.println(client.getExecuteUrl("TrustedStorage0707", "encryptedTextTransmission", encryped));
// System.out.println(
// client.executeContractAsString("TrustedStorage0707", "encryptedTextTransmission", encryped));
//------示例2 明文传输上链
// System.out.println(
// client.executeContractAsString("TrustedStorage0707", "plainTextTransmission", data));
//------示例3 查询链上哈希值
String hash="fa2d81311e45c6ed238bcd935f3391a2ca8c8c53";
System.out.println( System.out.println(
client.executeContractAsString("TrustedStorage0707", "queryByHash", hash)); client.getExecuteUrl("TrustedStorage0707", "encryptedTextTransmission", encryped));
// System.out.println(
// client.executeContractAsString("TrustedStorage0707", "encryptedTextTransmission",
// encryped));
// ------示例2 明文传输上链
// System.out.println(
// client.executeContractAsString("TrustedStorage0707", "plainTextTransmission", data));
// ------示例3 查询链上哈希值
String hash = "fa2d81311e45c6ed238bcd935f3391a2ca8c8c53";
System.out
.println(client.executeContractAsString("TrustedStorage0707", "queryByHash", hash));
} }
@Test @Test
public void getPublicKey() throws Exception { public void getPublicKey() throws Exception {
SmartContractHttpClient client = SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
new SmartContractHttpClient( "{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
SM2KeyPair.fromJson( "021.node.internetapi.cn", 21030);
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
"021.node.internetapi.cn",
21030);
System.out.println(client.getExecuteUrl("TrustedStorage", "getPubkey", "")); System.out.println(client.getExecuteUrl("TrustedStorage", "getPubkey", ""));
String pubKey = String pubKey = JsonParser
JsonParser.parseString( .parseString(client.executeContractAsString("TrustedStorage", "getPubkey", ""))
client.executeContractAsString("TrustedStorage", "getPubkey", "")) .getAsJsonObject().get("result").getAsString();
.getAsJsonObject()
.get("result")
.getAsString();
System.out.println(pubKey); System.out.println(pubKey);
} }
@ -180,38 +163,31 @@ public class SmartContractHttpClientTest {
public void queryData() { public void queryData() {
String hash = "6f9a2f0b76a9e6142fdcccea544f5e3883db73d7"; String hash = "6f9a2f0b76a9e6142fdcccea544f5e3883db73d7";
hash = URLEncoder.encode(new String(Base64.encode((ByteUtils.fromHexString(hash))))); hash = URLEncoder.encode(new String(Base64.encode((ByteUtils.fromHexString(hash)))));
String url = String url = String.format(
String.format( "http://021.node.internetapi.cn:21121/v0/ledgers/default/transaction?hash=%s",
"http://021.node.internetapi.cn:21121/v0/ledgers/default/transaction?hash=%s", hash);
hash);
System.out.println(url); System.out.println(url);
} }
@Test @Test
public void hex2Str() { public void hex2Str() {
System.out.println( System.out.println(new String(ByteUtils.fromHexString(
new String( "0473e0276bfc6260ff89842c552d44b976677c46bb2abd377349c23f85cef3326efa4bc0e56f18a50e40bee9e3fedd2a34b8a1757d77717a71ea718529485df18f2b38a636f25fe18e464983bc786736e4d2a67822fe87ee29dff4c3d54cf0f2ac74dbad92f72863008b90631db358c1b504435a4b92ab85de8a97c5a7f6fcf785dd2ad0fc97d92c170293772d3a5c21b5fae25cf8de8382a5464684d5037d1366acdbb498114f9f220ecd6907ccecd8a32fee766054ebd2bd72568faabe92d8947104b34a892fd5cc5f679049eb6aa8cc6ca55387c82f2d71b1044a58269202693168a1fb1745b12e484752131d60f592da1791a3239789136f42afbc948798b2387f0de40dc14f7b8dacd70e4f73998707cf591489e85de1cfc6f95c8ae71131fd757b26c18b75ff0d6cdd8d851bab68c8fda315283d2b653024007079cd40779d4b559475c0db67b1eb5b27c467c1c0033a5e433fc763ce73bf1268927f1dcd891386db3abcbfb824df66ed")));
ByteUtils.fromHexString(
"0473e0276bfc6260ff89842c552d44b976677c46bb2abd377349c23f85cef3326efa4bc0e56f18a50e40bee9e3fedd2a34b8a1757d77717a71ea718529485df18f2b38a636f25fe18e464983bc786736e4d2a67822fe87ee29dff4c3d54cf0f2ac74dbad92f72863008b90631db358c1b504435a4b92ab85de8a97c5a7f6fcf785dd2ad0fc97d92c170293772d3a5c21b5fae25cf8de8382a5464684d5037d1366acdbb498114f9f220ecd6907ccecd8a32fee766054ebd2bd72568faabe92d8947104b34a892fd5cc5f679049eb6aa8cc6ca55387c82f2d71b1044a58269202693168a1fb1745b12e484752131d60f592da1791a3239789136f42afbc948798b2387f0de40dc14f7b8dacd70e4f73998707cf591489e85de1cfc6f95c8ae71131fd757b26c18b75ff0d6cdd8d851bab68c8fda315283d2b653024007079cd40779d4b559475c0db67b1eb5b27c467c1c0033a5e433fc763ce73bf1268927f1dcd891386db3abcbfb824df66ed")));
} }
@Test @Test
public void test3() throws Exception { public void test3() throws Exception {
SmartContractHttpClient client = SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
new SmartContractHttpClient( "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
SM2KeyPair.fromJson( "59.110.125.211", 21030);
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
"59.110.125.211",
21030);
System.out.println(client.getExecuteUrl("AccessControlManager", "search", "")); System.out.println(client.getExecuteUrl("AccessControlManager", "search", ""));
System.out.println(client.executeContractAsString("AccessControlManager", "search", "")); System.out.println(client.executeContractAsString("AccessControlManager", "search", ""));
} }
@Test @Test
public void testExecuteSync() { public void testExecuteSync() {
SM2KeyPair keyPair = SM2KeyPair keyPair = SM2KeyPair.fromJson(
SM2KeyPair.fromJson( "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}");
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}");
SmartContractClient client = SmartContractClient client =
new SmartContractClient("ws://127.0.0.1:18000/SCIDE/SCExecutor", keyPair); new SmartContractClient("ws://127.0.0.1:18000/SCIDE/SCExecutor", keyPair);