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 11, 2023
1 parent 0c928f0 commit 2ceb1fa
Show file tree
Hide file tree
Showing 15 changed files with 1,547 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public void testTxProof() {
if (transactionResponse == null && block.getNumber() == 0) {
return;
}
if (client.getChainCompatibilityVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) < 0) {
return;
}
if (client.getCryptoSuite().cryptoTypeConfig == CryptoType.ECDSA_TYPE) {
boolean verifyMerkle = MerkleProofUtility.verifyMerkle(block.getTransactionsRoot(), transactionResponse.getTxProof(), transactionResponse.getHash(), new Keccak256());
Assert.assertTrue(verifyMerkle);
Expand Down

Large diffs are not rendered by default.

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 2ceb1fa

Please sign in to comment.