Skip to content

Commit b427c1c

Browse files
authored
Merge pull request #434 from kyonRay/release-3.1.0
<fix>(codec): fix abi bytesN codec.
2 parents 62ccc9b + 786d5c7 commit b427c1c

File tree

15 files changed

+192
-119
lines changed

15 files changed

+192
-119
lines changed

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

Lines changed: 13 additions & 11 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

@@ -222,6 +226,7 @@ private Type buildType(ABIDefinition.NamedType namedType, String param)
222226
return type;
223227
}
224228

229+
// static bytesN
225230
if (typeStr.startsWith("bytes")) {
226231
String lengthStr = typeStr.substring("bytes".length());
227232
int length;
@@ -238,22 +243,19 @@ private Type buildType(ABIDefinition.NamedType namedType, String param)
238243
logger.error(errorMsg);
239244
throw new ABICodecException(errorMsg);
240245
}
241-
242-
JsonNode jsonNode = this.objectMapper.readTree(param);
243-
assert jsonNode.isArray();
244-
if (jsonNode.size() != length) {
246+
byte[] bytesN = ABICodecJsonWrapper.tryDecodeInputData(param);
247+
if (bytesN == null) {
248+
bytesN = param.getBytes();
249+
}
250+
if (bytesN.length != length) {
245251
String errorMsg =
246252
String.format(
247253
"expected byte array at length %d but length of provided in data is %d",
248-
length, jsonNode.size());
254+
length, bytesN.length);
249255
logger.error(errorMsg);
250256
throw new ABICodecException(errorMsg);
251257
}
252258

253-
byte[] bytes = new byte[jsonNode.size()];
254-
for (int i = 0; i < jsonNode.size(); ++i) {
255-
bytes[i] = ((byte) jsonNode.get(i).asInt());
256-
}
257259
try {
258260
Class<?> bytesClass =
259261
Class.forName(
@@ -262,7 +264,7 @@ private Type buildType(ABIDefinition.NamedType namedType, String param)
262264
(Type)
263265
bytesClass
264266
.getDeclaredConstructor(byte[].class)
265-
.newInstance(bytes);
267+
.newInstance(bytesN);
266268
} catch (ClassNotFoundException
267269
| NoSuchMethodException
268270
| InstantiationException

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -296,88 +296,83 @@ void sendTransactionAsync(
296296
* Ledger operation: get block by hash
297297
*
298298
* @param blockHash the hashcode of the block
299-
* @param returnFullTransactionObjects the boolean define the tx is full or not
299+
* @param onlyTxHash the boolean define the tx is full or not
300300
* @return a block
301301
*/
302-
BcosBlock getBlockByHash(
303-
String blockHash, boolean onlyHeader, boolean returnFullTransactionObjects);
302+
BcosBlock getBlockByHash(String blockHash, boolean onlyHeader, boolean onlyTxHash);
304303

305304
/**
306305
* Ledger operation: get block by hash
307306
*
308307
* @param node the node rpc request send to
309308
* @param blockHash the hashcode of the block
310-
* @param returnFullTransactionObjects the boolean define the tx is full or not
309+
* @param onlyTxHash the boolean define the tx is full or not
311310
* @return a block
312311
*/
313-
BcosBlock getBlockByHash(
314-
String node,
315-
String blockHash,
316-
boolean onlyHeader,
317-
boolean returnFullTransactionObjects);
312+
BcosBlock getBlockByHash(String node, String blockHash, boolean onlyHeader, boolean onlyTxHash);
318313

319314
/**
320315
* Ledger operation: async get block by hash
321316
*
322317
* @param blockHash the hashcode of the block
323-
* @param returnFullTransactionObjects the boolean define the tx is full or not
318+
* @param onlyTxHash the boolean define the tx is full or not
324319
* @param callback the callback that will be called when receive the response
325320
*/
326321
void getBlockByHashAsync(
327322
String blockHash,
328323
boolean onlyHeader,
329-
boolean returnFullTransactionObjects,
324+
boolean onlyTxHash,
330325
RespCallback<BcosBlock> callback);
331326

332327
/**
333328
* Ledger operation: async get block by hash
334329
*
335330
* @param node the node rpc request send to
336331
* @param blockHash the hashcode of the block
337-
* @param returnFullTransactionObjects the boolean define the tx is full or not
332+
* @param onlyTxHash the boolean define the tx is full or not
338333
* @param callback the callback that will be called when receive the response
339334
*/
340335
void getBlockByHashAsync(
341336
String node,
342337
String blockHash,
343338
boolean onlyHeader,
344-
boolean returnFullTransactionObjects,
339+
boolean onlyTxHash,
345340
RespCallback<BcosBlock> callback);
346341

347342
/**
348343
* Ledger operation: get block by block number
349344
*
350345
* @param blockNumber the number of the block
351346
* @param onlyHeader the boolean define if only return header
352-
* @param isOnlyTxHash the boolean define if only return tx hash
347+
* @param onlyTxHash the boolean define if only return tx hash
353348
* @return block
354349
*/
355-
BcosBlock getBlockByNumber(BigInteger blockNumber, boolean onlyHeader, boolean isOnlyTxHash);
350+
BcosBlock getBlockByNumber(BigInteger blockNumber, boolean onlyHeader, boolean onlyTxHash);
356351

357352
/**
358353
* Ledger operation: get block by block number
359354
*
360355
* @param node the node rpc request send to
361356
* @param blockNumber the number of the block
362357
* @param onlyHeader the boolean define if only return header
363-
* @param isOnlyTxHash the boolean define if only return tx hash
358+
* @param onlyTxHash the boolean define if only return tx hash
364359
* @return block
365360
*/
366361
BcosBlock getBlockByNumber(
367-
String node, BigInteger blockNumber, boolean onlyHeader, boolean isOnlyTxHash);
362+
String node, BigInteger blockNumber, boolean onlyHeader, boolean onlyTxHash);
368363

369364
/**
370365
* Ledger operation: async get block by block number
371366
*
372367
* @param blockNumber the number of the block
373368
* @param onlyHeader the boolean if only need header
374-
* @param isOnlyTxHash the boolean if you need all transactions
369+
* @param onlyTxHash the boolean if you need all transactions
375370
* @param callback the callback that will be called when receive the response
376371
*/
377372
void getBlockByNumberAsync(
378373
BigInteger blockNumber,
379374
boolean onlyHeader,
380-
boolean isOnlyTxHash,
375+
boolean onlyTxHash,
381376
RespCallback<BcosBlock> callback);
382377

383378
/**
@@ -386,14 +381,14 @@ void getBlockByNumberAsync(
386381
* @param node the node rpc request send to
387382
* @param blockNumber the number of the block
388383
* @param onlyHeader the boolean if only need header
389-
* @param isOnlyTxHash the boolean if you need all transactions
384+
* @param onlyTxHash the boolean if you need all transactions
390385
* @param callback the callback that will be called when receive the response
391386
*/
392387
void getBlockByNumberAsync(
393388
String node,
394389
BigInteger blockNumber,
395390
boolean onlyHeader,
396-
boolean isOnlyTxHash,
391+
boolean onlyTxHash,
397392
RespCallback<BcosBlock> callback);
398393

399394
/**

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

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -380,106 +380,92 @@ public void getTotalTransactionCountAsync(
380380
}
381381

382382
@Override
383-
public BcosBlock getBlockByHash(
384-
String blockHash, boolean onlyHeader, boolean returnFullTransactionObjects) {
385-
return this.getBlockByHash("", blockHash, onlyHeader, returnFullTransactionObjects);
383+
public BcosBlock getBlockByHash(String blockHash, boolean onlyHeader, boolean onlyTxHash) {
384+
return this.getBlockByHash("", blockHash, onlyHeader, onlyTxHash);
386385
}
387386

388387
@Override
389388
public BcosBlock getBlockByHash(
390-
String node,
391-
String blockHash,
392-
boolean onlyHeader,
393-
boolean returnFullTransactionObjects) {
389+
String node, String blockHash, boolean onlyHeader, boolean onlyTxHash) {
394390
node = Objects.isNull(node) ? "" : node;
395391
return this.callRemoteMethod(
396392
this.groupID,
397393
node,
398394
new JsonRpcRequest(
399395
JsonRpcMethods.GET_BLOCK_BY_HASH,
400-
Arrays.asList(
401-
this.groupID,
402-
node,
403-
blockHash,
404-
onlyHeader,
405-
returnFullTransactionObjects)),
396+
Arrays.asList(this.groupID, node, blockHash, onlyHeader, onlyTxHash)),
406397
BcosBlock.class);
407398
}
408399

409400
@Override
410401
public void getBlockByHashAsync(
411402
String blockHash,
412403
boolean onlyHeader,
413-
boolean returnFullTransactionObjects,
404+
boolean onlyTxHash,
414405
RespCallback<BcosBlock> callback) {
415-
this.getBlockByHash("", blockHash, onlyHeader, returnFullTransactionObjects);
406+
this.getBlockByHash("", blockHash, onlyHeader, onlyTxHash);
416407
}
417408

418409
@Override
419410
public void getBlockByHashAsync(
420411
String node,
421412
String blockHash,
422413
boolean onlyHeader,
423-
boolean returnFullTransactionObjects,
414+
boolean onlyTxHash,
424415
RespCallback<BcosBlock> callback) {
425416
node = Objects.isNull(node) ? "" : node;
426417
this.asyncCallRemoteMethod(
427418
this.groupID,
428419
node,
429420
new JsonRpcRequest(
430421
JsonRpcMethods.GET_BLOCK_BY_HASH,
431-
Arrays.asList(
432-
this.groupID,
433-
node,
434-
blockHash,
435-
onlyHeader,
436-
returnFullTransactionObjects)),
422+
Arrays.asList(this.groupID, node, blockHash, onlyHeader, onlyTxHash)),
437423
BcosBlock.class,
438424
callback);
439425
}
440426

441427
@Override
442428
public BcosBlock getBlockByNumber(
443-
BigInteger blockNumber, boolean onlyHeader, boolean isOnlyTxHash) {
444-
return this.getBlockByNumber("", blockNumber, onlyHeader, isOnlyTxHash);
429+
BigInteger blockNumber, boolean onlyHeader, boolean onlyTxHash) {
430+
return this.getBlockByNumber("", blockNumber, onlyHeader, onlyTxHash);
445431
}
446432

447433
@Override
448434
public BcosBlock getBlockByNumber(
449-
String node, BigInteger blockNumber, boolean onlyHeader, boolean isOnlyTxHash) {
435+
String node, BigInteger blockNumber, boolean onlyHeader, boolean onlyTxHash) {
450436
node = Objects.isNull(node) ? "" : node;
451437
return this.callRemoteMethod(
452438
this.groupID,
453439
node,
454440
new JsonRpcRequest(
455441
JsonRpcMethods.GET_BLOCK_BY_NUMBER,
456-
Arrays.asList(this.groupID, node, blockNumber, onlyHeader, isOnlyTxHash)),
442+
Arrays.asList(this.groupID, node, blockNumber, onlyHeader, onlyTxHash)),
457443
BcosBlock.class);
458444
}
459445

460446
@Override
461447
public void getBlockByNumberAsync(
462448
BigInteger blockNumber,
463449
boolean onlyHeader,
464-
boolean isOnlyTxHash,
450+
boolean onlyTxHash,
465451
RespCallback<BcosBlock> callback) {
466-
this.getBlockByNumberAsync("", blockNumber, onlyHeader, isOnlyTxHash, callback);
452+
this.getBlockByNumberAsync("", blockNumber, onlyHeader, onlyTxHash, callback);
467453
}
468454

469455
@Override
470456
public void getBlockByNumberAsync(
471457
String node,
472458
BigInteger blockNumber,
473459
boolean onlyHeader,
474-
boolean isOnlyTxHash,
460+
boolean onlyTxHash,
475461
RespCallback<BcosBlock> callback) {
476462
node = Objects.isNull(node) ? "" : node;
477463
this.asyncCallRemoteMethod(
478464
this.groupID,
479465
node,
480466
new JsonRpcRequest(
481467
JsonRpcMethods.GET_BLOCK_BY_NUMBER,
482-
Arrays.asList(this.groupID, node, blockNumber, onlyHeader, isOnlyTxHash)),
468+
Arrays.asList(this.groupID, node, blockNumber, onlyHeader, onlyTxHash)),
483469
BcosBlock.class,
484470
callback);
485471
}

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/manager/AuthManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public TransactionReceipt voteProposal(BigInteger proposalId, Boolean agree) {
192192
* @param transactionResponse which get proposal from
193193
* @return proposal id
194194
*/
195-
public BigInteger getProposal(TransactionResponse transactionResponse)
195+
private BigInteger getProposal(TransactionResponse transactionResponse)
196196
throws TransactionException {
197197
if (transactionResponse == null) {
198198
throw new TransactionException("Decode transaction response error");
@@ -236,7 +236,7 @@ public CommitteeInfo getCommitteeInfo() throws ContractException {
236236
* @param account the account to check
237237
* @return true or false
238238
*/
239-
public Boolean hasDeployAuth(String account) throws ContractException {
239+
public Boolean checkDeployAuth(String account) throws ContractException {
240240
return contractAuthPrecompiled.hasDeployAuth(account);
241241
}
242242

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+
}

0 commit comments

Comments
 (0)