|
56 | 56 | import org.tron.api.GrpcAPI.ProposalList; |
57 | 57 | import org.tron.api.GrpcAPI.Return; |
58 | 58 | import org.tron.api.GrpcAPI.Return.response_code; |
| 59 | +import org.tron.api.GrpcAPI.TransactionApprovedList; |
59 | 60 | import org.tron.api.GrpcAPI.TransactionExtention; |
60 | 61 | import org.tron.api.GrpcAPI.TransactionExtention.Builder; |
61 | 62 | import org.tron.api.GrpcAPI.TransactionSignWeight; |
@@ -571,6 +572,54 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) { |
571 | 572 | return tswBuilder.build(); |
572 | 573 | } |
573 | 574 |
|
| 575 | + public TransactionApprovedList getTransactionApprovedList(Transaction trx) { |
| 576 | + TransactionApprovedList.Builder tswBuilder = TransactionApprovedList.newBuilder(); |
| 577 | + TransactionExtention.Builder trxExBuilder = TransactionExtention.newBuilder(); |
| 578 | + trxExBuilder.setTransaction(trx); |
| 579 | + trxExBuilder.setTxid(ByteString.copyFrom(Sha256Hash.hash(trx.getRawData().toByteArray()))); |
| 580 | + Return.Builder retBuilder = Return.newBuilder(); |
| 581 | + retBuilder.setResult(true).setCode(response_code.SUCCESS); |
| 582 | + trxExBuilder.setResult(retBuilder); |
| 583 | + tswBuilder.setTransaction(trxExBuilder); |
| 584 | + TransactionApprovedList.Result.Builder resultBuilder = TransactionApprovedList.Result |
| 585 | + .newBuilder(); |
| 586 | + try { |
| 587 | + Contract contract = trx.getRawData().getContract(0); |
| 588 | + byte[] owner = TransactionCapsule.getOwner(contract); |
| 589 | + AccountCapsule account = dbManager.getAccountStore().get(owner); |
| 590 | + if (account == null) { |
| 591 | + throw new PermissionException("Account is not exist!"); |
| 592 | + } |
| 593 | + |
| 594 | + if (trx.getSignatureCount() > 0) { |
| 595 | + List<ByteString> approveList = new ArrayList<ByteString>(); |
| 596 | + byte[] hash = Sha256Hash.hash(trx.getRawData().toByteArray()); |
| 597 | + for (ByteString sig : trx.getSignatureList()) { |
| 598 | + if (sig.size() < 65) { |
| 599 | + throw new SignatureFormatException( |
| 600 | + "Signature size is " + sig.size()); |
| 601 | + } |
| 602 | + String base64 = TransactionCapsule.getBase64FromByteString(sig); |
| 603 | + byte[] address = ECKey.signatureToAddress(hash, base64); |
| 604 | + approveList.add(ByteString.copyFrom(address)); //out put approve list. |
| 605 | + } |
| 606 | + tswBuilder.addAllApprovedList(approveList); |
| 607 | + } |
| 608 | + resultBuilder.setCode(TransactionApprovedList.Result.response_code.SUCCESS); |
| 609 | + } catch (SignatureFormatException signEx) { |
| 610 | + resultBuilder.setCode(TransactionApprovedList.Result.response_code.SIGNATURE_FORMAT_ERROR); |
| 611 | + resultBuilder.setMessage(signEx.getMessage()); |
| 612 | + } catch (SignatureException signEx) { |
| 613 | + resultBuilder.setCode(TransactionApprovedList.Result.response_code.COMPUTE_ADDRESS_ERROR); |
| 614 | + resultBuilder.setMessage(signEx.getMessage()); |
| 615 | + } catch (Exception ex) { |
| 616 | + resultBuilder.setCode(TransactionApprovedList.Result.response_code.OTHER_ERROR); |
| 617 | + resultBuilder.setMessage(ex.getClass() + " : " + ex.getMessage()); |
| 618 | + } |
| 619 | + tswBuilder.setResult(resultBuilder); |
| 620 | + return tswBuilder.build(); |
| 621 | + } |
| 622 | + |
574 | 623 | public byte[] pass2Key(byte[] passPhrase) { |
575 | 624 | return Sha256Hash.hash(passPhrase); |
576 | 625 | } |
|
0 commit comments