Skip to content
17 changes: 0 additions & 17 deletions src/main/java/org/tron/core/WalletSolidity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.api.GrpcAPI.AssetIssueList;
import org.tron.api.GrpcAPI.TransactionList;
import org.tron.api.GrpcAPI.WitnessList;
import org.tron.common.utils.ByteArray;
import org.tron.core.db.api.StoreAPI;
import org.tron.protos.Contract.AssetIssueContract;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Witness;

@Slf4j
@Component
Expand All @@ -21,19 +17,6 @@ public class WalletSolidity {
@Autowired
private StoreAPI storeAPI;

public WitnessList getWitnessList() {
List<Witness> witnessAll = storeAPI.getWitnessAll();
WitnessList witnessList = WitnessList.newBuilder().addAllWitnesses(witnessAll).build();
return witnessList;
}

public AssetIssueList getAssetIssueList() {
List<AssetIssueContract> assetIssueAll = storeAPI.getAssetIssueAll();
AssetIssueList assetIssueList =
AssetIssueList.newBuilder().addAllAssetIssue(assetIssueAll).build();
return assetIssueList;
}

public TransactionList getTransactionsFromThis(ByteString thisAddress, long offset, long limit) {
List<Transaction> transactionsFromThis = storeAPI
.getTransactionsFromThis(ByteArray.toHexString(thisAddress.toByteArray()), offset, limit);
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/org/tron/core/db/api/StoreAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import org.springframework.util.StringUtils;
import org.tron.core.db.api.index.Index;
import org.tron.core.db.api.index.TransactionIndex;
import org.tron.protos.Contract.AssetIssueContract;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Witness;

@Component
@Slf4j
Expand Down Expand Up @@ -119,17 +117,17 @@ public List<Transaction> getTransactionsToThis(String address, long offset, long
* witness api *
*******************************************************************************
*/
public List<Witness> getWitnessAll() {
Index.Iface<Witness> index = indexHelper.getWitnessIndex();
return ImmutableList.copyOf(index);
}
// public List<Witness> getWitnessAll() {
// Index.Iface<Witness> index = indexHelper.getWitnessIndex();
// return ImmutableList.copyOf(index);
// }

/********************************************************************************
* AssetIssue api *
********************************************************************************
*/
public List<AssetIssueContract> getAssetIssueAll() {
Index.Iface<AssetIssueContract> index = indexHelper.getAssetIssueIndex();
return ImmutableList.copyOf(index);
}
// public List<AssetIssueContract> getAssetIssueAll() {
// Index.Iface<AssetIssueContract> index = indexHelper.getAssetIssueIndex();
// return ImmutableList.copyOf(index);
// }
}
4 changes: 2 additions & 2 deletions src/main/java/org/tron/core/services/RpcApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ public void getAccount(Account request, StreamObserver<Account> responseObserver

@Override
public void listWitnesses(EmptyMessage request, StreamObserver<WitnessList> responseObserver) {
responseObserver.onNext(walletSolidity.getWitnessList());
responseObserver.onNext(wallet.getWitnessList());
responseObserver.onCompleted();
}

@Override
public void getAssetIssueList(EmptyMessage request,
StreamObserver<AssetIssueList> responseObserver) {
responseObserver.onNext(walletSolidity.getAssetIssueList());
responseObserver.onNext(wallet.getAssetIssueList());
responseObserver.onCompleted();
}

Expand Down
101 changes: 10 additions & 91 deletions src/main/protos/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ service Wallet {
};

rpc CreateWitness (WitnessCreateContract) returns (Transaction) {
option (google.api.http) = {
post: "/wallet/createwitness"
body: "*"
additional_bindings {
get: "/wallet/createwitness"
}
};
option (google.api.http) = {
post: "/wallet/createwitness"
body: "*"
additional_bindings {
get: "/wallet/createwitness"
}
};
};

rpc TransferAsset (TransferAssetContract) returns (Transaction) {
option (google.api.http) = {
Expand Down Expand Up @@ -192,14 +192,14 @@ service Wallet {
};
}
rpc GetAccountNet (Account) returns (AccountNetMessage) {
option (google.api.http) = {
option (google.api.http) = {
post: "/wallet/getaccountnet"
body: "*"
additional_bindings {
get: "/wallet/getaccountnet"
}
};
};
};
rpc GetAssetIssueByName (BytesMessage) returns (AssetIssueContract) {
option (google.api.http) = {
post: "/wallet/getassetissuebyname"
Expand Down Expand Up @@ -333,33 +333,6 @@ service WalletSolidity {
}
};
}
rpc GetAssetIssueListByTimestamp (NumberMessage) returns (AssetIssueList) {
option (google.api.http) = {
post: "/walletsolidity/getassetissuelistbytimestamp"
body: "*"
additional_bindings {
get: "/walletsolidity/getassetissuelistbytimestamp"
}
};
}
rpc GetAssetIssueByAccount (Account) returns (AssetIssueList) {
option (google.api.http) = {
post: "/walletsolidity/getassetissuebyaccount"
body: "*"
additional_bindings {
get: "/walletsolidity/getassetissuebyaccount"
}
};
}
rpc GetAssetIssueByName (BytesMessage) returns (AssetIssueContract) {
option (google.api.http) = {
post: "/walletsolidity/getassetissuebyname"
body: "*"
additional_bindings {
get: "/walletsolidity/getassetissuebyname"
}
};
}
rpc GetNowBlock (EmptyMessage) returns (Block) {
option (google.api.http) = {
post: "/walletsolidity/getnowblock"
Expand All @@ -378,46 +351,10 @@ service WalletSolidity {
}
};
}
//get transaction
rpc TotalTransaction (EmptyMessage) returns (NumberMessage) {
option (google.api.http) = {
post: "/walletsolidity/totaltransaction"
body: "*"
additional_bindings {
get: "/walletsolidity/totaltransaction"
}
};
}
rpc GetTransactionById (BytesMessage) returns (Transaction) {
option (google.api.http) = {
post: "/walletsolidity/gettransactionbyid"
body: "*"
additional_bindings {
get: "/walletsolidity/gettransactionbyid"
}
};
}
};

service WalletExtension {
rpc GetTransactionsByTimestamp (TimePaginatedMessage) returns (TransactionList) {
option (google.api.http) = {
post: "/walletextension/gettransactionsbytimestamp"
body: "*"
additional_bindings {
get: "/walletextension/gettransactionsbytimestamp"
}
};
}
rpc GetTransactionsByTimestampCount (TimeMessage) returns (NumberMessage) {
option (google.api.http) = {
post: "/walletextension/gettransactionsbytimestampcount"
body: "*"
additional_bindings {
get: "/walletextension/gettransactionsbytimestampcount"
}
};
}

rpc GetTransactionsFromThis (AccountPaginated) returns (TransactionList) {
option (google.api.http) = {
post: "/walletextension/gettransactionsfromthis"
Expand All @@ -436,24 +373,6 @@ service WalletExtension {
}
};
}
rpc GetTransactionsFromThisCount (Account) returns (NumberMessage) {
option (google.api.http) = {
post: "/walletextension/gettransactionsfromthiscount"
body: "*"
additional_bindings {
get: "/walletextension/gettransactionsfromthiscount"
}
};
}
rpc GetTransactionsToThisCount (Account) returns (NumberMessage) {
option (google.api.http) = {
post: "/walletextension/gettransactionstothiscount"
body: "*"
additional_bindings {
get: "/walletextension/gettransactionstothiscount"
}
};
}
};

// the api of tron's db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ public class WalletTestAccount003 {
private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list")
.get(0);

/* ECKey ecKey = new ECKey(Utils.getRandom());
byte[] NOWITNESSADDRESS = ecKey.getAddress();
String testKeyForNoWitness = ByteArray.toHexString(ecKey.getPrivKeyBytes());*/
//get account
ECKey ecKey1 = new ECKey(Utils.getRandom());
byte[] noBandwitchAddress = ecKey1.getAddress();
String noBandwitch = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

@BeforeClass
public void beforeClass() {
Expand All @@ -104,10 +105,11 @@ public void testCreateAccount() {

//TestVoteToNonWitnessAccount
HashMap<String, String> voteToNonWitnessAccount = new HashMap<String, String>();
voteToNonWitnessAccount.put("27dUQbeRLz6BavhUJE6UbNp5AtAtPuzNZv6", "1");
voteToNonWitnessAccount.put("27dUQbeRLz6BavhUJE6UbNp5AtAtPuzNZv6", "3");
HashMap<String, String> voteToInvaildAddress = new HashMap<String, String>();
voteToInvaildAddress.put("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48", "1");
voteToInvaildAddress.put("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48", "4");
Assert.assertTrue(freezeBalance(FROM_ADDRESS, 10000000L, 3L, testKey002));
voteWitness(voteToNonWitnessAccount, FROM_ADDRESS, testKey002);
Assert.assertFalse(voteWitness(voteToNonWitnessAccount, FROM_ADDRESS, testKey002));
Assert.assertFalse(voteWitness(voteToInvaildAddress, FROM_ADDRESS, testKey002));

Expand Down Expand Up @@ -469,9 +471,9 @@ public Boolean voteWitness(HashMap<String, String> witness, byte[] address, Stri
.newBuilder();
byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58);
if (addRess == null) {
continue;
return false;
}
voteBuilder.setVoteAddress(ByteString.copyFrom(address));
voteBuilder.setVoteAddress(ByteString.copyFrom(addRess));
voteBuilder.setVoteCount(count);
builder.addVotes(voteBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura
}

Long afterBlockNum = 0L;

while (afterBlockNum < beforeBlockNum) {
Integer wait = 0;
while (afterBlockNum < beforeBlockNum && wait < 10) {
Block currentBlock1 = searchBlockingStubFull.getNowBlock(EmptyMessage.newBuilder().build());
afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber();
wait++;
try {
Thread.sleep(2000);
logger.info("wait 2 second");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import org.tron.api.WalletGrpc;
import org.tron.api.WalletSolidityGrpc;
import org.tron.common.crypto.ECKey;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Utils;
import org.tron.protos.Protocol.Account;
import org.tron.protos.Protocol.Block;
import stest.tron.wallet.common.client.Configuration;
import stest.tron.wallet.common.client.utils.Base58;
import stest.tron.wallet.common.client.utils.PublicMethed;

@Slf4j
public class WalletTestAssetIssue006 {
Expand Down Expand Up @@ -53,14 +56,22 @@ public class WalletTestAssetIssue006 {
private ManagedChannel channelSolidity = null;
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;

private static final long now = System.currentTimeMillis();

private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list")
.get(0);
private String soliditynode = Configuration.getByPath("testng.conf")
.getStringList("solidityNode.ip.list").get(0);

private static final long now = System.currentTimeMillis();
private static String name = "assetissue006" + Long.toString(now);
private static final long totalSupply = now;
String description = "test query assetissue by timestamp from soliditynode";
String url = "https://testqueryassetissue.com/bytimestamp/from/soliditynode/";

//get account
ECKey ecKey = new ECKey(Utils.getRandom());
byte[] queryAssetIssueFromSoliAddress = ecKey.getAddress();
String queryAssetIssueKey = ByteArray.toHexString(ecKey.getPrivKeyBytes());

@BeforeClass
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
Expand All @@ -72,10 +83,42 @@ public void beforeClass() {
.usePlaintext(true)
.build();
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);

Assert.assertTrue(PublicMethed.freezeBalance(FROM_ADDRESS,10000000,3,testKey002,
blockingStubFull));
Assert.assertTrue(PublicMethed.sendcoin(queryAssetIssueFromSoliAddress,2048000000,FROM_ADDRESS,
testKey002,blockingStubFull));
Long start = System.currentTimeMillis() + 2000;
Long end = System.currentTimeMillis() + 1000000000;
//Create a new AssetIssue success.
Assert.assertTrue(PublicMethed.createAssetIssue(queryAssetIssueFromSoliAddress, name,
totalSupply, 1, 100, start, end, 1, description, url, 1000L,
1000L,1L,1L,queryAssetIssueKey,blockingStubFull));
}

@Test(enabled = true)
/* @Test(enabled = true)
public void testGetAssetIssueListByTimestamp() {
Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build());
Block solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage
.newBuilder().build());
Integer wait = 0;
while (solidityCurrentBlock.getBlockHeader().getRawData().getNumber()
< currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 10) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("Solidity didn't synchronize the fullnode block,please wait");
solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder()
.build());
wait++;
if (wait == 9) {
logger.info("Didn't syn,skip to next case.");
}
}


long time = now;
NumberMessage.Builder timeStamp = NumberMessage.newBuilder();
timeStamp.setNum(time);
Expand Down Expand Up @@ -117,7 +160,7 @@ public void testExceptionGetAssetIssueListByTimestamp() {
getAssetIssueListByTimestamp = Optional.ofNullable(assetIssueList);
Assert.assertTrue(getAssetIssueListByTimestamp.get().getAssetIssueCount() == 0);

}
}*/

@AfterClass
public void shutdown() throws InterruptedException {
Expand Down
Loading