Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ext {
junitVersion = '4.13.2'
commonsCollections4Version = "4.4"
guavaVersion = '30.1.1-jre'
bcosSdkJniVersion = "3.0.0"
bcosSdkJniVersion = "3.1.2-SNAPSHOT"
slf4jApiVerison = '2.0.3'
mockitoVersion = '4.8.0'
}
Expand All @@ -34,7 +34,8 @@ ext {
// integrationTest.mustRunAfter test
allprojects {
group = 'org.fisco-bcos.java-sdk'
version = '3.1.1'
version = '3.1.2-SNAPSHOT'

apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'eclipse'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ public void testHelloWorldInSolidity() throws ConfigException, JniException, Con
ConfigOption configOption = Config.load(configFile);
Client client = Client.build(GROUP, configOption);

String extraData = "HelloWorld ExtraData";
client.setExtraData(extraData);

Assert.assertTrue(extraData.equals(client.getExtraData()));

// CryptoSuite cryptoSuite = new CryptoSuite(CryptoType.ECDSA_TYPE);
// CryptoSuite cryptoSuite = new CryptoSuite(CryptoType.SM_TYPE);
CryptoSuite cryptoSuite = client.getCryptoSuite();
Expand Down Expand Up @@ -316,6 +321,16 @@ public void onError(Response errorResponse) {
TransactionReceipt receipt = helloWorld.set("fisco hello");
System.out.println("helloworld set : fisco hello, status=" + receipt.getStatus());
System.out.println(receipt);
Assert.assertTrue(receipt.isStatusOK());

String txHash = receipt.getTransactionHash();
BcosTransaction transaction1 = client.getTransaction(txHash, false);
Assert.assertEquals(extraData, transaction1.getResult().getExtraData());
Assert.assertTrue(extraData.equals(transaction1.getResult().getExtraData()));

BcosTransactionReceipt transactionReceipt = client.getTransactionReceipt(txHash, false);
Assert.assertTrue(extraData.equals(transactionReceipt.getResult().getExtraData()));

// get 2nd block
block1 =
client.getBlockByNumber(
Expand Down Expand Up @@ -373,9 +388,10 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
.sign(transactionDataHash, client.getCryptoSuite().getCryptoKeyPair());

String transactionDataHashSignedData2 = Hex.toHexString(sign.encode());
String extraData = "extraData";
String signedMessage =
TransactionBuilderJniObj.createSignedTransaction(
transactionData, transactionDataHashSignedData2, transactionDataHash, 0);
transactionData, transactionDataHashSignedData2, transactionDataHash, 0, extraData);

TransactionPusherService txPusher = new TransactionPusherService(client);
TransactionReceipt receipt2 = txPusher.push(signedMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.mockito.internal.matchers.Null;

/**
* TransactionProcessorTest @Description: TransactionProcessorTest
Expand Down Expand Up @@ -431,6 +432,16 @@ public void test8ComplexSetBytesFuture() throws Exception {
r -> {
Assert.assertEquals(0, response.getTransactionReceipt().getStatus());
});

TxPair txPair0 =
transactionProcessor.createSignedTransaction(
contractAddress, data, this.cryptoKeyPair, 0, "a");
CompletableFuture<TransactionReceipt> future0 =
transactionProcessor.sendTransactionAsync(txPair0.getSignedTx());
future0.thenAccept(
r -> {
Assert.assertEquals(0, response.getTransactionReceipt().getStatus());
});
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/fisco/bcos/sdk/v3/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ static Client build(String groupId, ConfigOption configOption, long nativePointe
/** @return native pointer */
long getNativePointer();

String getExtraData();

void setExtraData(String extraData);

/**
* Get CryptoSuite
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class ClientImpl implements Client {
private Boolean authCheck = false;
private boolean serialExecute;
private Boolean smCrypto;
private String extraData = "";
// ------------basic group info --------------

// ------------ runtime info -----------------
Expand Down Expand Up @@ -160,6 +161,16 @@ protected ClientImpl(String groupID, ConfigOption configOption, long nativePoint
isWASM());
}

@Override
public String getExtraData() {
return extraData;
}

@Override
public void setExtraData(String extraData) {
this.extraData = extraData;
}

@Override
public long getNativePointer() {
return rpcJniObj.getNativePointer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class JsonTransactionResponse {
private String input;
private String chainID;
private String groupID;
private String extraData;
private String signature;
private long importTime;
private List<MerkleProofUnit> transactionProof;
Expand Down Expand Up @@ -184,6 +185,7 @@ public boolean equals(Object o) {
&& Objects.equals(this.blockLimit, that.blockLimit)
&& Objects.equals(this.chainID, that.chainID)
&& Objects.equals(this.groupID, that.groupID)
&& Objects.equals(this.extraData, that.extraData)
&& Objects.equals(this.signature, that.signature);
}

Expand All @@ -200,6 +202,7 @@ public int hashCode() {
this.blockLimit,
this.chainID,
this.groupID,
this.extraData,
this.signature);
}

Expand Down Expand Up @@ -241,9 +244,19 @@ public String toString() {
+ '\''
+ ", signature="
+ this.signature
+ ", extraData="
+ this.extraData
+ '}';
}

public String getExtraData() {
return extraData;
}

public void setExtraData(String extraData) {
this.extraData = extraData;
}

public long getImportTime() {
return this.importTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class CryptoKeyPair {
protected String signatureAlgorithm;

// for jni transaction sign
protected long jniKeyPair;
protected long jniKeyPair = 0;

public CryptoKeyPair() {}

Expand Down Expand Up @@ -305,6 +305,29 @@ protected String getKeyStoreFilePath(String address, String postFix) {
}

public void destroy() {
KeyPairJniObj.destroyJniKeyPair(this.jniKeyPair);
releaseJni();
}

public void releaseJni() {
if (this.jniKeyPair != 0) {
KeyPairJniObj.destroyJniKeyPair(this.jniKeyPair);
if (logger.isTraceEnabled()) {
logger.trace("finalize, jni key pair: {}", this.jniKeyPair);
}

this.jniKeyPair = 0;
}
}

@Override
protected void finalize() {
try {
super.finalize();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation

Invoking [Object.finalize](1) should be avoided because it has been deprecated.
releaseJni();
} catch (Exception e) {

} catch (Throwable throwable) {
// throwable.printStackTrace();
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/org/fisco/bcos/sdk/v3/model/TransactionReceipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class TransactionReceipt {
private String input;
private String from;
private String to;
private String extraData;
private List<MerkleProofUnit> transactionProof;
private List<MerkleProofUnit> receiptProof;
private String message;
Expand Down Expand Up @@ -247,6 +248,14 @@ public void setTransactionProof(List<MerkleProofUnit> transactionProof) {
this.transactionProof = transactionProof;
}

public String getExtraData() {
return extraData;
}

public void setExtraData(String extraData) {
this.extraData = extraData;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -264,6 +273,7 @@ public boolean equals(Object o) {
&& Objects.equals(this.status, that.status)
&& Objects.equals(this.input, that.input)
&& Objects.equals(this.output, that.output)
&& Objects.equals(this.extraData, that.extraData)
&& Objects.equals(this.transactionProof, that.transactionProof)
&& Objects.equals(this.receiptProof, that.receiptProof);
}
Expand All @@ -283,6 +293,7 @@ public int hashCode() {
this.status,
this.input,
this.output,
this.extraData,
this.transactionProof,
this.receiptProof);
}
Expand Down Expand Up @@ -318,6 +329,9 @@ public String toString() {
+ ", status='"
+ this.status
+ '\''
+ ", extraData='"
+ this.extraData
+ '\''
+ ", input='"
+ this.input
+ '\''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public TransactionReceipt deployAndGetReceipt(
data,
abi,
cryptoKeyPair == null ? this.cryptoKeyPair : cryptoKeyPair,
txAttribute);
txAttribute,
client.getExtraData());
TransactionReceipt transactionReceipt =
this.client.sendTransaction(txPair.getSignedTx(), false).getTransactionReceipt();
if (Objects.nonNull(transactionReceipt)
Expand All @@ -95,7 +96,8 @@ public TransactionReceipt sendTransactionAndGetReceipt(
to,
data,
cryptoKeyPair == null ? this.cryptoKeyPair : cryptoKeyPair,
txAttribute);
txAttribute,
client.getExtraData());
TransactionReceipt transactionReceipt =
this.client.sendTransaction(txPair.getSignedTx(), false).getTransactionReceipt();
if (Objects.nonNull(transactionReceipt)
Expand All @@ -106,8 +108,8 @@ public TransactionReceipt sendTransactionAndGetReceipt(
}

@Override
public TransactionReceipt sendTransactionAndGetReceipt(String to, byte[] data, int txAttribute)
throws JniException {
public TransactionReceipt sendTransactionAndGetReceipt(
String to, byte[] data, int txAttribute) {
return sendTransactionAndGetReceipt(to, data, this.cryptoKeyPair, txAttribute);
}

Expand All @@ -118,7 +120,9 @@ public String sendTransactionAsync(
CryptoKeyPair cryptoKeyPair,
int txAttribute,
TransactionCallback callback) {
TxPair txPair = this.createSignedTransaction(to, data, cryptoKeyPair, txAttribute);
TxPair txPair =
this.createSignedTransaction(
to, data, cryptoKeyPair, txAttribute, client.getExtraData());
this.client.sendTransactionAsync(txPair.getSignedTx(), false, callback);
return txPair.getTxHash();
}
Expand Down Expand Up @@ -158,16 +162,33 @@ public void asyncExecuteCall(CallRequest callRequest, RespCallback<Call> callbac
@Override
public TxPair createDeploySignedTransaction(
String to, byte[] data, String abi, CryptoKeyPair cryptoKeyPair, int txAttribute) {
try {
return createDeploySignedTransaction(
to, data, abi, cryptoKeyPair, txAttribute, client.getExtraData());
}

@Override
public TxPair createSignedTransaction(
String to, byte[] data, CryptoKeyPair cryptoKeyPair, int txAttribute) {
return createSignedTransaction(to, data, cryptoKeyPair, txAttribute, client.getExtraData());
}

@Override
public TxPair createDeploySignedTransaction(
String to,
byte[] data,
String abi,
CryptoKeyPair cryptoKeyPair,
int txAttribute,
String extraData) {
try {
if (log.isDebugEnabled()) {
log.debug(
"createDeploySignedTransaction to: {}, abi: {}, attr: {}",
"createDeploySignedTransaction to: {}, abi: {}, attr: {}, extraData: {}",
to,
abi,
txAttribute);
txAttribute,
extraData);
}

return TransactionBuilderJniObj.createSignedTransaction(
cryptoKeyPair.getJniKeyPair(),
this.groupId,
Expand All @@ -176,7 +197,8 @@ public TxPair createDeploySignedTransaction(
Hex.toHexString(data),
Objects.nonNull(abi) ? abi : "",
client.getBlockLimit().longValue(),
txAttribute);
txAttribute,
Objects.nonNull(extraData) ? extraData : "");
} catch (JniException e) {
log.error("jni e: ", e);
return null;
Expand All @@ -185,11 +207,19 @@ public TxPair createDeploySignedTransaction(

@Override
public TxPair createSignedTransaction(
String to, byte[] data, CryptoKeyPair cryptoKeyPair, int txAttribute) {
String to,
byte[] data,
CryptoKeyPair cryptoKeyPair,
int txAttribute,
String extraData) {
try {

if (log.isDebugEnabled()) {
log.debug("createSignedTransaction to: {}, attr: {}", to, txAttribute);
log.debug(
"createSignedTransaction to: {}, attr: {}, extraData: {}",
to,
txAttribute,
extraData);
}

return TransactionBuilderJniObj.createSignedTransaction(
Expand All @@ -200,7 +230,8 @@ public TxPair createSignedTransaction(
Hex.toHexString(data),
"",
client.getBlockLimit().longValue(),
txAttribute);
txAttribute,
Objects.nonNull(extraData) ? extraData : "");
} catch (JniException e) {
log.error("jni e: ", e);
return null;
Expand Down
Loading