Skip to content

Commit f7e2509

Browse files
committed
add getApprovedList
1 parent d9b1c0d commit f7e2509

4 files changed

Lines changed: 85 additions & 26 deletions

File tree

‎src/main/java/org/tron/core/Wallet.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.tron.api.GrpcAPI.ProposalList;
5757
import org.tron.api.GrpcAPI.Return;
5858
import org.tron.api.GrpcAPI.Return.response_code;
59+
import org.tron.api.GrpcAPI.TransactionApprovedList;
5960
import org.tron.api.GrpcAPI.TransactionExtention;
6061
import org.tron.api.GrpcAPI.TransactionExtention.Builder;
6162
import org.tron.api.GrpcAPI.TransactionSignWeight;
@@ -571,6 +572,54 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
571572
return tswBuilder.build();
572573
}
573574

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+
574623
public byte[] pass2Key(byte[] passPhrase) {
575624
return Sha256Hash.hash(passPhrase);
576625
}

‎src/main/java/org/tron/core/services/RpcApiService.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.tron.api.GrpcAPI.ProposalList;
4747
import org.tron.api.GrpcAPI.Return;
4848
import org.tron.api.GrpcAPI.Return.response_code;
49+
import org.tron.api.GrpcAPI.TransactionApprovedList;
4950
import org.tron.api.GrpcAPI.TransactionExtention;
5051
import org.tron.api.GrpcAPI.TransactionList;
5152
import org.tron.api.GrpcAPI.TransactionListExtention;
@@ -718,6 +719,14 @@ public void getTransactionSignWeight(Transaction req,
718719
responseObserver.onCompleted();
719720
}
720721

722+
@Override
723+
public void getTransactionApprovedList(Transaction req,
724+
StreamObserver<TransactionApprovedList> responseObserver) {
725+
TransactionApprovedList tal = wallet.getTransactionApprovedList(req);
726+
responseObserver.onNext(tal);
727+
responseObserver.onCompleted();
728+
}
729+
721730
@Override
722731
public void createAddress(BytesMessage req,
723732
StreamObserver<BytesMessage> responseObserver) {

‎src/main/protos/api/api.proto‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,9 @@ message TransactionSignWeight {
10311031
message TransactionApprovedList {
10321032
message Result {
10331033
enum response_code {
1034-
SIGNATURE_FORMAT_ERROR = 0;
1035-
COMPUTE_ADDRESS_ERROR = 1;
1034+
SUCCESS = 0;
1035+
SIGNATURE_FORMAT_ERROR = 1;
1036+
COMPUTE_ADDRESS_ERROR = 2;
10361037
OTHER_ERROR = 20;
10371038
}
10381039
response_code code = 1;

‎src/main/resources/config-localtest.conf‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ node {
141141

142142
# Connection being idle for longer than which will be gracefully terminated
143143
maxConnectionIdleInMillis = 60000
144-
144+
minEffectiveConnection = 0
145145
# Connection lasting longer than which will be gracefully terminated
146146
# maxConnectionAgeInMillis =
147147

@@ -166,9 +166,9 @@ seed.node = {
166166
# ]
167167
ip.list = [
168168
"127.0.0.1:6666",
169-
"127.0.0.1:7777",
170-
"127.0.0.1:8888",
171-
"127.0.0.1:9999",
169+
// "127.0.0.1:7777",
170+
// "127.0.0.1:8888",
171+
// "127.0.0.1:9999",
172172
]
173173
}
174174

@@ -213,26 +213,26 @@ genesis.block = {
213213
voteCount = 106
214214
#priKey = f4df789d3210ac881cb900464dd30409453044d2777060a0c391cbdf4c6a4f57 6666
215215
},
216-
{
217-
address: TPrLL5ckUdMaPNgJYmGv23qtYjBE34aBf8
218-
url = "http://Mercury.org",
219-
voteCount = 105
220-
#priKey = f5583fd20e13073900a513f333ed13db8c9e83e7e3cf37e74adacef96c5afeaa 7777
221-
},
222-
{
223-
address: TEZBh76rouEQpB2zqYVopbRXGx7RfyWorT
224-
#address: 27TfVERREG3FeWMHEAQ95tWHG4sb3ANn3Qe
225-
url = "http://Venus.org",
226-
voteCount = 104
227-
#priKey = 9f5c5e48bf87cf92017313082e8cf0f58ccfce423097f0fcebf801695fc99bd4 8888
228-
},
229-
{
230-
address: TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
231-
#address: 27b8RUuyZnNPFNZGct2bZkNu9MnGWNAdH3Z
232-
url = "http://Earth.org",
233-
voteCount = 103
234-
#priKey = 6781f44d9a2083b14fad1702b8e9ba82749162b795e2fc3f136192fc63f80de2 9999
235-
},
216+
// {
217+
// address: TPrLL5ckUdMaPNgJYmGv23qtYjBE34aBf8
218+
// url = "http://Mercury.org",
219+
// voteCount = 105
220+
// #priKey = f5583fd20e13073900a513f333ed13db8c9e83e7e3cf37e74adacef96c5afeaa 7777
221+
// },
222+
// {
223+
// address: TEZBh76rouEQpB2zqYVopbRXGx7RfyWorT
224+
// #address: 27TfVERREG3FeWMHEAQ95tWHG4sb3ANn3Qe
225+
// url = "http://Venus.org",
226+
// voteCount = 104
227+
// #priKey = 9f5c5e48bf87cf92017313082e8cf0f58ccfce423097f0fcebf801695fc99bd4 8888
228+
// },
229+
// {
230+
// address: TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
231+
// #address: 27b8RUuyZnNPFNZGct2bZkNu9MnGWNAdH3Z
232+
// url = "http://Earth.org",
233+
// voteCount = 103
234+
// #priKey = 6781f44d9a2083b14fad1702b8e9ba82749162b795e2fc3f136192fc63f80de2 9999
235+
// },
236236
]
237237

238238
timestamp = "0" #2017-8-26 12:00:00

0 commit comments

Comments
 (0)