org.bcos.web3j.tx.FastRawTransactionManager Maven / Gradle / Ivy
package org.bcos.web3j.tx;
import java.io.IOException;
import java.math.BigInteger;
import java.util.concurrent.ExecutionException;
import org.bcos.web3j.crypto.Credentials;
import org.bcos.web3j.protocol.Web3j;
/**
* Simple RawTransactionManager derivative that manages nonces to facilitate multiple transactions
* per block.
*/
public class FastRawTransactionManager extends RawTransactionManager {
private volatile 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() throws IOException {
if (nonce.signum() == -1) {
nonce = super.getNonce();
} else {
nonce = nonce.add(BigInteger.ONE);
}
return nonce;
}
public BigInteger getCurrentNonce() {
return nonce;
}
public synchronized void resetNonce() throws IOException {
nonce = super.getNonce();
}
public synchronized void setNonce(BigInteger value) {
nonce = value;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy