mirror of
https://gitee.com/BDWare/sdk-java
synced 2025-01-09 17:34:19 +00:00
build: config spotless plugin and reformat code
This commit is contained in:
parent
d8c3d1753b
commit
dc30a32a34
@ -4,6 +4,9 @@ plugins {
|
||||
id 'maven-publish'
|
||||
id 'signing'
|
||||
}
|
||||
|
||||
apply from: '../spotless.gradle'
|
||||
|
||||
group 'org.bdware.bdcontract'
|
||||
version '1.0.2'
|
||||
sourceCompatibility = 1.8
|
||||
|
@ -5,11 +5,13 @@ import org.zz.gmhelper.SM2KeyPair;
|
||||
|
||||
public class AutoRegister {
|
||||
public static void main(String[] args) {
|
||||
String keyPairStr = "{\"privateKey\":\"347caf3393482440cf5a79995b2c83f567644dfa9b4804755bd093141542db96\",\"publicKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\"}";
|
||||
// "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
|
||||
//; "{\"privateKey\":\"b1f6223a49b9e0943016505e932a17ea0bfe357f3b23cae28f847db9566d30cf\",\"publicKey\":\"0469344c29715c32f0f45765f9446c6208eb1f9ce2c2b765a1c6a7f50e0f8fdb904be2acbaa41898e25144aa5740f5c1dfccdd8bc7fff193dee94269853b1d476b\"}";
|
||||
String keyPairStr =
|
||||
"{\"privateKey\":\"347caf3393482440cf5a79995b2c83f567644dfa9b4804755bd093141542db96\",\"publicKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\"}";
|
||||
// "{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
|
||||
// ;
|
||||
// "{\"privateKey\":\"b1f6223a49b9e0943016505e932a17ea0bfe357f3b23cae28f847db9566d30cf\",\"publicKey\":\"0469344c29715c32f0f45765f9446c6208eb1f9ce2c2b765a1c6a7f50e0f8fdb904be2acbaa41898e25144aa5740f5c1dfccdd8bc7fff193dee94269853b1d476b\"}";
|
||||
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) {
|
||||
initialize(ip, 21030, keyPair);
|
||||
}
|
||||
@ -19,28 +21,27 @@ public class AutoRegister {
|
||||
String local = "ws://" + ip + ":" + port + "/SCIDE/SCExecutor";
|
||||
System.out.println("config:" + ip + ":" + port);
|
||||
|
||||
SmartContractClient testClient =
|
||||
new SmartContractClient(local, keyPair) {
|
||||
public void onListContractProcess(JsonObject obj) {
|
||||
super.onListContractProcess(obj);
|
||||
}
|
||||
SmartContractClient testClient = new SmartContractClient(local, keyPair) {
|
||||
public void onListContractProcess(JsonObject obj) {
|
||||
super.onListContractProcess(obj);
|
||||
}
|
||||
|
||||
public void onLogin(JsonObject obj) {
|
||||
this.setName("Node_" + port);
|
||||
this.setBDLedger("127.0.0.1:18030");
|
||||
this.setMasterAddress(ip + ":" + (port + 1));
|
||||
String apply =
|
||||
"{\"action\":\"applyNodeRole\",\"role\":\"_ROLE_\",\"pubKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
|
||||
this.sendMsg(apply.replaceAll("_ROLE_", "ContractProvider"));
|
||||
this.sendMsg(apply.replaceAll("_ROLE_", "ContractUser"));
|
||||
this.sendMsg(apply.replaceAll("_ROLE_", "ContractInstanceManager"));
|
||||
String auth =
|
||||
"{\"action\":\"authNodeRole\",\"pubKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\",\"isAccept\":true}";
|
||||
this.sendMsg(auth);
|
||||
this.setClusterAddress("ws://10.10.133.38:18002");
|
||||
this.listContractProcess();
|
||||
}
|
||||
};
|
||||
public void onLogin(JsonObject obj) {
|
||||
this.setName("Node_" + port);
|
||||
this.setBDLedger("127.0.0.1:18030");
|
||||
this.setMasterAddress(ip + ":" + (port + 1));
|
||||
String apply =
|
||||
"{\"action\":\"applyNodeRole\",\"role\":\"_ROLE_\",\"pubKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
|
||||
this.sendMsg(apply.replaceAll("_ROLE_", "ContractProvider"));
|
||||
this.sendMsg(apply.replaceAll("_ROLE_", "ContractUser"));
|
||||
this.sendMsg(apply.replaceAll("_ROLE_", "ContractInstanceManager"));
|
||||
String auth =
|
||||
"{\"action\":\"authNodeRole\",\"pubKey\":\"04f5c7cc4b202047da7aff4b93e66204d8e04d0e26435e792afcfb8b4bf918b9b4ec8550e669fb1581203fcd7187ea993391d6c3ee6e348ee17febee3bdad783c3\",\"isAccept\":true}";
|
||||
this.sendMsg(auth);
|
||||
this.setClusterAddress("ws://10.10.133.38:18002");
|
||||
this.listContractProcess();
|
||||
}
|
||||
};
|
||||
testClient.waitForConnect();
|
||||
testClient.login();
|
||||
try {
|
||||
|
@ -4,6 +4,7 @@ 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")) {
|
||||
@ -37,28 +38,27 @@ public class Main {
|
||||
}
|
||||
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);
|
||||
}
|
||||
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 onChangeNodeName(JsonObject obj) {
|
||||
System.out.println(obj.toString());
|
||||
}
|
||||
|
||||
@Action
|
||||
public void onChangeNodeCenter(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());
|
||||
}
|
||||
};
|
||||
@Action
|
||||
public void onUpdateConfig(JsonObject obj) {
|
||||
System.out.println(obj.toString());
|
||||
}
|
||||
};
|
||||
client.waitForConnect();
|
||||
client.login();
|
||||
Thread.sleep(1000);
|
||||
|
@ -134,13 +134,9 @@ public class ContractRequest extends SM2Verifiable
|
||||
|
||||
@Override
|
||||
public String getContentStr() {
|
||||
return String.format(
|
||||
"%s|%s|%s%s|%s",
|
||||
return String.format("%s|%s|%s%s|%s",
|
||||
(contractDOI != null && contractDOI.length() > 0) ? contractDOI : contractID,
|
||||
action,
|
||||
parseArg(),
|
||||
gasLimit > 0 ? "|" + gasLimit : "",
|
||||
requester);
|
||||
action, parseArg(), gasLimit > 0 ? "|" + gasLimit : "", requester);
|
||||
}
|
||||
|
||||
private String parseArg() {
|
||||
|
@ -4,10 +4,6 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.bdware.client.ws.BaseClient;
|
||||
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.ContainerProvider;
|
||||
@ -24,9 +20,8 @@ public class EventSubscriberClient implements Handler {
|
||||
public EventSubscriberClient(String uri) {
|
||||
try {
|
||||
bc = new BaseClient(this);
|
||||
ContainerProvider.getWebSocketContainer()
|
||||
.connectToServer(
|
||||
bc, ClientEndpointConfig.Builder.create().build(), URI.create(uri));
|
||||
ContainerProvider.getWebSocketContainer().connectToServer(bc,
|
||||
ClientEndpointConfig.Builder.create().build(), URI.create(uri));
|
||||
} catch (DeploymentException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -46,23 +41,23 @@ public class EventSubscriberClient implements Handler {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Map<String, String> setNodeID = new HashMap<>();
|
||||
// setNodeID.put("action", "setNodeID");
|
||||
// SM2KeyPair keyPair = SM2Util.generateSM2KeyPair(null);
|
||||
// setNodeID.put("id", keyPair.getPublicKeyStr());
|
||||
//
|
||||
// byte[] sig;
|
||||
// try {
|
||||
// sig =
|
||||
// SM2Util.sign(
|
||||
// keyPair.getPrivateKeyParameter(), keyPair.getPublicKeyStr().getBytes());
|
||||
// setNodeID.put("signature", ByteUtils.toHexString(sig));
|
||||
//
|
||||
// } catch (CryptoException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// setNodeID.put("nodeName", "[LiteClient_" + System.currentTimeMillis() + "]");
|
||||
// bc.sendText(new Gson().toJson(setNodeID));
|
||||
// Map<String, String> setNodeID = new HashMap<>();
|
||||
// setNodeID.put("action", "setNodeID");
|
||||
// SM2KeyPair keyPair = SM2Util.generateSM2KeyPair(null);
|
||||
// setNodeID.put("id", keyPair.getPublicKeyStr());
|
||||
//
|
||||
// byte[] sig;
|
||||
// try {
|
||||
// sig =
|
||||
// SM2Util.sign(
|
||||
// keyPair.getPrivateKeyParameter(), keyPair.getPublicKeyStr().getBytes());
|
||||
// setNodeID.put("signature", ByteUtils.toHexString(sig));
|
||||
//
|
||||
// } catch (CryptoException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// setNodeID.put("nodeName", "[LiteClient_" + System.currentTimeMillis() + "]");
|
||||
// bc.sendText(new Gson().toJson(setNodeID));
|
||||
}
|
||||
|
||||
public void subscribeEvent(String contractID, String topic) {
|
||||
|
@ -29,10 +29,8 @@ public abstract class SM2Verifiable {
|
||||
try {
|
||||
setPublicKey(pair.getPublicKeyStr());
|
||||
|
||||
signature =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(
|
||||
pair.getPrivateKeyParameter(), getContentStr().getBytes()));
|
||||
signature = ByteUtils.toHexString(
|
||||
SM2Util.sign(pair.getPrivateKeyParameter(), getContentStr().getBytes()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -41,11 +39,10 @@ public abstract class SM2Verifiable {
|
||||
public boolean verifySignature() {
|
||||
try {
|
||||
String verifiedStr = getContentStr();
|
||||
ECPublicKeyParameters pubKey =
|
||||
BCECUtil.createECPublicKeyFromStrParameters(
|
||||
getPublicKey(), SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
|
||||
return SM2Util.verify(
|
||||
pubKey, verifiedStr.getBytes(), ByteUtils.fromHexString(signature));
|
||||
ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyFromStrParameters(
|
||||
getPublicKey(), SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
|
||||
return SM2Util.verify(pubKey, verifiedStr.getBytes(),
|
||||
ByteUtils.fromHexString(signature));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -38,9 +38,8 @@ public class SmartContractClient extends SmartContractHandler {
|
||||
keyPair = pair;
|
||||
bc = new BaseClient(this);
|
||||
this.uri = uri;
|
||||
ContainerProvider.getWebSocketContainer()
|
||||
.connectToServer(
|
||||
bc, ClientEndpointConfig.Builder.create().build(), URI.create(uri));
|
||||
ContainerProvider.getWebSocketContainer().connectToServer(bc,
|
||||
ClientEndpointConfig.Builder.create().build(), URI.create(uri));
|
||||
} catch (DeploymentException | IOException e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("[Connect failed]:" + uri);
|
||||
@ -145,9 +144,8 @@ public class SmartContractClient extends SmartContractHandler {
|
||||
String msg = "{\"action\":\"login\",\"signature\":\"";
|
||||
String signature = null;
|
||||
try {
|
||||
signature =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(keyPair.getPrivateKeyParameter(), session.getBytes()));
|
||||
signature = ByteUtils.toHexString(
|
||||
SM2Util.sign(keyPair.getPrivateKeyParameter(), session.getBytes()));
|
||||
} catch (CryptoException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -236,32 +234,17 @@ public class SmartContractClient extends SmartContractHandler {
|
||||
}
|
||||
|
||||
public String getExecuteUrl(ContractRequest cr) {
|
||||
return uri.replaceFirst("ws://", "http://")
|
||||
.replaceFirst("/SCIDE/SCExecutor", "/SCIDE/CMManager?")
|
||||
+ "action=executeContract"
|
||||
+ "&contractID="
|
||||
+ cr.getContractID()
|
||||
+ "&pubkey="
|
||||
+ cr.getPublicKey()
|
||||
+ "&operation="
|
||||
+ cr.getAction()
|
||||
+ "&arg="
|
||||
+ cr.getArg()
|
||||
+ "&signature="
|
||||
+ cr.signature;
|
||||
return uri.replaceFirst("ws://", "http://").replaceFirst("/SCIDE/SCExecutor",
|
||||
"/SCIDE/CMManager?") + "action=executeContract" + "&contractID="
|
||||
+ cr.getContractID() + "&pubkey=" + cr.getPublicKey() + "&operation="
|
||||
+ cr.getAction() + "&arg=" + cr.getArg() + "&signature=" + cr.signature;
|
||||
}
|
||||
|
||||
|
||||
public String getExecuteUrlNoSign(ContractRequest cr) {
|
||||
return uri.replaceFirst("ws://", "http://")
|
||||
.replaceFirst("/SCIDE/SCExecutor", "/SCIDE/CMManager")
|
||||
+ "?action=executeContract"
|
||||
+ "&contractID="
|
||||
+ cr.getContractID()
|
||||
+ "&operation="
|
||||
+ cr.getAction()
|
||||
+ "&arg="
|
||||
+ cr.getArg();
|
||||
return uri.replaceFirst("ws://", "http://").replaceFirst("/SCIDE/SCExecutor",
|
||||
"/SCIDE/CMManager") + "?action=executeContract" + "&contractID="
|
||||
+ cr.getContractID() + "&operation=" + cr.getAction() + "&arg=" + cr.getArg();
|
||||
}
|
||||
|
||||
public void setClusterAddress(String addr) {
|
||||
|
@ -17,17 +17,14 @@ public abstract class SmartContractHandler implements Handler {
|
||||
|
||||
public SmartContractHandler() {
|
||||
methodMap = new HashMap<>();
|
||||
for (Class<?> clz = this.getClass();
|
||||
clz != null && clz != Object.class;
|
||||
clz = clz.getSuperclass()) {
|
||||
for (Class<?> clz = this.getClass(); clz != null && clz != Object.class; clz =
|
||||
clz.getSuperclass()) {
|
||||
for (Method m : clz.getDeclaredMethods()) {
|
||||
String actionName = getActionName(clz, m);
|
||||
if (actionName != null && !methodMap.containsKey(actionName)) {
|
||||
m.setAccessible(true);
|
||||
LOGGER.debug(
|
||||
String.format(
|
||||
"addAction: %s %s.%s",
|
||||
actionName, clz.getCanonicalName(), m.getName()));
|
||||
LOGGER.debug(String.format("addAction: %s %s.%s", actionName,
|
||||
clz.getCanonicalName(), m.getName()));
|
||||
methodMap.put(actionName, m);
|
||||
}
|
||||
}
|
||||
@ -51,8 +48,10 @@ public abstract class SmartContractHandler implements Handler {
|
||||
}
|
||||
}
|
||||
if (action != null) {
|
||||
if (action.name().length() > 0) return action.name();
|
||||
else return m.getName();
|
||||
if (action.name().length() > 0)
|
||||
return action.name();
|
||||
else
|
||||
return m.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -93,7 +92,7 @@ public abstract class SmartContractHandler implements Handler {
|
||||
@Override
|
||||
public void handle(JsonObject obj) {
|
||||
try {
|
||||
// LOGGER.info("receive:" + obj);
|
||||
// LOGGER.info("receive:" + obj);
|
||||
if (!obj.has("action")) {
|
||||
LOGGER.warn("can't handle message without action: " + obj);
|
||||
}
|
||||
|
@ -35,19 +35,16 @@ public class SmartContractHttpClient {
|
||||
public static String getExecuteUrl(String ip, int port, ContractRequest cr) {
|
||||
try {
|
||||
String str;
|
||||
if (cr.getArg() == null) str = "";
|
||||
if (cr.getArg() == null)
|
||||
str = "";
|
||||
else if (cr.getArg().isJsonPrimitive())
|
||||
str = cr.getArg().getAsString();
|
||||
else str = cr.getArg().toString();
|
||||
else
|
||||
str = cr.getArg().toString();
|
||||
return String.format(
|
||||
"http://%s:%d/SCIDE/CMManager?action=executeContract&contractID=%s&operation=%s&arg=%s&pubkey=%s&signature=%s",
|
||||
ip,
|
||||
port,
|
||||
cr.getContractID(),
|
||||
cr.getAction(),
|
||||
URLEncoder.encode(str, "utf-8"),
|
||||
cr.getPublicKey(),
|
||||
cr.signature);
|
||||
ip, port, cr.getContractID(), cr.getAction(), URLEncoder.encode(str, "utf-8"),
|
||||
cr.getPublicKey(), cr.signature);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
@ -15,11 +15,13 @@ public class TimeoutUtil {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
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");
|
||||
Field field = sco.getDeclaredField("sobj");
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
@ -8,45 +8,45 @@ import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.Session;
|
||||
|
||||
public class BaseClient extends Endpoint {
|
||||
private Session session;
|
||||
private boolean isConnected;
|
||||
private WSHandler handler;
|
||||
private Session session;
|
||||
private boolean isConnected;
|
||||
private WSHandler handler;
|
||||
|
||||
public BaseClient(Handler client) {
|
||||
isConnected = false;
|
||||
handler = new WSHandler(client);
|
||||
}
|
||||
public BaseClient(Handler client) {
|
||||
isConnected = false;
|
||||
handler = new WSHandler(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config) {
|
||||
this.session = session;
|
||||
// session.getBasicRemote().sendText("Session ID: " + this.session.getId());
|
||||
session.addMessageHandler(handler);
|
||||
isConnected = true;
|
||||
}
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config) {
|
||||
this.session = session;
|
||||
// session.getBasicRemote().sendText("Session ID: " + this.session.getId());
|
||||
session.addMessageHandler(handler);
|
||||
isConnected = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Session session, CloseReason config) {
|
||||
this.session = null;
|
||||
isConnected = false;
|
||||
}
|
||||
@Override
|
||||
public void onClose(Session session, CloseReason config) {
|
||||
this.session = null;
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Session session, Throwable config) {
|
||||
this.session = null;
|
||||
isConnected = false;
|
||||
}
|
||||
@Override
|
||||
public void onError(Session session, Throwable config) {
|
||||
this.session = null;
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
public void sendText(String text) {
|
||||
try {
|
||||
this.session.getBasicRemote().sendText(text);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void sendText(String text) {
|
||||
try {
|
||||
this.session.getBasicRemote().sendText(text);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean connected() {
|
||||
return isConnected;
|
||||
}
|
||||
public boolean connected() {
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package org.bdware.client.ws;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public interface Handler {
|
||||
public void handle(JsonObject obj);
|
||||
public void handle(JsonObject obj);
|
||||
}
|
@ -10,21 +10,21 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
public class WSHandler implements MessageHandler.Whole<String> {
|
||||
LinkedList<String> receivedMsg = new LinkedList<>();
|
||||
LinkedHashMap<String, List<Object>> waitList;
|
||||
Handler h;
|
||||
LinkedList<String> receivedMsg = new LinkedList<>();
|
||||
LinkedHashMap<String, List<Object>> waitList;
|
||||
Handler h;
|
||||
|
||||
public WSHandler(Handler h) {
|
||||
this.h = h;
|
||||
}
|
||||
public WSHandler(Handler h) {
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String arg0) {
|
||||
synchronized (receivedMsg) {
|
||||
JsonObject json = new JsonParser().parse(arg0).getAsJsonObject();
|
||||
// System.out.println("[WSHandler] onMessage:" + arg0);
|
||||
if (h != null)
|
||||
h.handle(json);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onMessage(String arg0) {
|
||||
synchronized (receivedMsg) {
|
||||
JsonObject json = new JsonParser().parse(arg0).getAsJsonObject();
|
||||
// System.out.println("[WSHandler] onMessage:" + arg0);
|
||||
if (h != null)
|
||||
h.handle(json);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,9 +15,7 @@ public class EventClientTest {
|
||||
System.out.println("WaitForConnect");
|
||||
testClient.waitForConnect();
|
||||
|
||||
testClient.subscribeEvent(
|
||||
"BDCoinAt162",
|
||||
"Transfer");
|
||||
testClient.subscribeEvent("BDCoinAt162", "Transfer");
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -59,9 +59,8 @@ public class SM2Test {
|
||||
String keyStr =
|
||||
"{\"publicKey\":\"04bbc40ff490a71a1fe2e8d76b49dd73ef3b19fd90b5cf2fc4a9b2f02bdb3c55a58f32ded81c508fc894dac32e0afe5703879c059ed2e6999f17d5a4172549f0b4\",\"privateKey\":\"cc62de3037d0944854c6f3fabea078b1e92c5c2404f5421e929827a481ac4cc5\"}";
|
||||
SM2KeyPair pair = SM2KeyPair.fromJson(keyStr);
|
||||
String signature =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.sign(pair.getPrivateKeyParameter(), strSign.getBytes()));
|
||||
String signature = ByteUtils
|
||||
.toHexString(SM2Util.sign(pair.getPrivateKeyParameter(), strSign.getBytes()));
|
||||
System.out.println("[Signature]" + signature);
|
||||
|
||||
} catch (CryptoException e) {
|
||||
@ -75,9 +74,8 @@ public class SM2Test {
|
||||
"3046022100ced6cab1c3f93b8768f14a5f69d493ba54619221375897613b6182dfd0fe2a6b02210091454953b42d8c5e07d2552b5d02c6df04d35c5c09703df41d7043953c38f71b";
|
||||
String pubKeyStr =
|
||||
"04bbc40ff490a71a1fe2e8d76b49dd73ef3b19fd90b5cf2fc4a9b2f02bdb3c55a58f32ded81c508fc894dac32e0afe5703879c059ed2e6999f17d5a4172549f0b4";
|
||||
ECPublicKeyParameters pubKey =
|
||||
BCECUtil.createECPublicKeyFromStrParameters(
|
||||
pubKeyStr, SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
|
||||
ECPublicKeyParameters pubKey = BCECUtil.createECPublicKeyFromStrParameters(pubKeyStr,
|
||||
SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
|
||||
boolean b = SM2Util.plainStrVerify(pubKeyStr, strSign, signature);
|
||||
System.out.println("[verifySignature] verify result:" + b);
|
||||
}
|
||||
@ -115,10 +113,8 @@ public class SM2Test {
|
||||
SM2KeyPair pair = SM2KeyPair.fromJson(key);
|
||||
String encrypted =
|
||||
"fa68b741a21e5cb63e9bffab8e1bfa8af6b89172fa0b656c2e557df6dac5858a7a0f47273a1d457421f76510d872db9f0a3e7bd1f294c3fe0e8e524f6bf4957f3a930c2c83980593cb3875421e03116adb4c6106522d0c366affd430b8371fbc6818a7";
|
||||
String str =
|
||||
new String(
|
||||
org.zz.gmhelper.SM2Util.decrypt(
|
||||
pair.getPrivateKeyParameter(), ByteUtils.fromHexString(encrypted)));
|
||||
String str = new String(org.zz.gmhelper.SM2Util.decrypt(pair.getPrivateKeyParameter(),
|
||||
ByteUtils.fromHexString(encrypted)));
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ public class SmartClientTest {
|
||||
isLogin = true;
|
||||
System.out.println("[SmartClientTest] --> login:" + jo.toString());
|
||||
}
|
||||
|
||||
// !!!!!Important!!!!
|
||||
// if you want to handle onXXX message, just use @Action annotation
|
||||
// there are more onXXX actions described in
|
||||
@ -36,7 +37,8 @@ public class SmartClientTest {
|
||||
System.out.println("WaitForConnect");
|
||||
testClient.waitForConnect();
|
||||
testClient.login();
|
||||
for (; !isLogin; ) Thread.yield();
|
||||
for (; !isLogin;)
|
||||
Thread.yield();
|
||||
testClient.listContractProcess();
|
||||
System.out.println("Connected!");
|
||||
}
|
||||
@ -58,17 +60,15 @@ public class SmartClientTest {
|
||||
ContractRequest cr = new ContractRequest();
|
||||
cr.setContractID("ScoreCollector");
|
||||
cr.setAction("getAllScore");
|
||||
testClient.executeContract(
|
||||
cr,
|
||||
new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println("[Async] --> " + r.toString());
|
||||
synchronized (cr) {
|
||||
cr.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
testClient.executeContract(cr, new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(JsonObject r) {
|
||||
System.out.println("[Async] --> " + r.toString());
|
||||
synchronized (cr) {
|
||||
cr.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
synchronized (cr) {
|
||||
try {
|
||||
cr.wait();
|
||||
|
@ -18,40 +18,33 @@ import java.util.Random;
|
||||
public class SmartContractHttpClientTest {
|
||||
@Test
|
||||
public void test() {
|
||||
SmartContractHttpClient client =
|
||||
new SmartContractHttpClient(
|
||||
SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
|
||||
"47.99.93.24",
|
||||
21030);
|
||||
SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
|
||||
"47.99.93.24", 21030);
|
||||
System.out.println(client.executeContractAsString("AccessControlManager", "getGlobal", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() throws Exception {
|
||||
SmartContractHttpClient client =
|
||||
new SmartContractHttpClient(
|
||||
SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"021.node.internetapi.cn",
|
||||
21030);
|
||||
SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"021.node.internetapi.cn", 21030);
|
||||
String pubkey =
|
||||
"047ff4ec3f6b1d70e1435c2e129884f8e8af412b76a187b0a1a7fb406f0c0800d625f9e0b2b9881c8e2298db06c197d66820136f552c555b0ddbdf4603ded55c7d";
|
||||
String data = "11112121122fddtoEncrypedDaddtaaaadaaa";
|
||||
String encryped =
|
||||
ByteUtils.toHexString(
|
||||
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
|
||||
String encryped = ByteUtils.toHexString(
|
||||
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
|
||||
System.out.println(
|
||||
client.getExecuteUrl("TrustedStorage", "encryptedTextTransmission", encryped));
|
||||
System.out.println(
|
||||
client.executeContractAsString(
|
||||
"TrustedStorage", "encryptedTextTransmission", encryped));
|
||||
System.out.println(client.executeContractAsString("TrustedStorage",
|
||||
"encryptedTextTransmission", encryped));
|
||||
}
|
||||
|
||||
String randStr(int len) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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();
|
||||
}
|
||||
|
||||
@ -59,9 +52,8 @@ public class SmartContractHttpClientTest {
|
||||
public void largeGetAndPost() throws Exception {
|
||||
String keyPair =
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}";
|
||||
SmartContractHttpClient client =
|
||||
new SmartContractHttpClient(
|
||||
SM2KeyPair.fromJson(keyPair), "127.0.0.1", 18000, "POST");
|
||||
SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(keyPair),
|
||||
"127.0.0.1", 18000, "POST");
|
||||
//
|
||||
// "{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
// "021.node.internetapi.cn",
|
||||
@ -70,10 +62,10 @@ public class SmartContractHttpClientTest {
|
||||
"047ff4ec3f6b1d70e1435c2e129884f8e8af412b76a187b0a1a7fb406f0c0800d625f9e0b2b9881c8e2298db06c197d66820136f552c555b0ddbdf4603ded55c7d";
|
||||
String data = randStr(9 * 1024 * 1024);
|
||||
// String encryped =
|
||||
// ByteUtils.toHexString(
|
||||
// SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
|
||||
// System.out.println(
|
||||
// client.getExecuteUrl("Hello", "encryptedTextTransmission", data));
|
||||
// ByteUtils.toHexString(
|
||||
// SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
|
||||
// System.out.println(
|
||||
// client.getExecuteUrl("Hello", "encryptedTextTransmission", data));
|
||||
System.out.println(
|
||||
client.executeContractAsString("Hello", "encryptedTextTransmission", data));
|
||||
}
|
||||
@ -84,95 +76,86 @@ public class SmartContractHttpClientTest {
|
||||
r.nextBytes(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptTrans2() throws Exception {
|
||||
//初始化客户端,用户传入自己的sm2密钥对。 使用"POST"方式可以传输3MB大小的内容。
|
||||
SmartContractHttpClient client =
|
||||
new SmartContractHttpClient(
|
||||
SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"023.node.internetapi.cn",
|
||||
21030,"POST");
|
||||
// 初始化客户端,用户传入自己的sm2密钥对。 使用"POST"方式可以传输3MB大小的内容。
|
||||
SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"023.node.internetapi.cn", 21030, "POST");
|
||||
|
||||
//--------示例1 传输加密上链
|
||||
//使用本合约的公钥。也可直接保存下来。
|
||||
// --------示例1 传输加密上链
|
||||
// 使用本合约的公钥。也可直接保存下来。
|
||||
String pubkey =
|
||||
"04786622f5a3fcc5c811ea34f19e81f05945f689bb6e5ecec2581cf6d16b4360c1eb3439fdc0620d14f3f2814be1cb39b5e408d345952305d9953563b16d0a53a3";
|
||||
//String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage", "getPubkey", ""))
|
||||
// .getAsJsonObject()
|
||||
// .get("result")
|
||||
// .getAsString();
|
||||
// String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage",
|
||||
// "getPubkey", ""))
|
||||
// .getAsJsonObject()
|
||||
// .get("result")
|
||||
// .getAsString();
|
||||
String data = "汉字123abc";
|
||||
//计算加密数据
|
||||
String encryped =
|
||||
ByteUtils.toHexString(
|
||||
//publickeyStr2ECPoint
|
||||
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
|
||||
//获取上链的链接
|
||||
System.out.println(client.getExecuteUrl("TrustedPlain0923", "encryptedTextTransmission", encryped));
|
||||
// 计算加密数据
|
||||
String encryped = ByteUtils.toHexString(
|
||||
// publickeyStr2ECPoint
|
||||
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
|
||||
// 获取上链的链接
|
||||
System.out.println(
|
||||
client.executeContractAsString("TrustedPlain0923", "encryptedTextTransmission", encryped));
|
||||
//------示例2 明文传输上链
|
||||
// System.out.println(
|
||||
// client.executeContractAsString("TrustedPlain0923", "plainTextTransmission", data));
|
||||
//------示例3 查询链上哈希值
|
||||
String hash="7f57c634be867ab79bb81926354c007aad4c312a";
|
||||
System.out.println(
|
||||
client.executeContractAsString("TrustedPlain0923", "queryByHash", hash));
|
||||
client.getExecuteUrl("TrustedPlain0923", "encryptedTextTransmission", encryped));
|
||||
System.out.println(client.executeContractAsString("TrustedPlain0923",
|
||||
"encryptedTextTransmission", encryped));
|
||||
// ------示例2 明文传输上链
|
||||
// System.out.println(
|
||||
// client.executeContractAsString("TrustedPlain0923", "plainTextTransmission", data));
|
||||
// ------示例3 查询链上哈希值
|
||||
String hash = "7f57c634be867ab79bb81926354c007aad4c312a";
|
||||
System.out.println(client.executeContractAsString("TrustedPlain0923", "queryByHash", hash));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void encryptTrans() throws Exception {
|
||||
//初始化客户端,用户传入自己的sm2密钥对。 使用"POST"方式可以传输3MB大小的内容。
|
||||
SmartContractHttpClient client =
|
||||
new SmartContractHttpClient(
|
||||
SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"023.node.internetapi.cn",
|
||||
21030,"POST");
|
||||
// 初始化客户端,用户传入自己的sm2密钥对。 使用"POST"方式可以传输3MB大小的内容。
|
||||
SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"023.node.internetapi.cn", 21030, "POST");
|
||||
|
||||
//--------示例1 传输加密上链
|
||||
//使用本合约的公钥。也可直接保存下来。
|
||||
// --------示例1 传输加密上链
|
||||
// 使用本合约的公钥。也可直接保存下来。
|
||||
String pubkey =
|
||||
"045c9ae29614371378206399242fc051a8599ac10d43ae51e051d698a1e14bc6f0c3b79e602865a370066d990038c14f029ae6fbc13c272ac43d19108674299dbc";
|
||||
//String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage", "getPubkey", ""))
|
||||
// .getAsJsonObject()
|
||||
// .get("result")
|
||||
// .getAsString();
|
||||
// String pubKey = JsonParser.parseString(client.executeContractAsString("TrustedStorage",
|
||||
// "getPubkey", ""))
|
||||
// .getAsJsonObject()
|
||||
// .get("result")
|
||||
// .getAsString();
|
||||
String data = "汉字123abc";
|
||||
//计算加密数据
|
||||
String encryped =
|
||||
ByteUtils.toHexString(
|
||||
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";
|
||||
// 计算加密数据
|
||||
String encryped = ByteUtils.toHexString(
|
||||
SM2Util.encrypt(SM2KeyPair.publicKeyStr2ECPoint(pubkey), data.getBytes()));
|
||||
// 获取上链的链接
|
||||
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
|
||||
public void getPublicKey() throws Exception {
|
||||
SmartContractHttpClient client =
|
||||
new SmartContractHttpClient(
|
||||
SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"021.node.internetapi.cn",
|
||||
21030);
|
||||
SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"f42040dc542124b07f00e7f89591a671526cb64037d5bae2799c143cec19a28d\",\"publicKey\":\"0408187c054e81d79d12f67cccdfb3d2cbafe077a81869f23b63cd8ab03db1bbf72ec4ef12d50c4e2fa08b96470556d2a34f6e5982731f303aca39094906c26f0a\"}"),
|
||||
"021.node.internetapi.cn", 21030);
|
||||
System.out.println(client.getExecuteUrl("TrustedStorage", "getPubkey", ""));
|
||||
String pubKey =
|
||||
JsonParser.parseString(
|
||||
client.executeContractAsString("TrustedStorage", "getPubkey", ""))
|
||||
.getAsJsonObject()
|
||||
.get("result")
|
||||
.getAsString();
|
||||
String pubKey = JsonParser
|
||||
.parseString(client.executeContractAsString("TrustedStorage", "getPubkey", ""))
|
||||
.getAsJsonObject().get("result").getAsString();
|
||||
System.out.println(pubKey);
|
||||
}
|
||||
|
||||
@ -180,38 +163,31 @@ public class SmartContractHttpClientTest {
|
||||
public void queryData() {
|
||||
String hash = "6f9a2f0b76a9e6142fdcccea544f5e3883db73d7";
|
||||
hash = URLEncoder.encode(new String(Base64.encode((ByteUtils.fromHexString(hash)))));
|
||||
String url =
|
||||
String.format(
|
||||
"http://021.node.internetapi.cn:21121/v0/ledgers/default/transaction?hash=%s",
|
||||
hash);
|
||||
String url = String.format(
|
||||
"http://021.node.internetapi.cn:21121/v0/ledgers/default/transaction?hash=%s",
|
||||
hash);
|
||||
System.out.println(url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hex2Str() {
|
||||
System.out.println(
|
||||
new String(
|
||||
ByteUtils.fromHexString(
|
||||
"0473e0276bfc6260ff89842c552d44b976677c46bb2abd377349c23f85cef3326efa4bc0e56f18a50e40bee9e3fedd2a34b8a1757d77717a71ea718529485df18f2b38a636f25fe18e464983bc786736e4d2a67822fe87ee29dff4c3d54cf0f2ac74dbad92f72863008b90631db358c1b504435a4b92ab85de8a97c5a7f6fcf785dd2ad0fc97d92c170293772d3a5c21b5fae25cf8de8382a5464684d5037d1366acdbb498114f9f220ecd6907ccecd8a32fee766054ebd2bd72568faabe92d8947104b34a892fd5cc5f679049eb6aa8cc6ca55387c82f2d71b1044a58269202693168a1fb1745b12e484752131d60f592da1791a3239789136f42afbc948798b2387f0de40dc14f7b8dacd70e4f73998707cf591489e85de1cfc6f95c8ae71131fd757b26c18b75ff0d6cdd8d851bab68c8fda315283d2b653024007079cd40779d4b559475c0db67b1eb5b27c467c1c0033a5e433fc763ce73bf1268927f1dcd891386db3abcbfb824df66ed")));
|
||||
System.out.println(new String(ByteUtils.fromHexString(
|
||||
"0473e0276bfc6260ff89842c552d44b976677c46bb2abd377349c23f85cef3326efa4bc0e56f18a50e40bee9e3fedd2a34b8a1757d77717a71ea718529485df18f2b38a636f25fe18e464983bc786736e4d2a67822fe87ee29dff4c3d54cf0f2ac74dbad92f72863008b90631db358c1b504435a4b92ab85de8a97c5a7f6fcf785dd2ad0fc97d92c170293772d3a5c21b5fae25cf8de8382a5464684d5037d1366acdbb498114f9f220ecd6907ccecd8a32fee766054ebd2bd72568faabe92d8947104b34a892fd5cc5f679049eb6aa8cc6ca55387c82f2d71b1044a58269202693168a1fb1745b12e484752131d60f592da1791a3239789136f42afbc948798b2387f0de40dc14f7b8dacd70e4f73998707cf591489e85de1cfc6f95c8ae71131fd757b26c18b75ff0d6cdd8d851bab68c8fda315283d2b653024007079cd40779d4b559475c0db67b1eb5b27c467c1c0033a5e433fc763ce73bf1268927f1dcd891386db3abcbfb824df66ed")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() throws Exception {
|
||||
SmartContractHttpClient client =
|
||||
new SmartContractHttpClient(
|
||||
SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
|
||||
"59.110.125.211",
|
||||
21030);
|
||||
SmartContractHttpClient client = new SmartContractHttpClient(SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}"),
|
||||
"59.110.125.211", 21030);
|
||||
System.out.println(client.getExecuteUrl("AccessControlManager", "search", "玉"));
|
||||
System.out.println(client.executeContractAsString("AccessControlManager", "search", "玉"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSync() {
|
||||
SM2KeyPair keyPair =
|
||||
SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}");
|
||||
SM2KeyPair keyPair = SM2KeyPair.fromJson(
|
||||
"{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}");
|
||||
|
||||
SmartContractClient client =
|
||||
new SmartContractClient("ws://127.0.0.1:18000/SCIDE/SCExecutor", keyPair);
|
||||
|
Loading…
Reference in New Issue
Block a user