@@ -62,6 +62,124 @@ public void setNonceProvider(NonceAndBlockLimitProvider nonceProvider) {
6262 this .nonceProvider = nonceProvider ;
6363 }
6464
65+ /**
66+ * This method is used to send transaction.
67+ *
68+ * @param request An instance of AbiEncodedRequest which contains the necessary information to
69+ * create a transaction: if it is a contract creation, request should setCreate(true), and
70+ * the abi field should be set; if it is EIP1559 transaction, request should set
71+ * EIP1559Struct.
72+ * @return An instance of TxPair which contains the signed transaction and the transaction hash.
73+ * @throws JniException If there is an error during the JNI operation.
74+ */
75+ @ Override
76+ public TransactionReceipt sendTransaction (AbiEncodedRequest request ) throws JniException {
77+ String signedTransaction = createSignedTransaction (request ).getSignedTx ();
78+ BcosTransactionReceipt bcosTransactionReceipt =
79+ client .sendTransaction (signedTransaction , false );
80+ return bcosTransactionReceipt .getTransactionReceipt ();
81+ }
82+
83+ /**
84+ * This method is used to send transaction asynchronously.
85+ *
86+ * @param request An instance of AbiEncodedRequest which contains the necessary information to
87+ * create a transaction: if it is a contract creation, request should setCreate(true), and
88+ * the abi field should be set; if it is EIP1559 transaction, request should set
89+ * EIP1559Struct.
90+ * @param callback callback when transaction receipt is returned
91+ * @return transaction data hash
92+ * @throws JniException If there is an error during the JNI operation.
93+ */
94+ @ Override
95+ public String asyncSendTransaction (AbiEncodedRequest request , TransactionCallback callback )
96+ throws JniException {
97+ TxPair txPair = createSignedTransaction (request );
98+ client .sendTransactionAsync (txPair .getSignedTx (), false , callback );
99+ return txPair .getTxHash ();
100+ }
101+
102+ /**
103+ * This method is used to create a signed transaction.
104+ *
105+ * @param request An instance of AbiEncodedRequest which contains the necessary information to
106+ * create a transaction: if it is a contract creation, request should setCreate(true), and
107+ * the abi field should be set; if it is EIP1559 transaction, request should set
108+ * EIP1559Struct.
109+ * @return An instance of TxPair which contains the signed transaction and the transaction hash.
110+ * @throws JniException If there is an error during the JNI operation.
111+ */
112+ @ Override
113+ public TxPair createSignedTransaction (AbiEncodedRequest request ) throws JniException {
114+ if (!request .isTransactionEssentialSatisfy ()) {
115+ throw new JniException (
116+ "Transaction essential fields are not satisfied: encodedData, to." );
117+ }
118+ int transactionAttribute ;
119+ if (client .isWASM ()) {
120+ transactionAttribute = TransactionAttribute .LIQUID_SCALE_CODEC ;
121+ if (request .isCreate ()) {
122+ transactionAttribute |= TransactionAttribute .LIQUID_CREATE ;
123+ }
124+ } else {
125+ transactionAttribute = TransactionAttribute .EVM_ABI_CODEC ;
126+ }
127+ byte [] methodId = new byte [4 ];
128+ if (!request .isCreate () && (request .getEncodedData ().length >= 4 )) {
129+ System .arraycopy (request .getEncodedData (), 0 , methodId , 0 , 4 );
130+ }
131+ String nonce =
132+ request .getNonce () == null ? getNonceProvider ().getNonce () : request .getNonce ();
133+ BigInteger blockLimit =
134+ request .getBlockLimit () == null
135+ ? getNonceProvider ().getBlockLimit (client )
136+ : request .getBlockLimit ();
137+ if (getGasProvider ().isEIP1559Enabled () || request .isEIP1559Enabled ()) {
138+ EIP1559Struct eip1559Struct =
139+ request .getEip1559Struct () == null
140+ ? getGasProvider ().getEIP1559Struct (methodId )
141+ : request .getEip1559Struct ();
142+ return TransactionBuilderV1JniObj .createSignedEIP1559TransactionWithFullFields (
143+ client .getCryptoSuite ().getCryptoKeyPair ().getJniKeyPair (),
144+ client .getGroup (),
145+ client .getChainId (),
146+ request .getTo (),
147+ nonce ,
148+ request .getEncodedData (),
149+ request .isCreate () ? request .getAbi () : "" ,
150+ blockLimit .longValue (),
151+ Numeric .toHexString (request .getValue ()),
152+ Numeric .toHexString (eip1559Struct .getMaxFeePerGas ()),
153+ Numeric .toHexString (eip1559Struct .getMaxPriorityFeePerGas ()),
154+ eip1559Struct .getGasLimit ().longValue (),
155+ transactionAttribute ,
156+ client .getExtraData ());
157+ }
158+
159+ BigInteger gasPrice =
160+ request .getGasPrice () == null
161+ ? getGasProvider ().getGasPrice (methodId )
162+ : request .getGasPrice ();
163+ BigInteger gasLimit =
164+ request .getGasLimit () == null
165+ ? getGasProvider ().getGasLimit (methodId )
166+ : request .getGasLimit ();
167+ return TransactionBuilderV1JniObj .createSignedTransactionWithFullFields (
168+ client .getCryptoSuite ().getCryptoKeyPair ().getJniKeyPair (),
169+ client .getGroup (),
170+ client .getChainId (),
171+ request .getTo (),
172+ nonce ,
173+ request .getEncodedData (),
174+ request .isCreate () ? request .getAbi () : "" ,
175+ blockLimit .longValue (),
176+ Numeric .toHexString (request .getValue ()),
177+ Numeric .toHexString (gasPrice ),
178+ gasLimit .longValue (),
179+ transactionAttribute ,
180+ client .getExtraData ());
181+ }
182+
65183 /**
66184 * Send tx with abi field
67185 *
@@ -152,14 +270,6 @@ public TransactionReceipt sendTransaction(
152270 return bcosTransactionReceipt .getTransactionReceipt ();
153271 }
154272
155- @ Override
156- public TransactionReceipt sendTransaction (AbiEncodedRequest request ) throws JniException {
157- String signedTransaction = createSignedTransaction (request ).getSignedTx ();
158- BcosTransactionReceipt bcosTransactionReceipt =
159- client .sendTransaction (signedTransaction , false );
160- return bcosTransactionReceipt .getTransactionReceipt ();
161- }
162-
163273 /**
164274 * This method is used to create a signed transaction.
165275 *
@@ -213,55 +323,6 @@ public String createSignedTransaction(
213323 return txPair .getSignedTx ();
214324 }
215325
216- @ Override
217- public TxPair createSignedTransaction (AbiEncodedRequest request ) throws JniException {
218- if (!request .isTransactionEssentialSatisfy ()) {
219- throw new JniException (
220- "Transaction essential fields are not satisfied: encodedData, to." );
221- }
222- int transactionAttribute ;
223- if (client .isWASM ()) {
224- transactionAttribute = TransactionAttribute .LIQUID_SCALE_CODEC ;
225- if (request .isCreate ()) {
226- transactionAttribute |= TransactionAttribute .LIQUID_CREATE ;
227- }
228- } else {
229- transactionAttribute = TransactionAttribute .EVM_ABI_CODEC ;
230- }
231- byte [] methodId = new byte [4 ];
232- if (!request .isCreate () && (request .getEncodedData ().length >= 4 )) {
233- System .arraycopy (request .getEncodedData (), 0 , methodId , 0 , 4 );
234- }
235- String nonce =
236- request .getNonce () == null ? getNonceProvider ().getNonce () : request .getNonce ();
237- BigInteger blockLimit =
238- request .getBlockLimit () == null
239- ? getNonceProvider ().getBlockLimit (client )
240- : request .getBlockLimit ();
241- BigInteger gasPrice =
242- request .getGasPrice () == null
243- ? getGasProvider ().getGasPrice (methodId )
244- : request .getGasPrice ();
245- BigInteger gasLimit =
246- request .getGasLimit () == null
247- ? getGasProvider ().getGasLimit (methodId )
248- : request .getGasLimit ();
249- return TransactionBuilderV1JniObj .createSignedTransactionWithFullFields (
250- client .getCryptoSuite ().getCryptoKeyPair ().getJniKeyPair (),
251- client .getGroup (),
252- client .getChainId (),
253- request .getTo (),
254- nonce ,
255- request .getEncodedData (),
256- request .isCreate () ? request .getAbi () : "" ,
257- blockLimit .longValue (),
258- Numeric .toHexString (request .getValue ()),
259- Numeric .toHexString (gasPrice ),
260- gasLimit .longValue (),
261- transactionAttribute ,
262- client .getExtraData ());
263- }
264-
265326 /**
266327 * Send tx with abi field asynchronously
267328 *
@@ -391,14 +452,6 @@ public String asyncSendTransaction(
391452 return txPair .getTxHash ();
392453 }
393454
394- @ Override
395- public String asyncSendTransaction (AbiEncodedRequest request , TransactionCallback callback )
396- throws JniException {
397- TxPair txPair = createSignedTransaction (request );
398- client .sendTransactionAsync (txPair .getSignedTx (), false , callback );
399- return txPair .getTxHash ();
400- }
401-
402455 /**
403456 * Send tx with EIP1559
404457 *
0 commit comments