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

The following examples show how to use org.fisco.bcos.web3j.crypto.TransactionEncoder. 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
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 #2
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 #3
Source File: TransactionEncoderTest.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
@Test
public void testSignMessage() {
    byte[] signedMessage =
            TransactionEncoder.signMessage(createContractTransaction(), SampleKeys.CREDENTIALS);
    String hexMessage = Numeric.toHexString(signedMessage);
    assertThat(
            hexMessage,
            is(
                    "0xf85a8201f4010a8201f5840add5355887fffffffffffffff801ba01cf44d4680e1ecaf11a9a997b08055ae84c5d417b1fc7c2bdbaffc3fd4a7659aa07a424ef2ad019c599a24309c97f4cd10d0e4293a51d8c1abb095052bf54a7ba7"));
}
 
Example #4
Source File: TransactionEncoderTest.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
@Test
public void testGMSignMessage() {


        Credentials credentials =
                GenCredential.create(
                        "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f");

        Instant startTime = Instant.now();

        byte[] signedMessage = TransactionEncoder.signMessage(createContractTransaction(), credentials);
        System.out.println("       sign  useTime: " + Duration.between(startTime, Instant.now()).toMillis());
     //   String hexMessage = Numeric.toHexString(signedMessage);


        // gm createTransaction!
        EncryptType encryptType = new EncryptType(1);
         assertSame(encryptType.getEncryptType(),1);
        Credentials gmcredentials =
                GenCredential.create(
                        "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f");

        Instant startTime1 = Instant.now();
         TransactionEncoder.signMessage(createContractTransaction(), gmcredentials);
        System.out.println(" guomi sign  useTime: " + Duration.between(startTime1, Instant.now()).toMillis());
  //      String hexMessage1 = Numeric.toHexString(signedMessage1);
}