Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ private TransferTransaction doAddHbarTransfer(AccountId accountId, Hbar value, b
requireNotFrozen();

for (var transfer : hbarTransfers) {
if (transfer.accountId.equals(accountId) && transfer.isApproved == isApproved) {
transfer.amount = Hbar.fromTinybars(transfer.amount.toTinybars() + value.toTinybars());
if (transfer.accountId.equals(accountId)) {
long combinedTinybars = transfer.amount.toTinybars() + value.toTinybars();
transfer.amount = Hbar.fromTinybars(combinedTinybars);
transfer.isApproved = transfer.isApproved || isApproved;
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ public AccountService(SdkService sdkService) {
@JSONRPC2Method("createAccount")
public AccountResponse createAccount(final AccountCreateParams params) throws Exception {
AccountCreateTransaction accountCreateTransaction = TransactionBuilders.AccountBuilder.buildCreate(params);
Client client = sdkService.getClient(params.getSessionId());

params.getCommonTransactionParams()
.ifPresent(commonTransactionParams ->
commonTransactionParams.fillOutTransaction(accountCreateTransaction, sdkService.getClient()));
commonTransactionParams.fillOutTransaction(accountCreateTransaction, client));

TransactionReceipt transactionReceipt =
accountCreateTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
accountCreateTransaction.execute(client).getReceipt(client);

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

params.getCommonTransactionParams()
.ifPresent(commonTransactionParams ->
commonTransactionParams.fillOutTransaction(accountUpdateTransaction, sdkService.getClient()));
commonTransactionParams.fillOutTransaction(accountUpdateTransaction, client));

TransactionReceipt transactionReceipt =
accountUpdateTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
accountUpdateTransaction.execute(client).getReceipt(client);

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

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

params.getCommonTransactionParams()
.ifPresent(commonTransactionParams ->
commonTransactionParams.fillOutTransaction(accountDeleteTransaction, sdkService.getClient()));
commonTransactionParams.fillOutTransaction(accountDeleteTransaction, client));

TransactionReceipt transactionReceipt =
accountDeleteTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
accountDeleteTransaction.execute(client).getReceipt(client);

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

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

params.getCommonTransactionParams()
.ifPresent(commonParams -> commonParams.fillOutTransaction(tx, sdkService.getClient()));
params.getCommonTransactionParams().ifPresent(commonParams -> commonParams.fillOutTransaction(tx, client));

TransactionReceipt transactionReceipt =
tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt transactionReceipt = tx.execute(client).getReceipt(client);
return new AccountAllowanceResponse(transactionReceipt.status);
}

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

params.getCommonTransactionParams()
.ifPresent(commonParams -> commonParams.fillOutTransaction(tx, sdkService.getClient()));
params.getCommonTransactionParams().ifPresent(commonParams -> commonParams.fillOutTransaction(tx, client));

TransactionReceipt transactionReceipt =
tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt transactionReceipt = tx.execute(client).getReceipt(client);
return new AccountAllowanceResponse(transactionReceipt.status);
}

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

params.getCommonTransactionParams()
.ifPresent(
commonParams -> commonParams.fillOutTransaction(transferTransaction, sdkService.getClient()));
.ifPresent(commonParams -> commonParams.fillOutTransaction(transferTransaction, client));

TransactionReceipt receipt =
transferTransaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = transferTransaction.execute(client).getReceipt(client);

return Map.of("status", receipt.status.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public ContractService(SdkService sdkService) {
@JSONRPC2Method("createContract")
public ContractResponse createContract(final CreateContractParams params) throws Exception {
ContractCreateTransaction transaction = new ContractCreateTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
Client client = sdkService.getClient(params.getSessionId());

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

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

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

TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);

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

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

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

TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);

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

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

params.getContractId()
.ifPresent(contractIdStr -> transaction.setContractId(ContractId.fromString(contractIdStr)));
Expand Down Expand Up @@ -146,17 +147,17 @@ public ContractResponse updateContract(final UpdateContractParams params) throws
}
});

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

TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);

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

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

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

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

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

TransactionReceipt receipt = transaction.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = transaction.execute(client).getReceipt(client);

return new ContractResponse(null, receipt.status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public FileService(SdkService sdkService) {
@JSONRPC2Method("createFile")
public FileResponse createFile(final FileCreateParams params) throws Exception {
FileCreateTransaction transaction = TransactionBuilders.FileBuilder.buildCreate(params);
Client client = sdkService.getClient(params.getSessionId());

params.getCommonTransactionParams()
.ifPresent(commonTransactionParams ->
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));

TransactionResponse txResponse = transaction.execute(sdkService.getClient());
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
TransactionResponse txResponse = transaction.execute(client);
TransactionReceipt receipt = txResponse.getReceipt(client);

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

params.getCommonTransactionParams()
.ifPresent(commonTransactionParams ->
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));

TransactionResponse txResponse = transaction.execute(sdkService.getClient());
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
TransactionResponse txResponse = transaction.execute(client);
TransactionReceipt receipt = txResponse.getReceipt(client);

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

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

params.getCommonTransactionParams()
.ifPresent(commonTransactionParams ->
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));

TransactionResponse txResponse = transaction.execute(sdkService.getClient());
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
TransactionResponse txResponse = transaction.execute(client);
TransactionReceipt receipt = txResponse.getReceipt(client);

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

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

params.getCommonTransactionParams()
.ifPresent(commonTransactionParams ->
commonTransactionParams.fillOutTransaction(transaction, sdkService.getClient()));
.ifPresent(commonTransactionParams -> commonTransactionParams.fillOutTransaction(transaction, client));

TransactionResponse txResponse = transaction.execute(sdkService.getClient());
TransactionReceipt receipt = txResponse.getReceipt(sdkService.getClient());
TransactionResponse txResponse = transaction.execute(client);
TransactionReceipt receipt = txResponse.getReceipt(client);

return new FileResponse("", receipt.status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public NodeService(SdkService sdkService) {
@JSONRPC2Method("createNode")
public NodeResponse createNode(final NodeCreateParams params) throws Exception {
NodeCreateTransaction tx = new NodeCreateTransaction().setGrpcDeadline(DEFAULT_GRPC_DEADLINE);
Client client = sdkService.getClient(params.getSessionId());

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

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

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

TransactionReceipt receipt = tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = tx.execute(client).getReceipt(client);

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

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

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

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

TransactionReceipt receipt = tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = tx.execute(client).getReceipt(client);

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

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

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

TransactionReceipt receipt = tx.execute(sdkService.getClient()).getReceipt(sdkService.getClient());
TransactionReceipt receipt = tx.execute(client).getReceipt(client);

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