Search in sources :

Example 6 with SendTransaction

use of org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction in project web3sdk by FISCO-BCOS.

the class RawTransactionManager method signAndSend.

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;
}
Also used : SendTransaction(org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction) TxHashMismatchException(org.fisco.bcos.web3j.tx.exceptions.TxHashMismatchException)

Aggregations

SendTransaction (org.fisco.bcos.web3j.protocol.core.methods.response.SendTransaction)6 TxHashMismatchException (org.fisco.bcos.web3j.tx.exceptions.TxHashMismatchException)2 IOException (java.io.IOException)1 BcosResponseCallback (org.fisco.bcos.channel.client.BcosResponseCallback)1 BcosRequest (org.fisco.bcos.channel.dto.BcosRequest)1 BcosResponse (org.fisco.bcos.channel.dto.BcosResponse)1 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)1 MessageDecodingException (org.fisco.bcos.web3j.protocol.exceptions.MessageDecodingException)1 ContractCallException (org.fisco.bcos.web3j.tx.exceptions.ContractCallException)1