use of org.web3j.rlp.RlpList in project alpha-wallet-android by AlphaWallet.
the class TransactionRepository method encode.
/**
* From Web3j to encode a constructor
* @param rawTransaction
* @param signatureData
* @return
*/
private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) {
List<RlpType> values = TransactionEncoder.asRlpValues(rawTransaction, signatureData);
RlpList rlpList = new RlpList(values);
return RlpEncoder.encode(rlpList);
}
use of org.web3j.rlp.RlpList in project web3j by web3j.
the class PrivateTransactionDecoder method decode.
public static RawPrivateTransaction decode(final String hexTransaction) {
final byte[] transaction = Numeric.hexStringToByteArray(hexTransaction);
final RlpList rlpList = RlpDecoder.decode(transaction);
final RlpList temp = (RlpList) rlpList.getValues().get(0);
final List<RlpType> values = temp.getValues();
final RawTransaction rawTransaction = TransactionDecoder.decode(hexTransaction);
if (values.size() == 9) {
final Base64String privateFrom = extractBase64(values.get(6));
final Restriction restriction = extractRestriction(values.get(8));
if (values.get(7) instanceof RlpList) {
return new RawPrivateTransaction(rawTransaction, privateFrom, extractBase64List(values.get(7)), restriction);
} else {
return new RawPrivateTransaction(rawTransaction, privateFrom, extractBase64(values.get(7)), restriction);
}
} else {
final Base64String privateFrom = extractBase64(values.get(9));
final Restriction restriction = extractRestriction(values.get(11));
if (values.get(10) instanceof RlpList) {
return new SignedRawPrivateTransaction((SignedRawTransaction) rawTransaction, privateFrom, extractBase64List(values.get(10)), restriction);
} else {
return new SignedRawPrivateTransaction((SignedRawTransaction) rawTransaction, privateFrom, extractBase64(values.get(10)), restriction);
}
}
}
use of org.web3j.rlp.RlpList in project alpha-wallet-android by AlphaWallet.
the class KeystoreAccountService method encode.
private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) {
List<RlpType> values = TransactionEncoder.asRlpValues(rawTransaction, signatureData);
RlpList rlpList = new RlpList(values);
byte[] encoded = RlpEncoder.encode(rlpList);
if (!rawTransaction.getType().equals(TransactionType.LEGACY)) {
return ByteBuffer.allocate(encoded.length + 1).put(rawTransaction.getType().getRlpType()).put(encoded).array();
}
return encoded;
}
use of org.web3j.rlp.RlpList in project web3j by web3j.
the class TransactionDecoder method decodeEIP1559Transaction.
private static RawTransaction decodeEIP1559Transaction(final byte[] transaction) {
final byte[] encodedTx = Arrays.copyOfRange(transaction, 1, transaction.length);
final RlpList rlpList = RlpDecoder.decode(encodedTx);
final RlpList values = (RlpList) rlpList.getValues().get(0);
final long chainId = ((RlpString) values.getValues().get(0)).asPositiveBigInteger().longValue();
final BigInteger nonce = ((RlpString) values.getValues().get(1)).asPositiveBigInteger();
final BigInteger maxPriorityFeePerGas = ((RlpString) values.getValues().get(2)).asPositiveBigInteger();
final BigInteger maxFeePerGas = ((RlpString) values.getValues().get(3)).asPositiveBigInteger();
final BigInteger gasLimit = ((RlpString) values.getValues().get(4)).asPositiveBigInteger();
final String to = ((RlpString) values.getValues().get(5)).asString();
final BigInteger value = ((RlpString) values.getValues().get(6)).asPositiveBigInteger();
final String data = ((RlpString) values.getValues().get(7)).asString();
final RawTransaction rawTransaction = RawTransaction.createTransaction(chainId, nonce, gasLimit, to, value, data, maxPriorityFeePerGas, maxFeePerGas);
if (values.getValues().size() == UNSIGNED_EIP1559TX_RLP_LIST_SIZE) {
return rawTransaction;
} else {
final byte[] v = Sign.getVFromRecId(Numeric.toBigInt(((RlpString) values.getValues().get(9)).getBytes()).intValue());
final byte[] r = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(10)).getBytes()), 32);
final byte[] s = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(11)).getBytes()), 32);
final Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s);
return new SignedRawTransaction(rawTransaction.getTransaction(), signatureData);
}
}
use of org.web3j.rlp.RlpList in project web3j by web3j.
the class TransactionDecoder method decodeLegacyTransaction.
private static RawTransaction decodeLegacyTransaction(final byte[] transaction) {
final RlpList rlpList = RlpDecoder.decode(transaction);
final RlpList values = (RlpList) rlpList.getValues().get(0);
final BigInteger nonce = ((RlpString) values.getValues().get(0)).asPositiveBigInteger();
final BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asPositiveBigInteger();
final BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asPositiveBigInteger();
final String to = ((RlpString) values.getValues().get(3)).asString();
final BigInteger value = ((RlpString) values.getValues().get(4)).asPositiveBigInteger();
final String data = ((RlpString) values.getValues().get(5)).asString();
if (values.getValues().size() == 6 || (values.getValues().size() == 8 && ((RlpString) values.getValues().get(7)).getBytes().length == 10) || (values.getValues().size() == 9 && ((RlpString) values.getValues().get(8)).getBytes().length == 10)) {
// representation of "restricted" for private transactions
return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data);
} else {
final byte[] v = ((RlpString) values.getValues().get(6)).getBytes();
final byte[] r = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(7)).getBytes()), 32);
final byte[] s = Numeric.toBytesPadded(Numeric.toBigInt(((RlpString) values.getValues().get(8)).getBytes()), 32);
final Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s);
return new SignedRawTransaction(nonce, gasPrice, gasLimit, to, value, data, signatureData);
}
}
Aggregations