Skip to content

Commit

Permalink
<feat>(transaction): impl AssembleTransactionService, add integration…
Browse files Browse the repository at this point in the history
… test of it.
  • Loading branch information
kyonRay committed Dec 5, 2023
1 parent 154f566 commit fb8490a
Show file tree
Hide file tree
Showing 14 changed files with 1,523 additions and 213 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/org/fisco/bcos/sdk/v3/BcosSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void registerBlockNotifier(String groupID, BlockNotifier blockNotifier) {
*/
public Client getClient(String groupId) throws BcosSDKException {
try {
return Client.build(groupId, config);
return Client.build(groupId, config, bcosSDKJniObj);
} catch (Exception e) {
logger.warn("create client for failed, error: ", e);
throw new BcosSDKException("get Client failed, e: " + e.getMessage(), e);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,12 @@ public Pair<List<Object>, List<ABIObject>> decodeMethodAndGetOutputObject(
return ContractCodecTools.decodeJavaObjectAndGetOutputObject(abiObject);
}

public Pair<List<Object>, List<ABIObject>> decodeMethodOutputAndGetObject(
String abi, String methodName, String output) throws ContractCodecException {
ABIObject abiObject = decodeMethodAndGetOutputAbiObject(abi, methodName, output);
return ContractCodecTools.decodeJavaObjectAndGetOutputObject(abiObject);
}

public ABIObject decodeMethodAndGetOutAbiObjectByABIDefinition(
ABIDefinition abiDefinition, String output) throws ContractCodecException {
ABIObject outputABIObject = ABIObjectFactory.createOutputObject(abiDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public class Constant {
public static final BigInteger MIN_INT128 = MAX_INT128.negate();

public static String NO_APPROPRIATE_ABI_METHOD =
"Cann't encode in encodeMethodFromObject with appropriate interface ABI, please check your method name or ABI file";
"Can't encode in encodeMethodFromObject with appropriate interface ABI, please check your method name or ABI file";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package org.fisco.bcos.sdk.v3.transaction.manager.Transactionv2;

import java.util.Objects;
import org.fisco.bcos.sdk.jni.common.JniException;
import org.fisco.bcos.sdk.v3.client.Client;
import org.fisco.bcos.sdk.v3.codec.ContractCodecException;
import org.fisco.bcos.sdk.v3.model.TransactionReceipt;
import org.fisco.bcos.sdk.v3.model.callback.TransactionCallback;
import org.fisco.bcos.sdk.v3.transaction.manager.Transactionv2.dto.DeployTransactionRequest;
import org.fisco.bcos.sdk.v3.transaction.manager.Transactionv2.dto.DeployTransactionRequestWithStringParams;
import org.fisco.bcos.sdk.v3.transaction.manager.Transactionv2.dto.TransactionRequest;
import org.fisco.bcos.sdk.v3.transaction.manager.Transactionv2.dto.TransactionRequestWithStringParams;
import org.fisco.bcos.sdk.v3.transaction.model.dto.TransactionResponse;
import org.fisco.bcos.sdk.v3.utils.Hex;

/**
* AssembleTransactionService
*
* <p>codec(abi, method, params) -> inputData sendTx(to, inputData) -> receipt decode(abi, method,
* receipt.output, ) -> result
*/
public class AssembleEIP1559TransactionService extends AssembleTransactionService {

AssembleEIP1559TransactionService(Client client) {
super(client);
}

public TransactionResponse sendEIP1559Transaction(TransactionRequest request)
throws ContractCodecException, JniException {
byte[] encodeMethod =
contractCodec.encodeMethod(
request.getAbi(), request.getMethod(), request.getParams());
TransactionReceipt receipt =
transactionManager.sendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeMethod),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
false);
if (Objects.nonNull(receipt)
&& (Objects.isNull(receipt.getInput()) || receipt.getInput().isEmpty())) {
receipt.setInput(Hex.toHexStringWithPrefix(encodeMethod));
}
return this.transactionDecoder.decodeReceiptWithValues(
request.getAbi(), request.getMethod(), receipt);
}

public TransactionResponse sendEIP1559TransactionWithStringParams(
TransactionRequestWithStringParams request)
throws ContractCodecException, JniException {
byte[] encodeMethod =
contractCodec.encodeMethodFromString(
request.getAbi(), request.getMethod(), request.getStringParams());
TransactionReceipt receipt =
transactionManager.sendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeMethod),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
false);
if (Objects.nonNull(receipt)
&& (Objects.isNull(receipt.getInput()) || receipt.getInput().isEmpty())) {
receipt.setInput(Hex.toHexStringWithPrefix(encodeMethod));
}
return this.transactionDecoder.decodeReceiptWithValues(
request.getAbi(), request.getMethod(), receipt);
}

public TransactionResponse deployContractEIP1559(DeployTransactionRequest request)
throws ContractCodecException, JniException {
byte[] encodeConstructor =
contractCodec.encodeConstructor(
request.getAbi(), request.getBin(), request.getParams());
TransactionReceipt receipt =
transactionManager.sendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeConstructor),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
true);
if (Objects.nonNull(receipt)
&& (Objects.isNull(receipt.getInput()) || receipt.getInput().isEmpty())) {
receipt.setInput(Hex.toHexStringWithPrefix(encodeConstructor));
}
return this.transactionDecoder.decodeReceiptWithValues(request.getAbi(), "", receipt);
}

public TransactionResponse deployContractEIP1559WithStringParams(
DeployTransactionRequestWithStringParams request)
throws ContractCodecException, JniException {
byte[] encodeConstructor =
contractCodec.encodeConstructorFromString(
request.getAbi(), request.getBin(), request.getStringParams());
TransactionReceipt receipt =
transactionManager.sendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeConstructor),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
true);
if (Objects.nonNull(receipt)
&& (Objects.isNull(receipt.getInput()) || receipt.getInput().isEmpty())) {
receipt.setInput(Hex.toHexStringWithPrefix(encodeConstructor));
}
return this.transactionDecoder.decodeReceiptWithValues(request.getAbi(), "", receipt);
}

public String asyncSendEIP1559Transaction(
TransactionRequest request, TransactionCallback callback)
throws ContractCodecException, JniException {
byte[] encodeMethod =
contractCodec.encodeMethod(
request.getAbi(), request.getMethod(), request.getParams());
return transactionManager.asyncSendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeMethod),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
false,
callback);
}

public String asyncSendEIP1559TransactionWithStringParams(
TransactionRequestWithStringParams request, TransactionCallback callback)
throws ContractCodecException, JniException {
byte[] encodeMethod =
contractCodec.encodeMethodFromString(
request.getAbi(), request.getMethod(), request.getStringParams());
return transactionManager.asyncSendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeMethod),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
false,
callback);
}

public String asyncDeployContractEIP1559(
DeployTransactionRequest request, TransactionCallback callback)
throws ContractCodecException, JniException {
byte[] encodeConstructor =
contractCodec.encodeConstructor(
request.getAbi(), request.getBin(), request.getParams());
return transactionManager.asyncSendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeConstructor),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
true,
callback);
}

public String asyncDeployContractEIP1559WithStringParams(
DeployTransactionRequestWithStringParams request, TransactionCallback callback)
throws ContractCodecException, JniException {
byte[] encodeConstructor =
contractCodec.encodeConstructorFromString(
request.getAbi(), request.getBin(), request.getStringParams());
return transactionManager.asyncSendTransactionEIP1559(
request.getTo(),
Hex.toHexString(encodeConstructor),
request.getValue(),
request.getEip1559Struct(),
request.getAbi(),
true,
callback);
}
}
Loading

0 comments on commit fb8490a

Please sign in to comment.