Skip to content

Commit

Permalink
<rec&fix>(transaction): refator transaction request, fix v2 assemble …
Browse files Browse the repository at this point in the history
…transaction service bug.
  • Loading branch information
kyonRay committed Dec 28, 2023
1 parent 985e86b commit 237b67f
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,43 @@
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.BasicDeployRequest;
import org.fisco.bcos.sdk.v3.transaction.manager.transactionv2.dto.BasicRequest;
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)
public TransactionResponse sendEIP1559Transaction(BasicRequest 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));
if (!request.isTransactionEssentialSatisfy()) {
throw new ContractCodecException("Request is not satisfy, please check.");
}
byte[] encodeMethod = null;
if (request instanceof TransactionRequest) {
encodeMethod =
contractCodec.encodeMethod(
request.getAbi(),
request.getMethod(),
((TransactionRequest) request).getParams());
} else if (request instanceof TransactionRequestWithStringParams) {
encodeMethod =
contractCodec.encodeMethodFromString(
request.getAbi(),
request.getMethod(),
((TransactionRequestWithStringParams) request).getStringParams());
} else {
throw new ContractCodecException("Request type error, please check.");
}
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(),
Expand All @@ -68,32 +59,29 @@ public TransactionResponse sendEIP1559TransactionWithStringParams(
request.getAbi(), request.getMethod(), receipt);
}

public TransactionResponse deployContractEIP1559(DeployTransactionRequest request)
public TransactionResponse deployContractEIP1559(BasicDeployRequest 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));
if (!request.isTransactionEssentialSatisfy()) {
throw new ContractCodecException("DeployRequest is not satisfy, please check.");
}

byte[] encodeConstructor = null;
if (request instanceof DeployTransactionRequest) {
encodeConstructor =
contractCodec.encodeConstructor(
request.getAbi(),
request.getBin(),
((DeployTransactionRequest) request).getParams());
} else if (request instanceof DeployTransactionRequestWithStringParams) {
encodeConstructor =
contractCodec.encodeConstructorFromString(
request.getAbi(),
request.getBin(),
((DeployTransactionRequestWithStringParams) request).getStringParams());
} else {
throw new ContractCodecException("DeployRequest type error, please check.");
}
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(),
Expand All @@ -109,28 +97,28 @@ public TransactionResponse deployContractEIP1559WithStringParams(
return this.transactionDecoder.decodeReceiptWithValues(request.getAbi(), "", receipt);
}

public String asyncSendEIP1559Transaction(
TransactionRequest request, TransactionCallback callback)
public String asyncSendEIP1559Transaction(BasicRequest 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);
}
if (!request.isTransactionEssentialSatisfy()) {
throw new ContractCodecException("Request is not satisfy, please check.");
}
byte[] encodeMethod = null;
if (request instanceof TransactionRequest) {
encodeMethod =
contractCodec.encodeMethod(
request.getAbi(),
request.getMethod(),
((TransactionRequest) request).getParams());
} else if (request instanceof TransactionRequestWithStringParams) {
encodeMethod =
contractCodec.encodeMethodFromString(
request.getAbi(),
request.getMethod(),
((TransactionRequestWithStringParams) request).getStringParams());
} else {
throw new ContractCodecException("Request type error, please check.");
}

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),
Expand All @@ -142,27 +130,29 @@ public String asyncSendEIP1559TransactionWithStringParams(
}

public String asyncDeployContractEIP1559(
DeployTransactionRequest request, TransactionCallback callback)
BasicDeployRequest 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);
}
if (!request.isTransactionEssentialSatisfy()) {
throw new ContractCodecException("DeployRequest is not satisfy, please check.");
}

byte[] encodeConstructor = null;
if (request instanceof DeployTransactionRequest) {
encodeConstructor =
contractCodec.encodeConstructor(
request.getAbi(),
request.getBin(),
((DeployTransactionRequest) request).getParams());
} else if (request instanceof DeployTransactionRequestWithStringParams) {
encodeConstructor =
contractCodec.encodeConstructorFromString(
request.getAbi(),
request.getBin(),
((DeployTransactionRequestWithStringParams) request).getStringParams());
} else {
throw new ContractCodecException("DeployRequest type error, please check.");
}

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),
Expand Down
Loading

0 comments on commit 237b67f

Please sign in to comment.