Skip to content

Commit 446eaa7

Browse files
Merge pull request #909 from tronprotocol/rm_api
Rm api
2 parents 28d733b + d1023fc commit 446eaa7

24 files changed

+963
-732
lines changed

src/main/java/org/tron/core/WalletSolidity.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
import lombok.extern.slf4j.Slf4j;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.stereotype.Component;
8-
import org.tron.api.GrpcAPI.AssetIssueList;
98
import org.tron.api.GrpcAPI.TransactionList;
10-
import org.tron.api.GrpcAPI.WitnessList;
119
import org.tron.common.utils.ByteArray;
1210
import org.tron.core.db.api.StoreAPI;
13-
import org.tron.protos.Contract.AssetIssueContract;
1411
import org.tron.protos.Protocol.Transaction;
15-
import org.tron.protos.Protocol.Witness;
1612

1713
@Slf4j
1814
@Component
@@ -21,19 +17,6 @@ public class WalletSolidity {
2117
@Autowired
2218
private StoreAPI storeAPI;
2319

24-
public WitnessList getWitnessList() {
25-
List<Witness> witnessAll = storeAPI.getWitnessAll();
26-
WitnessList witnessList = WitnessList.newBuilder().addAllWitnesses(witnessAll).build();
27-
return witnessList;
28-
}
29-
30-
public AssetIssueList getAssetIssueList() {
31-
List<AssetIssueContract> assetIssueAll = storeAPI.getAssetIssueAll();
32-
AssetIssueList assetIssueList =
33-
AssetIssueList.newBuilder().addAllAssetIssue(assetIssueAll).build();
34-
return assetIssueList;
35-
}
36-
3720
public TransactionList getTransactionsFromThis(ByteString thisAddress, long offset, long limit) {
3821
List<Transaction> transactionsFromThis = storeAPI
3922
.getTransactionsFromThis(ByteArray.toHexString(thisAddress.toByteArray()), offset, limit);

src/main/java/org/tron/core/db/api/StoreAPI.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import org.springframework.util.StringUtils;
2121
import org.tron.core.db.api.index.Index;
2222
import org.tron.core.db.api.index.TransactionIndex;
23-
import org.tron.protos.Contract.AssetIssueContract;
2423
import org.tron.protos.Protocol.Transaction;
25-
import org.tron.protos.Protocol.Witness;
2624

2725
@Component
2826
@Slf4j
@@ -119,17 +117,17 @@ public List<Transaction> getTransactionsToThis(String address, long offset, long
119117
* witness api *
120118
*******************************************************************************
121119
*/
122-
public List<Witness> getWitnessAll() {
123-
Index.Iface<Witness> index = indexHelper.getWitnessIndex();
124-
return ImmutableList.copyOf(index);
125-
}
120+
// public List<Witness> getWitnessAll() {
121+
// Index.Iface<Witness> index = indexHelper.getWitnessIndex();
122+
// return ImmutableList.copyOf(index);
123+
// }
126124

127125
/********************************************************************************
128126
* AssetIssue api *
129127
********************************************************************************
130128
*/
131-
public List<AssetIssueContract> getAssetIssueAll() {
132-
Index.Iface<AssetIssueContract> index = indexHelper.getAssetIssueIndex();
133-
return ImmutableList.copyOf(index);
134-
}
129+
// public List<AssetIssueContract> getAssetIssueAll() {
130+
// Index.Iface<AssetIssueContract> index = indexHelper.getAssetIssueIndex();
131+
// return ImmutableList.copyOf(index);
132+
// }
135133
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ public void getAccount(Account request, StreamObserver<Account> responseObserver
214214

215215
@Override
216216
public void listWitnesses(EmptyMessage request, StreamObserver<WitnessList> responseObserver) {
217-
responseObserver.onNext(walletSolidity.getWitnessList());
217+
responseObserver.onNext(wallet.getWitnessList());
218218
responseObserver.onCompleted();
219219
}
220220

221221
@Override
222222
public void getAssetIssueList(EmptyMessage request,
223223
StreamObserver<AssetIssueList> responseObserver) {
224-
responseObserver.onNext(walletSolidity.getAssetIssueList());
224+
responseObserver.onNext(wallet.getAssetIssueList());
225225
responseObserver.onCompleted();
226226
}
227227

src/main/protos/api/api.proto

Lines changed: 10 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ service Wallet {
9393
};
9494

9595
rpc CreateWitness (WitnessCreateContract) returns (Transaction) {
96-
option (google.api.http) = {
97-
post: "/wallet/createwitness"
98-
body: "*"
99-
additional_bindings {
100-
get: "/wallet/createwitness"
101-
}
102-
};
96+
option (google.api.http) = {
97+
post: "/wallet/createwitness"
98+
body: "*"
99+
additional_bindings {
100+
get: "/wallet/createwitness"
101+
}
103102
};
103+
};
104104

105105
rpc TransferAsset (TransferAssetContract) returns (Transaction) {
106106
option (google.api.http) = {
@@ -192,14 +192,14 @@ service Wallet {
192192
};
193193
}
194194
rpc GetAccountNet (Account) returns (AccountNetMessage) {
195-
option (google.api.http) = {
195+
option (google.api.http) = {
196196
post: "/wallet/getaccountnet"
197197
body: "*"
198198
additional_bindings {
199199
get: "/wallet/getaccountnet"
200200
}
201201
};
202-
};
202+
};
203203
rpc GetAssetIssueByName (BytesMessage) returns (AssetIssueContract) {
204204
option (google.api.http) = {
205205
post: "/wallet/getassetissuebyname"
@@ -333,33 +333,6 @@ service WalletSolidity {
333333
}
334334
};
335335
}
336-
rpc GetAssetIssueListByTimestamp (NumberMessage) returns (AssetIssueList) {
337-
option (google.api.http) = {
338-
post: "/walletsolidity/getassetissuelistbytimestamp"
339-
body: "*"
340-
additional_bindings {
341-
get: "/walletsolidity/getassetissuelistbytimestamp"
342-
}
343-
};
344-
}
345-
rpc GetAssetIssueByAccount (Account) returns (AssetIssueList) {
346-
option (google.api.http) = {
347-
post: "/walletsolidity/getassetissuebyaccount"
348-
body: "*"
349-
additional_bindings {
350-
get: "/walletsolidity/getassetissuebyaccount"
351-
}
352-
};
353-
}
354-
rpc GetAssetIssueByName (BytesMessage) returns (AssetIssueContract) {
355-
option (google.api.http) = {
356-
post: "/walletsolidity/getassetissuebyname"
357-
body: "*"
358-
additional_bindings {
359-
get: "/walletsolidity/getassetissuebyname"
360-
}
361-
};
362-
}
363336
rpc GetNowBlock (EmptyMessage) returns (Block) {
364337
option (google.api.http) = {
365338
post: "/walletsolidity/getnowblock"
@@ -378,46 +351,10 @@ service WalletSolidity {
378351
}
379352
};
380353
}
381-
//get transaction
382-
rpc TotalTransaction (EmptyMessage) returns (NumberMessage) {
383-
option (google.api.http) = {
384-
post: "/walletsolidity/totaltransaction"
385-
body: "*"
386-
additional_bindings {
387-
get: "/walletsolidity/totaltransaction"
388-
}
389-
};
390-
}
391-
rpc GetTransactionById (BytesMessage) returns (Transaction) {
392-
option (google.api.http) = {
393-
post: "/walletsolidity/gettransactionbyid"
394-
body: "*"
395-
additional_bindings {
396-
get: "/walletsolidity/gettransactionbyid"
397-
}
398-
};
399-
}
400354
};
401355

402356
service WalletExtension {
403-
rpc GetTransactionsByTimestamp (TimePaginatedMessage) returns (TransactionList) {
404-
option (google.api.http) = {
405-
post: "/walletextension/gettransactionsbytimestamp"
406-
body: "*"
407-
additional_bindings {
408-
get: "/walletextension/gettransactionsbytimestamp"
409-
}
410-
};
411-
}
412-
rpc GetTransactionsByTimestampCount (TimeMessage) returns (NumberMessage) {
413-
option (google.api.http) = {
414-
post: "/walletextension/gettransactionsbytimestampcount"
415-
body: "*"
416-
additional_bindings {
417-
get: "/walletextension/gettransactionsbytimestampcount"
418-
}
419-
};
420-
}
357+
421358
rpc GetTransactionsFromThis (AccountPaginated) returns (TransactionList) {
422359
option (google.api.http) = {
423360
post: "/walletextension/gettransactionsfromthis"
@@ -436,24 +373,6 @@ service WalletExtension {
436373
}
437374
};
438375
}
439-
rpc GetTransactionsFromThisCount (Account) returns (NumberMessage) {
440-
option (google.api.http) = {
441-
post: "/walletextension/gettransactionsfromthiscount"
442-
body: "*"
443-
additional_bindings {
444-
get: "/walletextension/gettransactionsfromthiscount"
445-
}
446-
};
447-
}
448-
rpc GetTransactionsToThisCount (Account) returns (NumberMessage) {
449-
option (google.api.http) = {
450-
post: "/walletextension/gettransactionstothiscount"
451-
body: "*"
452-
additional_bindings {
453-
get: "/walletextension/gettransactionstothiscount"
454-
}
455-
};
456-
}
457376
};
458377

459378
// the api of tron's db

src/test/java/stest/tron/wallet/account/WalletTestAccount003.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ public class WalletTestAccount003 {
7777
private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list")
7878
.get(0);
7979

80-
/* ECKey ecKey = new ECKey(Utils.getRandom());
81-
byte[] NOWITNESSADDRESS = ecKey.getAddress();
82-
String testKeyForNoWitness = ByteArray.toHexString(ecKey.getPrivKeyBytes());*/
80+
//get account
81+
ECKey ecKey1 = new ECKey(Utils.getRandom());
82+
byte[] noBandwitchAddress = ecKey1.getAddress();
83+
String noBandwitch = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
8384

8485
@BeforeClass
8586
public void beforeClass() {
@@ -104,10 +105,11 @@ public void testCreateAccount() {
104105

105106
//TestVoteToNonWitnessAccount
106107
HashMap<String, String> voteToNonWitnessAccount = new HashMap<String, String>();
107-
voteToNonWitnessAccount.put("27dUQbeRLz6BavhUJE6UbNp5AtAtPuzNZv6", "1");
108+
voteToNonWitnessAccount.put("27dUQbeRLz6BavhUJE6UbNp5AtAtPuzNZv6", "3");
108109
HashMap<String, String> voteToInvaildAddress = new HashMap<String, String>();
109-
voteToInvaildAddress.put("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48", "1");
110+
voteToInvaildAddress.put("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48", "4");
110111
Assert.assertTrue(freezeBalance(FROM_ADDRESS, 10000000L, 3L, testKey002));
112+
voteWitness(voteToNonWitnessAccount, FROM_ADDRESS, testKey002);
111113
Assert.assertFalse(voteWitness(voteToNonWitnessAccount, FROM_ADDRESS, testKey002));
112114
Assert.assertFalse(voteWitness(voteToInvaildAddress, FROM_ADDRESS, testKey002));
113115

@@ -469,9 +471,9 @@ public Boolean voteWitness(HashMap<String, String> witness, byte[] address, Stri
469471
.newBuilder();
470472
byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58);
471473
if (addRess == null) {
472-
continue;
474+
return false;
473475
}
474-
voteBuilder.setVoteAddress(ByteString.copyFrom(address));
476+
voteBuilder.setVoteAddress(ByteString.copyFrom(addRess));
475477
voteBuilder.setVoteCount(count);
476478
builder.addVotes(voteBuilder.build());
477479
}

src/test/java/stest/tron/wallet/account/WalletTestAccount004.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,11 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura
173173
}
174174

175175
Long afterBlockNum = 0L;
176-
177-
while (afterBlockNum < beforeBlockNum) {
176+
Integer wait = 0;
177+
while (afterBlockNum < beforeBlockNum && wait < 10) {
178178
Block currentBlock1 = searchBlockingStubFull.getNowBlock(EmptyMessage.newBuilder().build());
179179
afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber();
180+
wait++;
180181
try {
181182
Thread.sleep(2000);
182183
logger.info("wait 2 second");

src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue006.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
import org.tron.api.WalletGrpc;
1818
import org.tron.api.WalletSolidityGrpc;
1919
import org.tron.common.crypto.ECKey;
20+
import org.tron.common.utils.ByteArray;
21+
import org.tron.common.utils.Utils;
2022
import org.tron.protos.Protocol.Account;
2123
import org.tron.protos.Protocol.Block;
2224
import stest.tron.wallet.common.client.Configuration;
2325
import stest.tron.wallet.common.client.utils.Base58;
26+
import stest.tron.wallet.common.client.utils.PublicMethed;
2427

2528
@Slf4j
2629
public class WalletTestAssetIssue006 {
@@ -53,14 +56,22 @@ public class WalletTestAssetIssue006 {
5356
private ManagedChannel channelSolidity = null;
5457
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
5558
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;
56-
57-
private static final long now = System.currentTimeMillis();
58-
5959
private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list")
6060
.get(0);
6161
private String soliditynode = Configuration.getByPath("testng.conf")
6262
.getStringList("solidityNode.ip.list").get(0);
6363

64+
private static final long now = System.currentTimeMillis();
65+
private static String name = "assetissue006" + Long.toString(now);
66+
private static final long totalSupply = now;
67+
String description = "test query assetissue by timestamp from soliditynode";
68+
String url = "https://testqueryassetissue.com/bytimestamp/from/soliditynode/";
69+
70+
//get account
71+
ECKey ecKey = new ECKey(Utils.getRandom());
72+
byte[] queryAssetIssueFromSoliAddress = ecKey.getAddress();
73+
String queryAssetIssueKey = ByteArray.toHexString(ecKey.getPrivKeyBytes());
74+
6475
@BeforeClass
6576
public void beforeClass() {
6677
channelFull = ManagedChannelBuilder.forTarget(fullnode)
@@ -72,10 +83,42 @@ public void beforeClass() {
7283
.usePlaintext(true)
7384
.build();
7485
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
86+
87+
Assert.assertTrue(PublicMethed.freezeBalance(FROM_ADDRESS,10000000,3,testKey002,
88+
blockingStubFull));
89+
Assert.assertTrue(PublicMethed.sendcoin(queryAssetIssueFromSoliAddress,2048000000,FROM_ADDRESS,
90+
testKey002,blockingStubFull));
91+
Long start = System.currentTimeMillis() + 2000;
92+
Long end = System.currentTimeMillis() + 1000000000;
93+
//Create a new AssetIssue success.
94+
Assert.assertTrue(PublicMethed.createAssetIssue(queryAssetIssueFromSoliAddress, name,
95+
totalSupply, 1, 100, start, end, 1, description, url, 1000L,
96+
1000L,1L,1L,queryAssetIssueKey,blockingStubFull));
7597
}
7698

77-
@Test(enabled = true)
99+
/* @Test(enabled = true)
78100
public void testGetAssetIssueListByTimestamp() {
101+
Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build());
102+
Block solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage
103+
.newBuilder().build());
104+
Integer wait = 0;
105+
while (solidityCurrentBlock.getBlockHeader().getRawData().getNumber()
106+
< currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 10) {
107+
try {
108+
Thread.sleep(3000);
109+
} catch (InterruptedException e) {
110+
e.printStackTrace();
111+
}
112+
logger.info("Solidity didn't synchronize the fullnode block,please wait");
113+
solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder()
114+
.build());
115+
wait++;
116+
if (wait == 9) {
117+
logger.info("Didn't syn,skip to next case.");
118+
}
119+
}
120+
121+
79122
long time = now;
80123
NumberMessage.Builder timeStamp = NumberMessage.newBuilder();
81124
timeStamp.setNum(time);
@@ -117,7 +160,7 @@ public void testExceptionGetAssetIssueListByTimestamp() {
117160
getAssetIssueListByTimestamp = Optional.ofNullable(assetIssueList);
118161
Assert.assertTrue(getAssetIssueListByTimestamp.get().getAssetIssueCount() == 0);
119162
120-
}
163+
}*/
121164

122165
@AfterClass
123166
public void shutdown() throws InterruptedException {

0 commit comments

Comments
 (0)