Skip to content

Commit d1f6468

Browse files
committed
<fix>(authConfig,BytesType): add authConfig from getGroupInfo, fix byte type encode base64 in Jackson.
1 parent d97dcf2 commit d1f6468

File tree

7 files changed

+100
-34
lines changed

7 files changed

+100
-34
lines changed

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/datatypes/BytesType.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package org.fisco.bcos.sdk.codec.datatypes;
22

3+
import com.fasterxml.jackson.core.JsonGenerator;
4+
import com.fasterxml.jackson.databind.JsonSerializer;
5+
import com.fasterxml.jackson.databind.SerializerProvider;
6+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
7+
import java.io.IOException;
38
import java.util.Arrays;
9+
import org.fisco.bcos.sdk.utils.Hex;
410

511
/** Binary sequence of bytes. */
612
public abstract class BytesType implements Type<byte[]> {
@@ -14,6 +20,7 @@ public BytesType(byte[] src, String type) {
1420
}
1521

1622
@Override
23+
@JsonSerialize(using = bytesUsingHexSerializer.class)
1724
public byte[] getValue() {
1825
return value;
1926
}
@@ -53,4 +60,17 @@ public int bytes32PaddedLength() {
5360
? MAX_BYTE_LENGTH
5461
: (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
5562
}
63+
64+
public static class bytesUsingHexSerializer extends JsonSerializer<byte[]> {
65+
@Override
66+
public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers)
67+
throws IOException {
68+
if (value == null) {
69+
gen.writeNull();
70+
return;
71+
}
72+
String hexString = Hex.toHexString(value);
73+
gen.writeString(hexString);
74+
}
75+
}
5676
}

sdk-core/src/main/java/org/fisco/bcos/sdk/config/model/AccountConfig.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class AccountConfig {
2525
private String accountFileFormat;
2626
private String accountPassword;
2727
private String accountFilePath;
28-
private Boolean authCheck;
2928

3029
public AccountConfig() {}
3130

@@ -44,9 +43,6 @@ public AccountConfig(ConfigProperty configProperty) throws ConfigException {
4443
if (!this.accountFilePath.equals("")) {
4544
this.accountFilePath = ConfigProperty.getConfigFilePath(this.accountFilePath);
4645
}
47-
String authCheck =
48-
ConfigProperty.getValue(configProperty.getAccount(), "authCheck", "false");
49-
this.authCheck = Boolean.valueOf(authCheck);
5046
checkAccountConfig();
5147
}
5248

@@ -103,14 +99,6 @@ public void setAccountPassword(String accountPassword) {
10399
this.accountPassword = accountPassword;
104100
}
105101

106-
public Boolean getAuthCheck() {
107-
return authCheck;
108-
}
109-
110-
public void setAuthCheck(Boolean authCheck) {
111-
this.authCheck = authCheck;
112-
}
113-
114102
@Override
115103
public String toString() {
116104
return "AccountConfig{"

sdk-service/src/main/java/org/fisco/bcos/sdk/client/Client.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ static Client build(String groupId, ConfigOption configOption, long nativePointe
101101
*/
102102
Boolean isWASM();
103103

104+
/**
105+
* Whether is auth check in chain
106+
*
107+
* @return true when chain in auth mode
108+
*/
109+
Boolean isAuthCheck();
110+
104111
/**
105112
* get groupId of the client
106113
*

sdk-service/src/main/java/org/fisco/bcos/sdk/client/ClientImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class ClientImpl implements Client {
5050
private String groupID = "";
5151
private String chainID;
5252
private Boolean wasm;
53+
private Boolean authCheck = false;
5354
private Boolean smCrypto;
5455
// ------------basic group info --------------
5556

@@ -84,14 +85,16 @@ protected void initGroupInfo() {
8485
this.groupNodeIniConfig = GroupNodeIniConfig.newIniConfig(nodeIniConfig);
8586
this.chainID = groupNodeIniConfig.getChain().getChainID();
8687
this.wasm = groupNodeIniConfig.getExecutor().isWasm();
88+
this.authCheck = groupNodeIniConfig.getExecutor().isAuthCheck();
8789
this.smCrypto = groupNodeIniConfig.getChain().isSmCrypto();
8890
this.blockNumber = this.getBlockNumber().getBlockNumber().longValue();
8991

9092
logger.info(
91-
"init group info in rpc, chainID: {}, smCrypto: {}, wasm: {}, blockNumber: {}, GroupNodeIniConfig: {}",
93+
"init group info in rpc, chainID: {}, smCrypto: {}, wasm: {}, authCheck:{}, blockNumber: {}, GroupNodeIniConfig: {}",
9294
chainID,
9395
smCrypto,
9496
wasm,
97+
authCheck,
9598
blockNumber,
9699
groupNodeIniConfig);
97100
}
@@ -146,10 +149,6 @@ public String getChainId() {
146149
return this.chainID;
147150
}
148151

149-
public Boolean getWasm() {
150-
return this.wasm;
151-
}
152-
153152
public Boolean getSmCrypto() {
154153
return this.smCrypto;
155154
}
@@ -179,6 +178,11 @@ public Boolean isWASM() {
179178
return this.wasm;
180179
}
181180

181+
@Override
182+
public Boolean isAuthCheck() {
183+
return this.authCheck;
184+
}
185+
182186
@Override
183187
public BcosTransactionReceipt sendTransaction(String signedTransactionData, boolean withProof) {
184188
return this.sendTransaction("", signedTransactionData, withProof);

sdk-service/src/main/java/org/fisco/bcos/sdk/client/protocol/model/GroupNodeIniConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static GroupNodeIniConfig newIniConfig(GroupNodeIniInfo groupIniConfig) {
2020
// executor
2121
GroupNodeIniConfig.Executor executor = new GroupNodeIniConfig.Executor();
2222
executor.setWasm(groupIniConfig.getWasm());
23+
executor.setAuthCheck(groupIniConfig.getAuthCheck());
2324

2425
GroupNodeIniConfig groupNodeIniConfig = new GroupNodeIniConfig();
2526
groupNodeIniConfig.setChain(chain);
@@ -53,6 +54,7 @@ public void setExecutor(Executor executor) {
5354

5455
public static class Executor {
5556
private boolean isWasm;
57+
private boolean isAuthCheck;
5658

5759
public boolean isWasm() {
5860
return isWasm;
@@ -62,9 +64,17 @@ public void setWasm(boolean wasm) {
6264
isWasm = wasm;
6365
}
6466

67+
public boolean isAuthCheck() {
68+
return isAuthCheck;
69+
}
70+
71+
public void setAuthCheck(boolean authCheck) {
72+
isAuthCheck = authCheck;
73+
}
74+
6575
@Override
6676
public String toString() {
67-
return "Executor{" + "isWasm=" + isWasm + '}';
77+
return "Executor{" + "isWasm=" + isWasm + ", isAuthCheck=" + isAuthCheck + '}';
6878
}
6979
}
7080

sdk-service/src/main/java/org/fisco/bcos/sdk/client/protocol/model/GroupNodeIniInfo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public String toString() {
8484
@JsonProperty("isWasm")
8585
private Boolean wasm;
8686

87+
@JsonProperty("isAuthCheck")
88+
private Boolean isAuthCheck = false;
89+
8790
private String nodeID;
8891
private String nodeName;
8992
private String rpcServiceName;
@@ -129,6 +132,14 @@ public void setWasm(Boolean wasm) {
129132
this.wasm = wasm;
130133
}
131134

135+
public Boolean getAuthCheck() {
136+
return isAuthCheck;
137+
}
138+
139+
public void setAuthCheck(Boolean authCheck) {
140+
isAuthCheck = authCheck;
141+
}
142+
132143
public String getNodeID() {
133144
return nodeID;
134145
}

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

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -448,23 +448,49 @@ public void test9ComplexSetStaticBytes() throws Exception {
448448
transactionProcessor.deployByContractLoader("ComplexSol", params);
449449
Assert.assertEquals(response.getTransactionReceipt().getStatus(), 0);
450450
String contractAddress = response.getContractAddress();
451+
451452
// setStaticByte4
452-
List<String> paramsSetBytes = Lists.newArrayList(new String("1234".getBytes()));
453-
TransactionResponse transactionResponse3 =
454-
transactionProcessor.sendTransactionWithStringParamsAndGetResponse(
455-
contractAddress, ABI, "setStaticByte4", paramsSetBytes);
456-
System.out.println(JsonUtils.toJson(transactionResponse3));
457-
Assert.assertEquals(transactionResponse3.getResults().size(), 1);
453+
{
454+
List<String> paramsSetBytes = Lists.newArrayList(new String("1234".getBytes()));
455+
TransactionResponse transactionResponse3 =
456+
transactionProcessor.sendTransactionWithStringParamsAndGetResponse(
457+
contractAddress, ABI, "setStaticByte4", paramsSetBytes);
458+
System.out.println(JsonUtils.toJson(transactionResponse3));
459+
Assert.assertEquals(transactionResponse3.getResults().size(), 1);
458460

459-
// get _bytes4V
460-
CallResponse callResponse4 =
461-
transactionProcessor.sendCall(
462-
this.cryptoKeyPair.getAddress(),
463-
contractAddress,
464-
ABI,
465-
"_bytes4V",
466-
Lists.newArrayList());
467-
Assert.assertEquals(0, callResponse4.getReturnCode());
468-
Assert.assertEquals(callResponse4.getResults().get(0), new Bytes4("1234".getBytes()));
461+
// get _bytes4V
462+
CallResponse callResponse4 =
463+
transactionProcessor.sendCall(
464+
this.cryptoKeyPair.getAddress(),
465+
contractAddress,
466+
ABI,
467+
"_bytes4V",
468+
Lists.newArrayList());
469+
Assert.assertEquals(0, callResponse4.getReturnCode());
470+
Assert.assertEquals(callResponse4.getResults().get(0), new Bytes4("1234".getBytes()));
471+
}
472+
473+
// setStaticByte4 in hex
474+
{
475+
List<String> paramsSetBytes = Lists.newArrayList("hex://0x12345678");
476+
TransactionResponse transactionResponse3 =
477+
transactionProcessor.sendTransactionWithStringParamsAndGetResponse(
478+
contractAddress, ABI, "setStaticByte4", paramsSetBytes);
479+
System.out.println(JsonUtils.toJson(transactionResponse3));
480+
Assert.assertEquals(transactionResponse3.getResults().size(), 1);
481+
482+
// get _bytes4V
483+
CallResponse callResponse4 =
484+
transactionProcessor.sendCall(
485+
this.cryptoKeyPair.getAddress(),
486+
contractAddress,
487+
ABI,
488+
"_bytes4V",
489+
Lists.newArrayList());
490+
String s = JsonUtils.toJson(callResponse4.getResults().get(0));
491+
Assert.assertEquals(0, callResponse4.getReturnCode());
492+
Assert.assertEquals(
493+
callResponse4.getResults().get(0), new Bytes4("12345678".getBytes()));
494+
}
469495
}
470496
}

0 commit comments

Comments
 (0)