Skip to content

Commit

Permalink
fix sign recovery failure
Browse files Browse the repository at this point in the history
fix sign recovery failure issue, update web3j-2.1.0-extension and its dependencies
  • Loading branch information
kelvin committed Nov 8, 2017
1 parent 0fbb58d commit ed29837
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 261 deletions.
1 change: 1 addition & 0 deletions tool/java/DfsSDK/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<classpathentry kind="lib" path="lib/rxjava-1.2.4.jar"/>
<classpathentry kind="lib" path="lib/scrypt-1.4.0.jar"/>
<classpathentry kind="lib" path="lib/web3j-2.1.0_main.jar"/>
<classpathentry kind="lib" path="lib/web3j-2.1.0-extension.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions tool/java/DfsSDK/.settings/com.zeroc.IceBuilderPlugin.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
builderVersion=4.1
eclipse.preferences.version=1
Binary file added tool/java/DfsSDK/lib/web3j-2.1.0-extension.jar
Binary file not shown.
9 changes: 4 additions & 5 deletions tool/java/DfsSDK/src/com/dfs/fileserver/DfsEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.bcos.web3j.tx.BcosRawTxManager;
import org.junit.internal.runners.ErrorReportingRunner;
import org.juzix.web3j.NonceTransactionManager;
import org.juzix.web3j.protocol.CostomerWeb3j;
Expand All @@ -30,14 +31,12 @@
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.WalletUtils;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.core.methods.response.EthAccounts;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.http.HttpService;
import org.web3j.protocol.parity.Parity;
import org.web3j.tx.ClientTransactionManager;
import org.web3j.tx.RawTransactionManager;
import org.web3j.tx.TransactionManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
Expand All @@ -53,7 +52,7 @@
import com.dfs.web3j.FileInfoManager;
import com.dfs.web3j.FileServerManager;
import com.dfs.web3j.FileInfoManager.NotifyEventResponse;
import com.dfs.web3j.tx.DfsRawTransactionManager;



public class DfsEngine {
Expand Down Expand Up @@ -1168,7 +1167,7 @@ private FileInfoManager createFileInfoManager(FileServer fileServer) {
return FileInfoManager.load(addr, parity, new RawTransactionManager(parity, credentials, 100, 100) , gasPrice, gasLimited);
}
else if (use_transaction_type == UserTransactionType.WeiWanRawSigned) {
return FileInfoManager.load(addr, parity, new DfsRawTransactionManager(parity, credentials, 100, 100) , gasPrice, gasLimited);
return FileInfoManager.load(addr, parity, new BcosRawTxManager(parity, credentials, 100, 100) , gasPrice, gasLimited);
}
else//3 or other is default for nonceExtension
{
Expand Down Expand Up @@ -1200,7 +1199,7 @@ private FileServerManager createFileServerManager(FileServer fileServer) {
return FileServerManager.load(addr, parity, new RawTransactionManager(parity, credentials, 100, 100) , gasPrice, gasLimited);
}
else if (use_transaction_type == UserTransactionType.WeiWanRawSigned) {
return FileServerManager.load(addr, parity, new DfsRawTransactionManager(parity, credentials, 100, 100) , gasPrice, gasLimited);
return FileServerManager.load(addr, parity, new BcosRawTxManager(parity, credentials, 100, 100) , gasPrice, gasLimited);
}
else//3 or other is default for nonceExtension
{
Expand Down
120 changes: 0 additions & 120 deletions tool/java/DfsSDK/src/com/dfs/web3j/tx/DfsRawTransactionManager.java

This file was deleted.

131 changes: 0 additions & 131 deletions tool/java/DfsSDK/src/com/dfs/web3j/tx/DfsTransactionEncoder.java

This file was deleted.

1 change: 1 addition & 0 deletions tool/java/DfsSample/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
<classpathentry kind="lib" path="lib/web3j-2.1.0_main.jar" sourcepath="/web3j-v2.0.1_src"/>
<classpathentry combineaccessrules="false" kind="src" path="/DfsSDK"/>
<classpathentry kind="lib" path="lib/DfsSDK.jar"/>
<classpathentry kind="lib" path="lib/web3j-2.1.0-extension.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
builderVersion=4.1
eclipse.preferences.version=1
1 change: 0 additions & 1 deletion tool/java/DfsSample/bin/.gitignore

This file was deleted.

Binary file modified tool/java/DfsSample/lib/DfsSDK.jar
Binary file not shown.
Binary file added tool/java/DfsSample/lib/web3j-2.1.0-extension.jar
Binary file not shown.
Binary file modified tool/java/output/DfsSDK.jar
Binary file not shown.
Binary file modified tool/java/output/web3j-2.1.0-extension.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
builderVersion=4.1
eclipse.preferences.version=1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.io.IOException;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
Expand All @@ -28,13 +30,18 @@ public class BcosRawTxManager extends TransactionManager {

private final byte chainId;
private BcosTxEncoder transactionEncoder;
private Random random;

public BcosRawTxManager(Web3j web3j, Credentials credentials, byte chainId) {
super(web3j);
this.web3j = web3j;
this.credentials = credentials;

this.chainId = chainId;

random = new Random();
random.setSeed(Calendar.getInstance().getTimeInMillis());

this.transactionEncoder = new BcosTxEncoder();
}

Expand All @@ -45,6 +52,9 @@ public BcosRawTxManager(
this.credentials = credentials;

this.chainId = chainId;

random = new Random();
random.setSeed(Calendar.getInstance().getTimeInMillis());
this.transactionEncoder = new BcosTxEncoder();
}

Expand Down Expand Up @@ -101,6 +111,11 @@ public EthSendTransaction signAndSend(RawTransaction rawTransaction)

blockLimited = blockLimited.add(new BigInteger("100", 10));
transactionEncoder.setBlockLimited(blockLimited);

//generate ramdomid
BigInteger ramdomid = new BigInteger(256, random);
transactionEncoder.setRandomId(ramdomid);

if (chainId > ChainId.NONE) {
signedMessage = transactionEncoder.signMessage(rawTransaction, chainId, credentials);
} else {
Expand Down
Loading

0 comments on commit ed29837

Please sign in to comment.