From 42745687abeaa6ce077d63fa6f2a44d48f4d1e51 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Fri, 3 Dec 2021 11:17:57 +0800 Subject: [PATCH] feat: support jsontype in executeContract --- src/main/base/org/bdware/sc/redo/TransRecord.java | 10 ++++++---- src/main/base/org/bdware/sc/util/JsonUtil.java | 4 +++- .../entry/org/bdware/sc/bean/ContractRequest.java | 13 ++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/base/org/bdware/sc/redo/TransRecord.java b/src/main/base/org/bdware/sc/redo/TransRecord.java index 254720a..65894a2 100644 --- a/src/main/base/org/bdware/sc/redo/TransRecord.java +++ b/src/main/base/org/bdware/sc/redo/TransRecord.java @@ -1,6 +1,8 @@ package org.bdware.sc.redo; +import com.google.gson.JsonElement; + import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -11,16 +13,16 @@ public class TransRecord implements Serializable,Comparable{ boolean needSeq = false; int seq; String functionName; - String arg; + JsonElement arg; public Map executes = new HashMap(); //flagresult)> - public TransRecord(String s1,String s2,int sequence) { + public TransRecord(String s1,JsonElement s2,int sequence) { this.functionName = s1; this.arg = s2; seq = sequence; needSeq = true; } - public TransRecord(String s1,String s2) { + public TransRecord(String s1,JsonElement s2) { this.functionName = s1; this.arg = s2; } @@ -29,7 +31,7 @@ public class TransRecord implements Serializable,Comparable{ return functionName; } - public String getArg() { + public JsonElement getArg() { return arg; } diff --git a/src/main/base/org/bdware/sc/util/JsonUtil.java b/src/main/base/org/bdware/sc/util/JsonUtil.java index 887667a..52af5d1 100644 --- a/src/main/base/org/bdware/sc/util/JsonUtil.java +++ b/src/main/base/org/bdware/sc/util/JsonUtil.java @@ -40,7 +40,9 @@ public class JsonUtil { public static JsonObject parseStringAsJsonObject(String json) { return JsonParser.parseString(json).getAsJsonObject(); } - + public static JsonElement parseString(String json) { + return JsonParser.parseString(json); + } public static JsonObject parseReaderAsJsonObject(Reader reader) { return JsonParser.parseReader(reader).getAsJsonObject(); } diff --git a/src/main/entry/org/bdware/sc/bean/ContractRequest.java b/src/main/entry/org/bdware/sc/bean/ContractRequest.java index 1877ea5..1f02d5f 100644 --- a/src/main/entry/org/bdware/sc/bean/ContractRequest.java +++ b/src/main/entry/org/bdware/sc/bean/ContractRequest.java @@ -1,5 +1,8 @@ package org.bdware.sc.bean; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; + import java.io.*; public class ContractRequest extends SM2Verifiable @@ -15,13 +18,13 @@ public class ContractRequest extends SM2Verifiable String contractID; String contractDOI; // requester = reqPubKey - String requester; + String requester; // DOI of requester String requesterDOI; // action = rsaPrivKeyEncoded(aesKey); String action; // arg = aesKeyEncoded({action,arg}); - String arg; + JsonElement arg; String requestID; boolean fromDebug = false; @@ -71,11 +74,15 @@ public class ContractRequest extends SM2Verifiable this.requesterDOI = requesterDOI; } - public String getArg() { + public JsonElement getArg() { return arg; } public ContractRequest setArg(String arg) { + return setArg(new JsonPrimitive(arg)); + } + + public ContractRequest setArg(JsonElement arg) { this.arg = arg; return this; }