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);
}
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);
}
}
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);
}
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);
}
}
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);
}