Skip to content

Commit 786d5c7

Browse files
committed
<fix>(codec,auth): fix bytes codec and fix auth interface.
1 parent 0a31236 commit 786d5c7

File tree

7 files changed

+99
-45
lines changed

7 files changed

+99
-45
lines changed

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/ABICodec.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ private Type buildType(ABIDefinition.NamedType namedType, String param)
213213
}
214214

215215
if (typeStr.equals("bytes")) {
216-
type = new DynamicBytes(param.getBytes());
216+
byte[] bytes = ABICodecJsonWrapper.tryDecodeInputData(param);
217+
if (bytes == null) {
218+
bytes = param.getBytes();
219+
}
220+
type = new DynamicBytes(bytes);
217221
return type;
218222
}
219223

@@ -239,7 +243,10 @@ private Type buildType(ABIDefinition.NamedType namedType, String param)
239243
logger.error(errorMsg);
240244
throw new ABICodecException(errorMsg);
241245
}
242-
byte[] bytesN = param.getBytes();
246+
byte[] bytesN = ABICodecJsonWrapper.tryDecodeInputData(param);
247+
if (bytesN == null) {
248+
bytesN = param.getBytes();
249+
}
243250
if (bytesN.length != length) {
244251
String errorMsg =
245252
String.format(

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/po/CommitteeInfo.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,6 @@
1010
public class CommitteeInfo {
1111
private final Logger logger = LoggerFactory.getLogger(CommitteeInfo.class);
1212

13-
class GovernorInfo {
14-
String governorAddress;
15-
BigInteger weight;
16-
17-
public GovernorInfo(String governorAddress, BigInteger weight) {
18-
this.governorAddress = governorAddress;
19-
this.weight = weight;
20-
}
21-
22-
@Override
23-
public String toString() {
24-
return "GovernorInfo{"
25-
+ "governorAddress='"
26-
+ governorAddress
27-
+ '\''
28-
+ ", weight="
29-
+ weight
30-
+ '}';
31-
}
32-
}
33-
3413
private List<GovernorInfo> governorList = new ArrayList<>();
3514
private int participatesRate;
3615
private int winRate;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.fisco.bcos.sdk.contract.auth.po;
2+
3+
import java.math.BigInteger;
4+
5+
public class GovernorInfo {
6+
private String governorAddress;
7+
private BigInteger weight;
8+
9+
public String getGovernorAddress() {
10+
return governorAddress;
11+
}
12+
13+
public BigInteger getWeight() {
14+
return weight;
15+
}
16+
17+
public GovernorInfo(String governorAddress, BigInteger weight) {
18+
this.governorAddress = governorAddress;
19+
this.weight = weight;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "GovernorInfo{"
25+
+ "governorAddress='"
26+
+ governorAddress
27+
+ '\''
28+
+ ", weight="
29+
+ weight
30+
+ '}';
31+
}
32+
}

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/po/ProposalInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public int getProposalType() {
4646
return proposalType;
4747
}
4848

49+
public String getProposalTypeString() {
50+
return ProposalType.fromInt(proposalType).getValue();
51+
}
52+
4953
public void setProposalType(int proposalType) {
5054
this.proposalType = proposalType;
5155
}
@@ -62,6 +66,10 @@ public int getStatus() {
6266
return status;
6367
}
6468

69+
public String getStatusString() {
70+
return ProposalStatus.fromInt(status).getValue();
71+
}
72+
6573
public void setStatus(int status) {
6674
this.status = status;
6775
}

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/po/ProposalStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final String getValue() {
1717
return value;
1818
}
1919

20-
static ProposalStatus fromInt(int status) {
20+
public static ProposalStatus fromInt(int status) {
2121
switch (status) {
2222
case 1:
2323
return NOT_ENOUGH_VOTE;

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/po/ProposalType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final String getValue() {
1818
return value;
1919
}
2020

21-
static ProposalType fromInt(int type) {
21+
public static ProposalType fromInt(int type) {
2222
switch (type) {
2323
case 11:
2424
return ProposalType.SET_WEIGHT;

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

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -357,28 +357,56 @@ public void test7ComplexSetBytes() throws Exception {
357357
Assert.assertEquals(response.getTransactionReceipt().getStatus(), 0);
358358
String contractAddress = response.getContractAddress();
359359
// setBytes
360-
List<String> paramsSetBytes = Lists.newArrayList(new String("123".getBytes()));
361-
TransactionResponse transactionResponse3 =
362-
transactionProcessor.sendTransactionWithStringParamsAndGetResponse(
363-
contractAddress, ABI, "setBytes", paramsSetBytes);
364-
System.out.println(JsonUtils.toJson(transactionResponse3));
365-
Assert.assertEquals(transactionResponse3.getResults().size(), 1);
360+
{
361+
List<String> paramsSetBytes = Lists.newArrayList(new String("123".getBytes()));
362+
TransactionResponse transactionResponse3 =
363+
transactionProcessor.sendTransactionWithStringParamsAndGetResponse(
364+
contractAddress, ABI, "setBytes", paramsSetBytes);
365+
System.out.println(JsonUtils.toJson(transactionResponse3));
366+
Assert.assertEquals(transactionResponse3.getResults().size(), 1);
366367

367-
Map<String, List<List<Object>>> eventsMap3 = transactionResponse3.getEventResultMap();
368-
System.out.println(JsonUtils.toJson(eventsMap3));
369-
Assert.assertEquals(1, eventsMap3.size());
370-
Assert.assertEquals("123", eventsMap3.get("LogSetBytes").get(0).get(1));
368+
Map<String, List<List<Object>>> eventsMap3 = transactionResponse3.getEventResultMap();
369+
System.out.println(JsonUtils.toJson(eventsMap3));
370+
Assert.assertEquals(1, eventsMap3.size());
371+
Assert.assertEquals("123", eventsMap3.get("LogSetBytes").get(0).get(1));
371372

372-
// getBytes
373-
CallResponse callResponse4 =
374-
transactionProcessor.sendCall(
375-
this.cryptoKeyPair.getAddress(),
376-
contractAddress,
377-
ABI,
378-
"_bytesV",
379-
Lists.newArrayList());
380-
Assert.assertEquals(0, callResponse4.getReturnCode());
381-
Assert.assertEquals(callResponse4.getResults().get(0), new DynamicBytes("123".getBytes()));
373+
// getBytes
374+
CallResponse callResponse4 =
375+
transactionProcessor.sendCall(
376+
this.cryptoKeyPair.getAddress(),
377+
contractAddress,
378+
ABI,
379+
"_bytesV",
380+
Lists.newArrayList());
381+
Assert.assertEquals(0, callResponse4.getReturnCode());
382+
Assert.assertEquals(
383+
callResponse4.getResults().get(0), new DynamicBytes("123".getBytes()));
384+
}
385+
386+
// setBytes
387+
{
388+
List<String> paramsSetBytes2 =
389+
Lists.newArrayList(new String("hex://0x1234".getBytes()));
390+
TransactionResponse transactionResponse4 =
391+
transactionProcessor.sendTransactionWithStringParamsAndGetResponse(
392+
contractAddress, ABI, "setBytes", paramsSetBytes2);
393+
System.out.println(JsonUtils.toJson(transactionResponse4));
394+
Assert.assertEquals(transactionResponse4.getResults().size(), 1);
395+
396+
Map<String, List<List<Object>>> eventsMap4 = transactionResponse4.getEventResultMap();
397+
System.out.println(JsonUtils.toJson(eventsMap4));
398+
Assert.assertEquals(1, eventsMap4.size());
399+
400+
// getBytes
401+
CallResponse callResponse4 =
402+
transactionProcessor.sendCall(
403+
this.cryptoKeyPair.getAddress(),
404+
contractAddress,
405+
ABI,
406+
"_bytesV",
407+
Lists.newArrayList());
408+
Assert.assertEquals(0, callResponse4.getReturnCode());
409+
}
382410
}
383411

384412
@Test

0 commit comments

Comments
 (0)