Skip to content

Commit 38d913f

Browse files
committed
feat: make tck server thread safe
Signed-off-by: emiliyank <e.kadiyski@gmail.com>
1 parent 31d97de commit 38d913f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+405
-172
lines changed

tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/AccountService.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ public AccountService(SdkService sdkService) {
2626
@JSONRPC2Method("createAccount")
2727
public AccountResponse createAccount(final AccountCreateParams params) throws Exception {
2828
AccountCreateTransaction accountCreateTransaction = TransactionBuilders.AccountBuilder.buildCreate(params);
29+
Client client = sdkService.getClient(params.getSessionId());
2930

3031
params.getCommonTransactionParams()
3132
.ifPresent(commonTransactionParams ->
32-
commonTransactionParams.fillOutTransaction(accountCreateTransaction, sdkService.getClient()));
33+
commonTransactionParams.fillOutTransaction(accountCreateTransaction, client));
3334

3435
TransactionReceipt transactionReceipt =
35-
accountCreateTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
36+
accountCreateTransaction.execute(client).getReceipt(client);
3637

3738
String stringAccountId = "";
3839
if (transactionReceipt.status == Status.SUCCESS) {
@@ -45,52 +46,52 @@ public AccountResponse createAccount(final AccountCreateParams params) throws Ex
4546
@JSONRPC2Method("updateAccount")
4647
public AccountResponse updateAccount(final AccountUpdateParams params) throws Exception {
4748
AccountUpdateTransaction accountUpdateTransaction = TransactionBuilders.AccountBuilder.buildUpdate(params);
49+
Client client = sdkService.getClient(params.getSessionId());
4850

4951
params.getCommonTransactionParams()
5052
.ifPresent(commonTransactionParams ->
51-
commonTransactionParams.fillOutTransaction(accountUpdateTransaction, sdkService.getClient()));
53+
commonTransactionParams.fillOutTransaction(accountUpdateTransaction, client));
5254

5355
TransactionReceipt transactionReceipt =
54-
accountUpdateTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
56+
accountUpdateTransaction.execute(client).getReceipt(client);
5557

5658
return new AccountResponse(null, transactionReceipt.status);
5759
}
5860

5961
@JSONRPC2Method("deleteAccount")
6062
public AccountResponse deleteAccount(final AccountDeleteParams params) throws Exception {
6163
AccountDeleteTransaction accountDeleteTransaction = TransactionBuilders.AccountBuilder.buildDelete(params);
64+
Client client = sdkService.getClient(params.getSessionId());
6265

6366
params.getCommonTransactionParams()
6467
.ifPresent(commonTransactionParams ->
65-
commonTransactionParams.fillOutTransaction(accountDeleteTransaction, sdkService.getClient()));
68+
commonTransactionParams.fillOutTransaction(accountDeleteTransaction, client));
6669

6770
TransactionReceipt transactionReceipt =
68-
accountDeleteTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
71+
accountDeleteTransaction.execute(client).getReceipt(client);
6972

7073
return new AccountResponse(null, transactionReceipt.status);
7174
}
7275

7376
@JSONRPC2Method("approveAllowance")
7477
public AccountAllowanceResponse approveAllowance(final AccountAllowanceParams params) throws Exception {
7578
AccountAllowanceApproveTransaction tx = TransactionBuilders.AccountBuilder.buildApproveAllowance(params);
79+
Client client = sdkService.getClient(params.getSessionId());
7680

77-
params.getCommonTransactionParams()
78-
.ifPresent(commonParams -> commonParams.fillOutTransaction(tx, sdkService.getClient()));
81+
params.getCommonTransactionParams().ifPresent(commonParams -> commonParams.fillOutTransaction(tx, client));
7982

80-
TransactionReceipt transactionReceipt =
81-
tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
83+
TransactionReceipt transactionReceipt = tx.execute(client).getReceipt(client);
8284
return new AccountAllowanceResponse(transactionReceipt.status);
8385
}
8486

8587
@JSONRPC2Method("deleteAllowance")
8688
public AccountAllowanceResponse deleteAllowance(final AccountAllowanceParams params) throws Exception {
8789
AccountAllowanceDeleteTransaction tx = TransactionBuilders.AccountBuilder.buildDeleteAllowance(params);
90+
Client client = sdkService.getClient(params.getSessionId());
8891

89-
params.getCommonTransactionParams()
90-
.ifPresent(commonParams -> commonParams.fillOutTransaction(tx, sdkService.getClient()));
92+
params.getCommonTransactionParams().ifPresent(commonParams -> commonParams.fillOutTransaction(tx, client));
9193

92-
TransactionReceipt transactionReceipt =
93-
tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
94+
TransactionReceipt transactionReceipt = tx.execute(client).getReceipt(client);
9495
return new AccountAllowanceResponse(transactionReceipt.status);
9596
}
9697

@@ -104,13 +105,12 @@ public AccountAllowanceResponse deleteAllowance(final AccountAllowanceParams par
104105
@JSONRPC2Method("transferCrypto")
105106
public Map<String, String> transferCrypto(final TransferCryptoParams params) throws Exception {
106107
TransferTransaction transferTransaction = TransactionBuilders.TransferBuilder.buildTransfer(params);
108+
Client client = sdkService.getClient(params.getSessionId());
107109

108110
params.getCommonTransactionParams()
109-
.ifPresent(
110-
commonParams -> commonParams.fillOutTransaction(transferTransaction, sdkService.getClient()));
111+
.ifPresent(commonParams -> commonParams.fillOutTransaction(transferTransaction, client));
111112

112-
TransactionReceipt receipt =
113-
transferTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
113+
TransactionReceipt receipt = transferTransaction.execute(client).getReceipt(client);
114114

115115
return Map.of("status", receipt.status.toString());
116116
}

tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/ContractService.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public ContractService(SdkService sdkService) {
2828
@JSONRPC2Method("createContract")
2929
public ContractResponse createContract(final CreateContractParams params) throws Exception {
3030
ContractCreateTransaction transaction = new ContractCreateTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
31+
Client client = sdkService.getClient(params.getSessionId());
3132

3233
params.getAdminKey().ifPresent(key -> {
3334
try {
@@ -66,10 +67,9 @@ public ContractResponse createContract(final CreateContractParams params) throws
6667

6768
params.getConstructorParameters().ifPresent(hex -> transaction.setConstructorParameters(Hex.decode(hex)));
6869

69-
params.getCommonTransactionParams()
70-
.ifPresent(common -> common.fillOutTransaction(transaction, sdkService.getClient()));
70+
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(transaction, client));
7171

72-
TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
72+
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);
7373

7474
String contractId = "";
7575
if (receipt.status == Status.SUCCESS && receipt.contractId != null) {
@@ -83,6 +83,7 @@ public ContractResponse createContract(final CreateContractParams params) throws
8383
public ContractResponse executeContract(final ExecuteContractParams params) throws Exception {
8484
ContractExecuteTransaction transaction =
8585
new ContractExecuteTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
86+
Client client = sdkService.getClient(params.getSessionId());
8687

8788
if (params.getContractId() != null) {
8889
transaction.setContractId(ContractId.fromString(params.getContractId()));
@@ -96,17 +97,17 @@ public ContractResponse executeContract(final ExecuteContractParams params) thro
9697
params.getFunctionParameters()
9798
.ifPresent(hex -> transaction.setFunctionParameters(ByteString.copyFrom(Hex.decode(hex))));
9899

99-
params.getCommonTransactionParams()
100-
.ifPresent(common -> common.fillOutTransaction(transaction, sdkService.getClient()));
100+
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(transaction, client));
101101

102-
TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
102+
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);
103103

104104
return new ContractResponse("", receipt.status);
105105
}
106106

107107
@JSONRPC2Method("updateContract")
108108
public ContractResponse updateContract(final UpdateContractParams params) throws Exception {
109109
ContractUpdateTransaction transaction = new ContractUpdateTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
110+
Client client = sdkService.getClient(params.getSessionId());
110111

111112
params.getContractId()
112113
.ifPresent(contractIdStr -> transaction.setContractId(ContractId.fromString(contractIdStr)));
@@ -146,17 +147,17 @@ public ContractResponse updateContract(final UpdateContractParams params) throws
146147
}
147148
});
148149

149-
params.getCommonTransactionParams()
150-
.ifPresent(common -> common.fillOutTransaction(transaction, sdkService.getClient()));
150+
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(transaction, client));
151151

152-
TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
152+
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);
153153

154154
return new ContractResponse(null, receipt.status);
155155
}
156156

157157
@JSONRPC2Method("deleteContract")
158158
public ContractResponse deleteContract(final DeleteContractParams params) throws Exception {
159159
ContractDeleteTransaction transaction = new ContractDeleteTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
160+
Client client = sdkService.getClient(params.getSessionId());
160161

161162
params.getContractId()
162163
.ifPresent(contractIdStr -> transaction.setContractId(ContractId.fromString(contractIdStr)));
@@ -177,10 +178,9 @@ public ContractResponse deleteContract(final DeleteContractParams params) throws
177178

178179
params.getPermanentRemoval().ifPresent(transaction::setPermanentRemoval);
179180

180-
params.getCommonTransactionParams()
181-
.ifPresent(common -> common.fillOutTransaction(transaction, sdkService.getClient()));
181+
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(transaction, client));
182182

183-
TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
183+
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);
184184

185185
return new ContractResponse(null, receipt.status);
186186
}

tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/FileService.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ public FileService(SdkService sdkService) {
2929
@JSONRPC2Method("createFile")
3030
public FileResponse createFile(final FileCreateParams params) throws Exception {
3131
FileCreateTransaction transaction = TransactionBuilders.FileBuilder.buildCreate(params);
32+
Client client = sdkService.getClient(params.getSessionId());
3233

3334
params.getCommonTransactionParams()
34-
.ifPresent(commonTransactionParams ->
35-
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
35+
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));
3636

37-
TransactionResponse txResponse = transaction.execute(sdkService.getClient());
38-
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
37+
TransactionResponse txResponse = transaction.execute(client);
38+
TransactionReceipt receipt = txResponse.getReceipt(client);
3939

4040
String fileId = "";
4141
if (receipt.status == Status.SUCCESS && receipt.fileId != null) {
@@ -48,41 +48,41 @@ public FileResponse createFile(final FileCreateParams params) throws Exception {
4848
@JSONRPC2Method("deleteFile")
4949
public FileResponse deleteFile(final FileDeleteParams params) throws Exception {
5050
FileDeleteTransaction transaction = TransactionBuilders.FileBuilder.buildDelete(params);
51+
Client client = sdkService.getClient(params.getSessionId());
5152

5253
params.getCommonTransactionParams()
53-
.ifPresent(commonTransactionParams ->
54-
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
54+
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));
5555

56-
TransactionResponse txResponse = transaction.execute(sdkService.getClient());
57-
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
56+
TransactionResponse txResponse = transaction.execute(client);
57+
TransactionReceipt receipt = txResponse.getReceipt(client);
5858

5959
return new FileResponse("", receipt.status);
6060
}
6161

6262
@JSONRPC2Method("updateFile")
6363
public FileResponse updateFile(final FileUpdateParams params) throws Exception {
6464
FileUpdateTransaction transaction = TransactionBuilders.FileBuilder.buildUpdate(params);
65+
Client client = sdkService.getClient(params.getSessionId());
6566

6667
params.getCommonTransactionParams()
67-
.ifPresent(commonTransactionParams ->
68-
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
68+
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));
6969

70-
TransactionResponse txResponse = transaction.execute(sdkService.getClient());
71-
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
70+
TransactionResponse txResponse = transaction.execute(client);
71+
TransactionReceipt receipt = txResponse.getReceipt(client);
7272

7373
return new FileResponse("", receipt.status);
7474
}
7575

7676
@JSONRPC2Method("appendFile")
7777
public FileResponse appendFile(final FileAppendParams params) throws Exception {
7878
FileAppendTransaction transaction = TransactionBuilders.FileBuilder.buildAppend(params);
79+
Client client = sdkService.getClient(params.getSessionId());
7980

8081
params.getCommonTransactionParams()
81-
.ifPresent(commonTransactionParams ->
82-
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
82+
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));
8383

84-
TransactionResponse txResponse = transaction.execute(sdkService.getClient());
85-
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
84+
TransactionResponse txResponse = transaction.execute(client);
85+
TransactionReceipt receipt = txResponse.getReceipt(client);
8686

8787
return new FileResponse("", receipt.status);
8888
}

tck/src/main/java/com/hedera/hashgraph/tck/methods/sdk/NodeService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public NodeService(SdkService sdkService) {
2929
@JSONRPC2Method("createNode")
3030
public NodeResponse createNode(final NodeCreateParams params) throws Exception {
3131
NodeCreateTransaction tx = new NodeCreateTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
32+
Client client = sdkService.getClient(params.getSessionId());
3233

3334
params.getAccountId().ifPresent(a -> tx.setAccountId(AccountId.fromString(a)));
3435
params.getDescription().ifPresent(tx::setDescription);
@@ -53,9 +54,9 @@ public NodeResponse createNode(final NodeCreateParams params) throws Exception {
5354

5455
params.getDeclineReward().ifPresent(tx::setDeclineReward);
5556

56-
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(tx, sdkService.getClient()));
57+
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(tx, client));
5758

58-
TransactionReceipt receipt = tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
59+
TransactionReceipt receipt = tx.execute(client).getReceipt(client);
5960

6061
String nodeId = receipt.nodeId > 0 ? Long.toString(receipt.nodeId) : "";
6162
return new NodeResponse(nodeId, receipt.status);
@@ -64,6 +65,7 @@ public NodeResponse createNode(final NodeCreateParams params) throws Exception {
6465
@JSONRPC2Method("updateNode")
6566
public NodeResponse updateNode(final NodeUpdateParams params) throws Exception {
6667
NodeUpdateTransaction tx = new NodeUpdateTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
68+
Client client = sdkService.getClient(params.getSessionId());
6769

6870
try {
6971
params.getNodeId().ifPresent(idStr -> tx.setNodeId(Long.parseLong(idStr)));
@@ -95,9 +97,9 @@ public NodeResponse updateNode(final NodeUpdateParams params) throws Exception {
9597

9698
params.getDeclineReward().ifPresent(tx::setDeclineReward);
9799

98-
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(tx, sdkService.getClient()));
100+
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(tx, client));
99101

100-
TransactionReceipt receipt = tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
102+
TransactionReceipt receipt = tx.execute(client).getReceipt(client);
101103

102104
String nodeId = receipt.nodeId > 0 ? Long.toString(receipt.nodeId) : "";
103105
return new NodeResponse(nodeId, receipt.status);
@@ -106,6 +108,7 @@ public NodeResponse updateNode(final NodeUpdateParams params) throws Exception {
106108
@JSONRPC2Method("deleteNode")
107109
public NodeResponse deleteNode(final NodeDeleteParams params) throws Exception {
108110
NodeDeleteTransaction tx = new NodeDeleteTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
111+
Client client = sdkService.getClient(params.getSessionId());
109112

110113
try {
111114
params.getNodeId().ifPresent(idStr -> tx.setNodeId(Long.parseLong(idStr)));
@@ -114,9 +117,9 @@ public NodeResponse deleteNode(final NodeDeleteParams params) throws Exception {
114117
tx.setNodeId(Long.MAX_VALUE);
115118
}
116119

117-
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(tx, sdkService.getClient()));
120+
params.getCommonTransactionParams().ifPresent(common -> common.fillOutTransaction(tx, client));
118121

119-
TransactionReceipt receipt = tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
122+
TransactionReceipt receipt = tx.execute(client).getReceipt(client);
120123

121124
String nodeId = receipt.nodeId > 0 ? Long.toString(receipt.nodeId) : "";
122125
return new NodeResponse(nodeId, receipt.status);

0 commit comments

Comments
 (0)