feat: support onCreateParams

This commit is contained in:
CaiHQ 2022-04-07 15:48:39 +08:00
parent 4b96899653
commit fa729d80a0
3 changed files with 76 additions and 18 deletions

View File

@ -1,6 +1,6 @@
package org.bdware.sc; package org.bdware.sc;
import com.google.gson.Gson; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
@ -520,7 +520,7 @@ public class ContractProcess {
String retStr = String retStr =
JsonUtil.toJson( JsonUtil.toJson(
engine.loadContract(contract, cn, cn.getInstrumentBranch())); engine.loadContract(contract, cn, cn.getInstrumentBranch()));
invokeOnCreate(); invokeOnCreate(contract.getCreateParam());
LOGGER.debug("result: " + retStr); LOGGER.debug("result: " + retStr);
return retStr; return retStr;
} else { } else {
@ -640,8 +640,7 @@ public class ContractProcess {
handleLog(); handleLog();
String ret = String ret =
JsonUtil.toJson(engine.loadContract(contract, cn, cn.getInstrumentBranch())); JsonUtil.toJson(engine.loadContract(contract, cn, cn.getInstrumentBranch()));
invokeOnCreate(); invokeOnCreate(contract.getCreateParam());
return ret; return ret;
} catch (Exception e) { } catch (Exception e) {
ByteArrayOutputStream bo = new ByteArrayOutputStream(); ByteArrayOutputStream bo = new ByteArrayOutputStream();
@ -694,7 +693,7 @@ public class ContractProcess {
return r.totalMemory() - r.freeMemory(); return r.totalMemory() - r.freeMemory();
} }
private void invokeOnCreate() { private void invokeOnCreate(JsonElement arg) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
logIndex = new TimeSerialIndex("./ContractDB/" + cn.getContractName() + ".index"); logIndex = new TimeSerialIndex("./ContractDB/" + cn.getContractName() + ".index");
LOGGER.debug("timeSerialIndex: " + (System.currentTimeMillis() - start)); LOGGER.debug("timeSerialIndex: " + (System.currentTimeMillis() - start));
@ -719,7 +718,10 @@ public class ContractProcess {
JavaScriptEntry.isDebug = contract.isDebug(); JavaScriptEntry.isDebug = contract.isDebug();
ContractRequest onCreate = new ContractRequest(); ContractRequest onCreate = new ContractRequest();
onCreate.setAction("onCreate"); onCreate.setAction("onCreate");
if (arg == null)
onCreate.setArg("null"); onCreate.setArg("null");
else
onCreate.setArg(arg);
onCreate.setRequester(contract.getOwner()); onCreate.setRequester(contract.getOwner());
if (contract.getDoipFlag() && null != contract.getDOI() && !contract.getDOI().isEmpty()) { if (contract.getDoipFlag() && null != contract.getDOI() && !contract.getDOI().isEmpty()) {
onCreate.setRequesterDOI(contract.getDOI()); onCreate.setRequesterDOI(contract.getDOI());
@ -730,11 +732,14 @@ public class ContractProcess {
invoke(start, onCreate, funNode); invoke(start, onCreate, funNode);
} }
private void invokeOnRecover() { private void invokeOnRecover(JsonElement arg) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
ContractRequest onRecover = new ContractRequest(); ContractRequest onRecover = new ContractRequest();
onRecover.setAction("onRecover"); onRecover.setAction("onRecover");
if (arg == null)
onRecover.setArg("null"); onRecover.setArg("null");
else
onRecover.setArg(arg);
onRecover.setRequester(contract.getOwner()); onRecover.setRequester(contract.getOwner());
if (contract.getDoipFlag() if (contract.getDoipFlag()
&& (contract.getDOI() != null) && (contract.getDOI() != null)
@ -1062,7 +1067,7 @@ public class ContractProcess {
public String loadMemoryDump(String path) { public String loadMemoryDump(String path) {
String str = engine.syncUtil.loadMemoryDump(path, contract.getStateful()); String str = engine.syncUtil.loadMemoryDump(path, contract.getStateful());
invokeOnRecover(); invokeOnRecover(contract.getCreateParam());
return str; return str;
} }

View File

@ -0,0 +1,32 @@
package org.bdware.sc;
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
public class ByteArrayTest {
@Test
public void abc() {
String str = "abc6787689dd";
byte[] data = str.getBytes(StandardCharsets.UTF_8);
String hexStr = ByteUtils.toHexString(data);
System.out.println("hashCode:" + Arrays.hashCode(data));
System.out.println("hexStr:" + hexStr);
//hashCode:-606029994
//hexStr:616263363738373638396464
}
@Test
public void abc2() {
String str = "abc678768229dd";
byte[] data = str.getBytes(StandardCharsets.UTF_8);
String hexStr = ByteUtils.toHexString(data);
System.out.println("hashCode:" + Arrays.hashCode(data));
System.out.println("hexStr:" + hexStr);
//hashCode:1712735702
//hexStr:6162633637383736383232396464
//
}
}

View File

@ -0,0 +1,21 @@
package org.bdware.sc;
import org.junit.Test;
import org.zz.gmhelper.SM2KeyPair;
import java.math.BigInteger;
public class SM2Test {
@Test
public void run(){
String str = "{publicKey:\"04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15\",privateKey:\"82a119ee46db52778182682f11e21980b6de3070b070a2f58e614af66775d6fc\"}";
String pubKey = "04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15";
// 04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7cOa5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15
String privKey = "82a119ee46db52778182682f11e21980b6de3070b070a2f58e614af66775d6fc";
// 82a119ee46db52778182682f11e21980b6de3070b070a2f58e614af66775d6fc
SM2KeyPair key = new SM2KeyPair(
SM2KeyPair.publicKeyStr2ECPoint(pubKey), new BigInteger(privKey, 16));
System.out.println("hello");
}
}