Search in sources :

Example 1 with RlpList

use of org.fisco.bcos.web3j.rlp.RlpList in project web3sdk by FISCO-BCOS.

the class ContractUtils method generateContractAddress.

/**
 * Generate a smart contract address. This enables you to identify what address a smart contract
 * will be deployed to on the network.
 *
 * @param address of sender
 * @param nonce of transaction
 * @return the generated smart contract address
 */
public static byte[] generateContractAddress(byte[] address, BigInteger nonce) {
    List<RlpType> values = new ArrayList<>();
    values.add(RlpString.create(address));
    values.add(RlpString.create(nonce));
    RlpList rlpList = new RlpList(values);
    byte[] encoded = RlpEncoder.encode(rlpList);
    byte[] hashed = Hash.sha3(encoded);
    return Arrays.copyOfRange(hashed, 12, hashed.length);
}
Also used : ArrayList(java.util.ArrayList) RlpType(org.fisco.bcos.web3j.rlp.RlpType) RlpList(org.fisco.bcos.web3j.rlp.RlpList)

Example 2 with RlpList

use of org.fisco.bcos.web3j.rlp.RlpList in project web3sdk by FISCO-BCOS.

the class ExtendedTransactionDecoder method decode.

public static ExtendedRawTransaction decode(String hexTransaction) {
    byte[] transaction = Numeric.hexStringToByteArray(hexTransaction);
    RlpList rlpList = RlpDecoder.decode(transaction);
    RlpList values = (RlpList) rlpList.getValues().get(0);
    BigInteger randomid = ((RlpString) values.getValues().get(0)).asPositiveBigInteger();
    BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asPositiveBigInteger();
    BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asPositiveBigInteger();
    BigInteger blockLimit = ((RlpString) values.getValues().get(3)).asPositiveBigInteger();
    String to = ((RlpString) values.getValues().get(4)).asString();
    BigInteger value = ((RlpString) values.getValues().get(5)).asPositiveBigInteger();
    String data = ((RlpString) values.getValues().get(6)).asString();
    // add extra data
    BigInteger chainId = ((RlpString) values.getValues().get(7)).asPositiveBigInteger();
    BigInteger groupId = ((RlpString) values.getValues().get(8)).asPositiveBigInteger();
    String extraData = ((RlpString) values.getValues().get(9)).asString();
    if (values.getValues().size() > 9) {
        byte v = ((RlpString) values.getValues().get(10)).getBytes()[0];
        byte[] r = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(11)).getBytes()), 32);
        byte[] s = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(12)).getBytes()), 32);
        Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s);
        return new SignedExtendedRawTransaction(randomid, gasPrice, gasLimit, blockLimit, to, value, data, chainId, groupId, extraData, signatureData);
    } else {
        return ExtendedRawTransaction.createTransaction(randomid, gasPrice, gasLimit, blockLimit, to, value, data, chainId, groupId, extraData);
    }
}
Also used : BigInteger(java.math.BigInteger) RlpString(org.fisco.bcos.web3j.rlp.RlpString) RlpString(org.fisco.bcos.web3j.rlp.RlpString) RlpList(org.fisco.bcos.web3j.rlp.RlpList)

Example 3 with RlpList

use of org.fisco.bcos.web3j.rlp.RlpList in project web3sdk by FISCO-BCOS.

the class ExtendedTransactionEncoder method encode.

public static byte[] encode(ExtendedRawTransaction rawTransaction, Sign.SignatureData signatureData) {
    List<RlpType> values = asRlpValues(rawTransaction, signatureData);
    RlpList rlpList = new RlpList(values);
    return RlpEncoder.encode(rlpList);
}
Also used : RlpType(org.fisco.bcos.web3j.rlp.RlpType) RlpList(org.fisco.bcos.web3j.rlp.RlpList)

Example 4 with RlpList

use of org.fisco.bcos.web3j.rlp.RlpList in project web3sdk by FISCO-BCOS.

the class TransactionDecoder method decode.

public static RawTransaction decode(String hexTransaction) {
    byte[] transaction = Numeric.hexStringToByteArray(hexTransaction);
    RlpList rlpList = RlpDecoder.decode(transaction);
    RlpList values = (RlpList) rlpList.getValues().get(0);
    BigInteger randomid = ((RlpString) values.getValues().get(0)).asPositiveBigInteger();
    BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asPositiveBigInteger();
    BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asPositiveBigInteger();
    BigInteger blockLimit = ((RlpString) values.getValues().get(3)).asPositiveBigInteger();
    String to = ((RlpString) values.getValues().get(4)).asString();
    BigInteger value = ((RlpString) values.getValues().get(5)).asPositiveBigInteger();
    String data = ((RlpString) values.getValues().get(6)).asString();
    if (values.getValues().size() > 7) {
        byte v = ((RlpString) values.getValues().get(7)).getBytes()[0];
        byte[] r = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(8)).getBytes()), 32);
        byte[] s = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(9)).getBytes()), 32);
        Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s);
        return new SignedRawTransaction(randomid, gasPrice, gasLimit, blockLimit, to, value, data, signatureData);
    } else {
        return RawTransaction.createTransaction(randomid, gasPrice, gasLimit, blockLimit, to, value, data);
    }
}
Also used : BigInteger(java.math.BigInteger) RlpString(org.fisco.bcos.web3j.rlp.RlpString) RlpString(org.fisco.bcos.web3j.rlp.RlpString) RlpList(org.fisco.bcos.web3j.rlp.RlpList)

Example 5 with RlpList

use of org.fisco.bcos.web3j.rlp.RlpList in project web3sdk by FISCO-BCOS.

the class TransactionEncoder method encode.

public static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) {
    List<RlpType> values = asRlpValues(rawTransaction, signatureData);
    RlpList rlpList = new RlpList(values);
    return RlpEncoder.encode(rlpList);
}
Also used : RlpType(org.fisco.bcos.web3j.rlp.RlpType) RlpList(org.fisco.bcos.web3j.rlp.RlpList)

Aggregations

RlpList (org.fisco.bcos.web3j.rlp.RlpList)7 RlpType (org.fisco.bcos.web3j.rlp.RlpType)5 RlpString (org.fisco.bcos.web3j.rlp.RlpString)3 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Log (org.fisco.bcos.web3j.protocol.core.methods.response.Log)1