11
11
import org .fisco .bcos .sdk .v3 .client .protocol .response .BcosTransactionReceipt ;
12
12
import org .fisco .bcos .sdk .v3 .client .protocol .response .Call ;
13
13
import org .fisco .bcos .sdk .v3 .crypto .signature .SignatureResult ;
14
+ import org .fisco .bcos .sdk .v3 .model .Response ;
14
15
import org .fisco .bcos .sdk .v3 .model .TransactionReceipt ;
15
16
import org .fisco .bcos .sdk .v3 .model .callback .RespCallback ;
16
17
import org .fisco .bcos .sdk .v3 .model .callback .TransactionCallback ;
@@ -36,7 +37,7 @@ public class DefaultTransactionManager extends TransactionManager {
36
37
private NonceProvider nonceProvider = new DefaultNonceProvider ();
37
38
private static final Logger logger = LoggerFactory .getLogger (DefaultTransactionManager .class );
38
39
39
- protected DefaultTransactionManager (Client client ) {
40
+ public DefaultTransactionManager (Client client ) {
40
41
super (client );
41
42
}
42
43
@@ -142,32 +143,11 @@ public TransactionReceipt sendTransaction(
142
143
String abi ,
143
144
boolean constructor )
144
145
throws JniException {
145
- int transactionAttribute ;
146
- if (client .isWASM ()) {
147
- transactionAttribute = TransactionAttribute .LIQUID_SCALE_CODEC ;
148
- if (constructor ) {
149
- transactionAttribute |= TransactionAttribute .LIQUID_CREATE ;
150
- }
151
- } else {
152
- transactionAttribute = TransactionAttribute .EVM_ABI_CODEC ;
153
- }
154
- TxPair txPair =
155
- TransactionBuilderV2JniObj .createSignedTransactionWithFullFields (
156
- client .getCryptoSuite ().getCryptoKeyPair ().getJniKeyPair (),
157
- client .getGroup (),
158
- client .getChainId (),
159
- to == null ? "" : to ,
160
- data ,
161
- (abi == null || !constructor ) ? "" : abi ,
162
- blockLimit .longValue (),
163
- Numeric .toHexString (value ),
164
- Numeric .toHexString (gasPrice ),
165
- gasLimit == null ? 0 : gasLimit .longValue (),
166
- transactionAttribute ,
167
- client .getExtraData ());
146
+ String signTx =
147
+ createSignedTransaction (
148
+ to , data , value , gasPrice , gasLimit , blockLimit , abi , constructor );
168
149
169
- BcosTransactionReceipt bcosTransactionReceipt =
170
- client .sendTransaction (txPair .getSignedTx (), false );
150
+ BcosTransactionReceipt bcosTransactionReceipt = client .sendTransaction (signTx , false );
171
151
return bcosTransactionReceipt .getTransactionReceipt ();
172
152
}
173
153
@@ -179,15 +159,30 @@ public TransactionReceipt sendTransaction(
179
159
* @param value The value to be transferred with the transaction.
180
160
* @param gasPrice The price of gas for the transaction.
181
161
* @param gasLimit The maximum amount of gas that can be used for the transaction.
162
+ * @param blockLimit The maximum block number that can be used for the transaction, if
163
+ * blockLimit is zero, then get client blockLimit
164
+ * @param abi ABI JSON string, generated by compile contract, should fill in when you deploy
165
+ * contract
166
+ * @param constructor If you deploy contract, should set to be true.
182
167
* @return A Hex string representation of the signed transaction.
183
168
*/
184
169
@ Override
185
170
public String createSignedTransaction (
186
- String to , byte [] data , BigInteger value , BigInteger gasPrice , BigInteger gasLimit )
171
+ String to ,
172
+ byte [] data ,
173
+ BigInteger value ,
174
+ BigInteger gasPrice ,
175
+ BigInteger gasLimit ,
176
+ BigInteger blockLimit ,
177
+ String abi ,
178
+ boolean constructor )
187
179
throws JniException {
188
180
int transactionAttribute ;
189
181
if (client .isWASM ()) {
190
182
transactionAttribute = TransactionAttribute .LIQUID_SCALE_CODEC ;
183
+ if (constructor ) {
184
+ transactionAttribute |= TransactionAttribute .LIQUID_CREATE ;
185
+ }
191
186
} else {
192
187
transactionAttribute = TransactionAttribute .EVM_ABI_CODEC ;
193
188
}
@@ -197,9 +192,10 @@ public String createSignedTransaction(
197
192
client .getGroup (),
198
193
client .getChainId (),
199
194
to == null ? "" : to ,
195
+ getNonceProvider ().getNonce (),
200
196
data ,
201
- "" ,
202
- client . getBlockLimit () .longValue (),
197
+ ( abi == null || ! constructor ) ? "" : abi ,
198
+ blockLimit .longValue (),
203
199
Numeric .toHexString (value ),
204
200
Numeric .toHexString (gasPrice ),
205
201
gasLimit == null ? 0 : gasLimit .longValue (),
@@ -324,6 +320,7 @@ public String asyncSendTransaction(
324
320
client .getGroup (),
325
321
client .getChainId (),
326
322
to == null ? "" : to ,
323
+ getNonceProvider ().getNonce (),
327
324
data ,
328
325
(abi == null || !constructor ) ? "" : abi ,
329
326
blockLimit .longValue (),
@@ -398,6 +395,7 @@ public TransactionReceipt sendTransactionEIP1559(
398
395
client .getGroup (),
399
396
client .getChainId (),
400
397
to == null ? "" : to ,
398
+ getNonceProvider ().getNonce (),
401
399
data ,
402
400
(abi == null || !constructor ) ? "" : abi ,
403
401
blockLimit .longValue (),
@@ -476,6 +474,7 @@ public String asyncSendTransactionEIP1559(
476
474
client .getGroup (),
477
475
client .getChainId (),
478
476
to == null ? "" : to ,
477
+ getNonceProvider ().getNonce (),
479
478
data ,
480
479
(abi == null || !constructor ) ? "" : abi ,
481
480
blockLimit .longValue (),
@@ -542,7 +541,7 @@ public void asyncSendCall(String to, byte[] data, RespCallback<Call> callback) {
542
541
new Transaction ("" , to , data ), Hex .toHexString (signature .encode ()), callback );
543
542
} catch (Exception e ) {
544
543
logger .error ("Send call failed, error message: {}" , e .getMessage (), e );
545
- throw new RuntimeException ( e );
544
+ callback . onError ( new Response (- 1 , e . getMessage ()) );
546
545
}
547
546
}
548
547
0 commit comments