Skip to content

Instantly share code, notes, and snippets.

@conor10
Created January 31, 2017 19:28
Show Gist options
  • Select an option

  • Save conor10/397f79440e808e3cf54132c9276937fc to your computer and use it in GitHub Desktop.

Select an option

Save conor10/397f79440e808e3cf54132c9276937fc to your computer and use it in GitHub Desktop.
package org.web3j.tx;
import java.math.BigInteger;
import java.util.concurrent.ExecutionException;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
public class FastRawTransactionManager extends RawTransactionManager {
private BigInteger nonce = BigInteger.valueOf(-1);
public FastRawTransactionManager(Web3j web3j, Credentials credentials, byte chainId) {
super(web3j, credentials, chainId);
}
public FastRawTransactionManager(Web3j web3j, Credentials credentials) {
super(web3j, credentials);
}
@Override
synchronized BigInteger getNonce(String address) throws InterruptedException, ExecutionException {
if (nonce.signum() == -1) {
nonce = super.getNonce(address);
} else {
nonce = nonce.add(BigInteger.ONE);
}
return nonce;
}
public BigInteger getCurrentNonce() {
return nonce;
}
public synchronized void resetNonce(String address) throws InterruptedException, ExecutionException {
nonce = super.getNonce(address);
}
public synchronized void setNonce(BigInteger value) {
nonce = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment