Skip to content

Commit 50ed1ac

Browse files
authored
<fix>(transaction,client): fix transaction manager async method not call back when exception occurs, DefaultTransactionManager adapt jni new interface with nonce, fix negotiatedProtocol init moment. (#865)
1 parent 8ad4dd3 commit 50ed1ac

File tree

6 files changed

+142
-239
lines changed

6 files changed

+142
-239
lines changed

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ext {
2424
webankJavaCryptoVersion = "1.0.3"
2525
junitVersion = '4.13.2'
2626
commonsCollections4Version = "4.4"
27-
bcosSdkJniVersion = "3.6.0-SNAPSHOT"
27+
bcosSdkJniVersion = "3.6.0-DEV-SNAPSHOT"
2828
slf4jApiVerison = '1.7.36'
2929
mockitoVersion = '4.8.0'
3030
gsonVersion = '2.10.1'
@@ -159,13 +159,13 @@ configurations {
159159
}
160160

161161
task integrationTest(type: Test) {
162-
dependsOn test
162+
// dependsOn test
163163
testClassesDirs = sourceSets.integrationTest.output.classesDirs
164164
classpath = sourceSets.integrationTest.runtimeClasspath
165165
}
166166

167167
task integrationWasmTest(type: Test) {
168-
dependsOn test
168+
// dependsOn test
169169
testClassesDirs = sourceSets.integrationWasmTest.output.classesDirs
170170
classpath = sourceSets.integrationWasmTest.runtimeClasspath
171171
}
@@ -208,9 +208,9 @@ jacocoTestReport {
208208
}
209209
}
210210

211-
tasks.withType(Test) {
212-
finalizedBy jacocoTestReport
213-
}
211+
//tasks.withType(Test) {
212+
// finalizedBy jacocoTestReport
213+
//}
214214

215215
publishing {
216216
publications {

src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ protected ClientImpl(String groupID, ConfigOption configOption, long nativePoint
158158
this.groupID = groupID;
159159
this.configOption = configOption;
160160
this.rpcJniObj = RpcJniObj.build(nativePointer);
161-
this.negotiatedProtocol = BcosSDKJniObj.negotiatedProtocolInfo(nativePointer);
162-
163161
// start rpc
164162
start();
165163

@@ -181,7 +179,8 @@ protected ClientImpl(String groupID, ConfigOption configOption, long nativePoint
181179
this.cryptoSuite = new CryptoSuite(CryptoType.ECDSA_TYPE, configOption);
182180
}
183181
}
184-
182+
// should be assigned after session connect
183+
this.negotiatedProtocol = BcosSDKJniObj.negotiatedProtocolInfo(nativePointer);
185184
logger.info(
186185
"ClientImpl constructor, groupID: {}, nativePointer: {}, smCrypto: {}, wasm: {}",
187186
groupID,

src/main/java/org/fisco/bcos/sdk/v3/contract/Contract.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,10 @@ protected String createSignedTransaction(Function function) {
568568
this.functionEncoder.encode(function),
569569
BigInteger.ZERO,
570570
BigInteger.ZERO,
571-
BigInteger.ZERO);
571+
BigInteger.ZERO,
572+
client.getBlockLimit(),
573+
"",
574+
false);
572575
} catch (JniException e) {
573576
logger.error("createSignedTransaction failed, error info: {}", e.getMessage(), e);
574577
return null;

src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv2/DefaultTransactionManager.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.fisco.bcos.sdk.v3.client.protocol.response.BcosTransactionReceipt;
1212
import org.fisco.bcos.sdk.v3.client.protocol.response.Call;
1313
import org.fisco.bcos.sdk.v3.crypto.signature.SignatureResult;
14+
import org.fisco.bcos.sdk.v3.model.Response;
1415
import org.fisco.bcos.sdk.v3.model.TransactionReceipt;
1516
import org.fisco.bcos.sdk.v3.model.callback.RespCallback;
1617
import org.fisco.bcos.sdk.v3.model.callback.TransactionCallback;
@@ -36,7 +37,7 @@ public class DefaultTransactionManager extends TransactionManager {
3637
private NonceProvider nonceProvider = new DefaultNonceProvider();
3738
private static final Logger logger = LoggerFactory.getLogger(DefaultTransactionManager.class);
3839

39-
protected DefaultTransactionManager(Client client) {
40+
public DefaultTransactionManager(Client client) {
4041
super(client);
4142
}
4243

@@ -142,32 +143,11 @@ public TransactionReceipt sendTransaction(
142143
String abi,
143144
boolean constructor)
144145
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);
168149

169-
BcosTransactionReceipt bcosTransactionReceipt =
170-
client.sendTransaction(txPair.getSignedTx(), false);
150+
BcosTransactionReceipt bcosTransactionReceipt = client.sendTransaction(signTx, false);
171151
return bcosTransactionReceipt.getTransactionReceipt();
172152
}
173153

@@ -179,15 +159,30 @@ public TransactionReceipt sendTransaction(
179159
* @param value The value to be transferred with the transaction.
180160
* @param gasPrice The price of gas for the transaction.
181161
* @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.
182167
* @return A Hex string representation of the signed transaction.
183168
*/
184169
@Override
185170
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)
187179
throws JniException {
188180
int transactionAttribute;
189181
if (client.isWASM()) {
190182
transactionAttribute = TransactionAttribute.LIQUID_SCALE_CODEC;
183+
if (constructor) {
184+
transactionAttribute |= TransactionAttribute.LIQUID_CREATE;
185+
}
191186
} else {
192187
transactionAttribute = TransactionAttribute.EVM_ABI_CODEC;
193188
}
@@ -197,9 +192,10 @@ public String createSignedTransaction(
197192
client.getGroup(),
198193
client.getChainId(),
199194
to == null ? "" : to,
195+
getNonceProvider().getNonce(),
200196
data,
201-
"",
202-
client.getBlockLimit().longValue(),
197+
(abi == null || !constructor) ? "" : abi,
198+
blockLimit.longValue(),
203199
Numeric.toHexString(value),
204200
Numeric.toHexString(gasPrice),
205201
gasLimit == null ? 0 : gasLimit.longValue(),
@@ -324,6 +320,7 @@ public String asyncSendTransaction(
324320
client.getGroup(),
325321
client.getChainId(),
326322
to == null ? "" : to,
323+
getNonceProvider().getNonce(),
327324
data,
328325
(abi == null || !constructor) ? "" : abi,
329326
blockLimit.longValue(),
@@ -398,6 +395,7 @@ public TransactionReceipt sendTransactionEIP1559(
398395
client.getGroup(),
399396
client.getChainId(),
400397
to == null ? "" : to,
398+
getNonceProvider().getNonce(),
401399
data,
402400
(abi == null || !constructor) ? "" : abi,
403401
blockLimit.longValue(),
@@ -476,6 +474,7 @@ public String asyncSendTransactionEIP1559(
476474
client.getGroup(),
477475
client.getChainId(),
478476
to == null ? "" : to,
477+
getNonceProvider().getNonce(),
479478
data,
480479
(abi == null || !constructor) ? "" : abi,
481480
blockLimit.longValue(),
@@ -542,7 +541,7 @@ public void asyncSendCall(String to, byte[] data, RespCallback<Call> callback) {
542541
new Transaction("", to, data), Hex.toHexString(signature.encode()), callback);
543542
} catch (Exception e) {
544543
logger.error("Send call failed, error message: {}", e.getMessage(), e);
545-
throw new RuntimeException(e);
544+
callback.onError(new Response(-1, e.getMessage()));
546545
}
547546
}
548547

0 commit comments

Comments
 (0)