org.fisco.bcos.web3j.crypto.RawTransaction Java Examples

The following examples show how to use org.fisco.bcos.web3j.crypto.RawTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RawTransactionManager.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Override
public SendTransaction sendTransaction(
        BigInteger gasPrice,
        BigInteger gasLimit,
        String to,
        String data,
        BigInteger value,
        String extraData)
        throws IOException {

    Random r = new SecureRandom();
    BigInteger randomid = new BigInteger(250, r);
    BigInteger blockLimit = getBlockLimit();
    RawTransaction rawTransaction =
            RawTransaction.createTransaction(
                    randomid, gasPrice, gasLimit, blockLimit, to, value, data);

    return signAndSend(rawTransaction);
}
 
Example #2
Source File: RawTransactionManager.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Override
public SendTransaction sendTransaction(
        BigInteger gasPrice,
        BigInteger gasLimit,
        String to,
        String data,
        BigInteger value,
        String extraData,
        TransactionSucCallback callback)
        throws IOException {
    Random r = new SecureRandom();
    BigInteger randomid = new BigInteger(250, r);
    BigInteger blockLimit = getBlockLimit();
    RawTransaction rawTransaction =
            RawTransaction.createTransaction(
                    randomid, gasPrice, gasLimit, blockLimit, to, value, data);

    return signAndSend(rawTransaction, callback);
}
 
Example #3
Source File: RawTransactionManager.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public SendTransaction signAndSend(RawTransaction rawTransaction) throws IOException {

        byte[] signedMessage;

        if (chainId > ChainId.NONE) {
            signedMessage = TransactionEncoder.signMessage(rawTransaction, chainId, credentials);
        } else {
            signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
        }

        String hexValue = Numeric.toHexString(signedMessage);
        SendTransaction sendTransaction = web3j.sendRawTransaction(hexValue).send();
        if (sendTransaction != null && !sendTransaction.hasError()) {
            String txHashLocal = Hash.sha3(hexValue);
            String txHashRemote = sendTransaction.getTransactionHash();
            if (!txHashVerifier.verify(txHashLocal, txHashRemote)) {
                throw new TxHashMismatchException(txHashLocal, txHashRemote);
            }
        }
        return sendTransaction;
    }
 
Example #4
Source File: RawTransactionManager.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
public SendTransaction signAndSend(
        RawTransaction rawTransaction, TransactionSucCallback callback) throws IOException {

    byte[] signedMessage;

    if (chainId > ChainId.NONE) {
        signedMessage = TransactionEncoder.signMessage(rawTransaction, chainId, credentials);
    } else {
        signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
    }

    String hexValue = Numeric.toHexString(signedMessage);
    Request<?, SendTransaction> request = web3j.sendRawTransaction(hexValue);
    request.setNeedTransCallback(true);
    request.setTransactionSucCallback(callback);
    request.sendOnly();

    return null;
}
 
Example #5
Source File: TransactionEncoderTest.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
private static RawTransaction createContractTransaction() {

        BigInteger randomid = new BigInteger("500");
        BigInteger blockLimit = new BigInteger("501");

        return RawTransaction.createContractTransaction(
                randomid, gasPrice, gasLimit, blockLimit, BigInteger.TEN, "0x0000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
    }