Skip to content

Commit 0d7c686

Browse files
authored
<feat>(rpc): add call with sign interface of rpc. (#771)
* <feat>(rpc): add call with sign interface of rpc. * <test>(integration): add v3.3.0 node test.
1 parent a0e3ae6 commit 0d7c686

File tree

13 files changed

+363
-35
lines changed

13 files changed

+363
-35
lines changed

.ci/ci_check.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ build_node()
105105
{
106106
local node_type="${1}"
107107
local sed_cmd=$(get_sed_cmd)
108-
curl -LO https://raw.githubusercontent.com/FISCO-BCOS/console/master/tools/get_account.sh
109-
curl -LO https://raw.githubusercontent.com/FISCO-BCOS/console/master/tools/get_gm_account.sh
108+
if [ ! -f "get_account.sh" ];then
109+
curl -LO https://raw.githubusercontent.com/FISCO-BCOS/console/master/tools/get_account.sh
110+
fi
111+
if [ ! -f "get_gm_account.sh" ];then
112+
curl -LO https://raw.githubusercontent.com/FISCO-BCOS/console/master/tools/get_gm_account.sh
113+
fi
110114
if [ "${node_type}" == "wasm" ];then
111-
bash build_chain.sh -l 127.0.0.1:4 -e ./fisco-bcos -w "${2}"
115+
bash build_chain.sh -l 127.0.0.1:4 -e ./fisco-bcos -w ${2}
112116
else
113-
bash build_chain.sh -l 127.0.0.1:4 -A -e ./fisco-bcos "${2}"
117+
bash build_chain.sh -l 127.0.0.1:4 -e ./fisco-bcos ${2}
114118
fi
115119
./nodes/127.0.0.1/fisco-bcos -v
116120
cat nodes/127.0.0.1/node0/config.genesis
@@ -153,9 +157,9 @@ pwd
153157
ls -la
154158
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
155159
download_tassl
156-
LOG_INFO "------ download_build_chain: v3.2.0---------"
157-
download_binary "v3.2.0"
158-
download_build_chain "v3.2.0"
160+
LOG_INFO "------ download_build_chain: v3.3.0---------"
161+
download_binary "v3.3.0"
162+
download_build_chain "v3.3.0"
159163
LOG_INFO "------ check_standard_node---------"
160164
check_standard_node "false" "sm" "-s"
161165
LOG_INFO "------ check_wasm_node---------"
@@ -164,6 +168,13 @@ LOG_INFO "------ check_basic---------"
164168
check_basic
165169
rm -rf ./bin
166170

171+
LOG_INFO "------ download_binary: v3.2.0---------"
172+
download_build_chain "v3.2.0"
173+
download_binary "v3.2.0"
174+
LOG_INFO "------ check_standard_node---------"
175+
check_standard_node "true" "sm" "-s -A"
176+
rm -rf ./bin
177+
167178
LOG_INFO "------ download_binary: v3.1.0---------"
168179
download_build_chain "v3.1.0"
169180
download_binary "v3.1.0"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ext {
3535
// integrationTest.mustRunAfter test
3636
allprojects {
3737
group = 'org.fisco-bcos.java-sdk'
38-
version = '3.3.0'
38+
version = '3.4.0-SNAPSHOT'
3939

4040
apply plugin: 'maven-publish'
4141
apply plugin: 'idea'

src/integration-test/java/org/fisco/bcos/sdk/v3/test/transaction/manager/AssembleTransactionProcessorTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,4 +554,41 @@ public void test10EventDemo() throws Exception {
554554
Assert.assertEquals(transactionResponse3.getEventResultMap().get("Echo").size(), 4);
555555
}
556556
}
557+
558+
@Test
559+
public void test11CallWithSign() throws Exception {
560+
AssembleTransactionProcessor transactionProcessor =
561+
TransactionProcessorFactory.createAssembleTransactionProcessor(
562+
this.client, this.cryptoKeyPair, ABI_FILE, BIN_FILE);
563+
564+
if(client.getChainVersion().compareToVersion(EnumNodeVersion.BCOS_3_4_0) < 0){
565+
return;
566+
}
567+
String contractAddress = null;
568+
// deploy
569+
{
570+
List<Object> params = Lists.newArrayList();
571+
TransactionResponse response =
572+
transactionProcessor.deployByContractLoader("TestCallWithSign", params);
573+
Assert.assertEquals(response.getTransactionReceipt().getStatus(), 0);
574+
contractAddress = response.getContractAddress();
575+
Assert.assertTrue(contractAddress != null && !contractAddress.isEmpty());
576+
}
577+
578+
String abi = transactionProcessor.getContractLoader().getABIByContractName("TestCallWithSign");
579+
List<Object> params = new ArrayList<>();
580+
// getOrigin
581+
{
582+
CallResponse getOrigin = transactionProcessor.sendCallWithSign("", contractAddress, abi, "getOrigin", params);
583+
String origin = (String) getOrigin.getReturnObject().get(0);
584+
Assert.assertEquals(origin, this.cryptoKeyPair.getAddress());
585+
}
586+
587+
// getSender
588+
{
589+
CallResponse getSender = transactionProcessor.sendCallWithSign("", contractAddress, abi, "getSender", params);
590+
String sender = (String) getSender.getReturnObject().get(0);
591+
Assert.assertEquals(sender, this.cryptoKeyPair.getAddress());
592+
}
593+
}
557594
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"inputs":[],"name":"getOrigin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6080604052348015600f57600080fd5b5060908061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80635e01eb5a146037578063df1f29ee146055575b600080fd5b335b6040516001600160a01b03909116815260200160405180910390f35b32603956fea2646970667358221220bdaeaf6c681d4b660240ed4c29eed765b0a053ccd4d1cd7d969cd88a2b5f34a864736f6c634300080b0033

src/main/java/org/fisco/bcos/sdk/v3/client/Client.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,25 @@ void sendTransactionAsync(
214214
*/
215215
Call call(String node, Transaction transaction);
216216

217+
/**
218+
* Ledger operation: call contract functions without sending transaction
219+
*
220+
* @param transaction transaction instance
221+
* @param sign the sign of call data hash(to+data)
222+
* @return Call
223+
*/
224+
Call call(Transaction transaction, String sign);
225+
226+
/**
227+
* Ledger operation: call contract functions without sending transaction
228+
*
229+
* @param node the node rpc request send to
230+
* @param transaction transaction instance
231+
* @param sign the sign of call data hash(to+data)
232+
* @return Call
233+
*/
234+
Call call(String node, Transaction transaction, String sign);
235+
217236
/**
218237
* Ledger operation: async call contract functions without sending transaction
219238
*
@@ -231,6 +250,25 @@ void sendTransactionAsync(
231250
*/
232251
void callAsync(String node, Transaction transaction, RespCallback<Call> callback);
233252

253+
/**
254+
* Ledger operation: async call contract functions without sending transaction
255+
*
256+
* @param transaction transaction instance
257+
* @param sign the sign of call data hash(to+data)
258+
* @param callback the callback that will be called when receive the response
259+
*/
260+
void callAsync(Transaction transaction, String sign, RespCallback<Call> callback);
261+
262+
/**
263+
* Ledger operation: async call contract functions without sending transaction
264+
*
265+
* @param node the node rpc request send to
266+
* @param transaction transaction instance
267+
* @param sign the sign of call data hash(to+data)
268+
* @param callback the callback that will be called when receive the response
269+
*/
270+
void callAsync(String node, Transaction transaction, String sign, RespCallback<Call> callback);
271+
234272
/**
235273
* Ledger operation: get block number
236274
*

src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,31 @@ public Call call(String node, Transaction transaction) {
311311
Call.class);
312312
}
313313

314+
@Override
315+
public Call call(Transaction transaction, String sign) {
316+
return call("", transaction, sign);
317+
}
318+
319+
@Override
320+
public Call call(String node, Transaction transaction, String sign) {
321+
node = Objects.isNull(node) ? "" : node;
322+
if (logger.isTraceEnabled()) {
323+
logger.trace("client call, to:{}, data:{}", transaction.getTo(), transaction.getData());
324+
}
325+
return this.callRemoteMethod(
326+
this.groupID,
327+
node,
328+
new JsonRpcRequest<>(
329+
JsonRpcMethods.CALL,
330+
Arrays.asList(
331+
this.groupID,
332+
node,
333+
Hex.trimPrefix(transaction.getTo()),
334+
Hex.toHexString(transaction.getData()),
335+
sign)),
336+
Call.class);
337+
}
338+
314339
@Override
315340
public void callAsync(Transaction transaction, RespCallback<Call> callback) {
316341
this.callAsync("", transaction, callback);
@@ -333,6 +358,30 @@ public void callAsync(String node, Transaction transaction, RespCallback<Call> c
333358
callback);
334359
}
335360

361+
@Override
362+
public void callAsync(Transaction transaction, String sign, RespCallback<Call> callback) {
363+
this.callAsync("", transaction, sign, callback);
364+
}
365+
366+
@Override
367+
public void callAsync(
368+
String node, Transaction transaction, String sign, RespCallback<Call> callback) {
369+
node = Objects.isNull(node) ? "" : node;
370+
this.asyncCallRemoteMethod(
371+
this.groupID,
372+
node,
373+
new JsonRpcRequest<>(
374+
JsonRpcMethods.CALL,
375+
Arrays.asList(
376+
this.groupID,
377+
node,
378+
Hex.trimPrefix(transaction.getTo()),
379+
Hex.toHexString(transaction.getData()),
380+
sign)),
381+
Call.class,
382+
callback);
383+
}
384+
336385
@Override
337386
public BlockNumber getBlockNumber() {
338387
return this.getBlockNumber("");

src/main/java/org/fisco/bcos/sdk/v3/model/EnumNodeVersion.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public enum EnumNodeVersion {
99
BCOS_3_0_0(0x03000000),
1010
BCOS_3_1_0(0x03010000),
1111
BCOS_3_2_0(0x03020000),
12-
BCOS_3_3_0(0x03030000);
12+
BCOS_3_3_0(0x03030000),
13+
BCOS_3_4_0(0x03040000);
1314

1415
private final Integer version;
1516
private static final Map<Integer, EnumNodeVersion> versionLookupMap = new HashMap<>();
@@ -20,6 +21,7 @@ public enum EnumNodeVersion {
2021
versionLookupMap.put(0x03010000, BCOS_3_1_0);
2122
versionLookupMap.put(0x03020000, BCOS_3_2_0);
2223
versionLookupMap.put(0x03030000, BCOS_3_3_0);
24+
versionLookupMap.put(0x03040000, BCOS_3_4_0);
2325
}
2426

2527
EnumNodeVersion(Integer version) {
@@ -42,6 +44,8 @@ public String getVersionString() {
4244
return "3.2.0";
4345
case BCOS_3_3_0:
4446
return "3.3.0";
47+
case BCOS_3_4_0:
48+
return "3.4.0";
4549
case UNKNOWN:
4650
default:
4751
return "0.0.0";

0 commit comments

Comments
 (0)