Search in sources :

Example 6 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class TransactionIntegrationTest method shouldDecodeInterestingRlpFromARealTransactionGeneratedUsingRemixAndASimpleContract.

@Test
public void shouldDecodeInterestingRlpFromARealTransactionGeneratedUsingRemixAndASimpleContract() {
    final String encodedString = "0xf902560c843b9aca00832dc6c08080b90202608060405234801561001057600080fd5b506040516020806101e283398101604052516000556101ae806100346000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632113522a81146100715780632a1afcd9146100af5780633bc5de30146100d657806360fe47b1146100eb578063db613e8114610105575b600080fd5b34801561007d57600080fd5b5061008661011a565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100bb57600080fd5b506100c4610136565b60408051918252519081900360200190f35b3480156100e257600080fd5b506100c461013c565b3480156100f757600080fd5b50610103600435610142565b005b34801561011157600080fd5b50610086610166565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b60005490565b6000556001805473ffffffffffffffffffffffffffffffffffffffff191633179055565b60015473ffffffffffffffffffffffffffffffffffffffff16905600a165627a7a723058208293fac83e9cc01039adf5e41eefd557d1324a3a4c830a4802fa1dd2515227a20029000000000000000000000000000000000000000000000000000000000000007b820fe8a009e7b69af4c318e7fb915f53649bd9f99e5423d41c2cd6a01ab69bb34a951b2fa01b5d39b7c9041ec022d13e6e89eec2cddbe27572eda7956ada5de1032cd5da15";
    final Bytes encoded = Bytes.fromHexString(encodedString);
    final RLPInput input = RLP.input(encoded);
    final Transaction transaction = Transaction.readFrom(input);
    assertThat(transaction).isNotNull();
    assertThat(transaction.isContractCreation()).isTrue();
    assertThat(transaction.getChainId()).contains(BigInteger.valueOf(2018));
    assertThat(transaction.getSender()).isEqualTo(Address.fromHexString("0xfe3b557e8fb62b89f4916b721be55ceb828dbd73"));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) Test(org.junit.Test)

Example 7 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class TransactionIntegrationTest method shouldDecodeAndEncodeTransactionCorrectly.

@Test
public void shouldDecodeAndEncodeTransactionCorrectly() {
    final String encodedString = "0xf9025780843b9aca00832dc6c08080b90202608060405234801561001057600080fd5b506040516020806101e283398101604052516000556101ae806100346000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632113522a81146100715780632a1afcd9146100af5780633bc5de30146100d657806360fe47b1146100eb578063db613e8114610105575b600080fd5b34801561007d57600080fd5b5061008661011a565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100bb57600080fd5b506100c4610136565b60408051918252519081900360200190f35b3480156100e257600080fd5b506100c461013c565b3480156100f757600080fd5b50610103600435610142565b005b34801561011157600080fd5b50610086610166565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b60005490565b6000556001805473ffffffffffffffffffffffffffffffffffffffff191633179055565b60015473ffffffffffffffffffffffffffffffffffffffff16905600a165627a7a723058208293fac83e9cc01039adf5e41eefd557d1324a3a4c830a4802fa1dd2515227a20029000000000000000000000000000000000000000000000000000000000000000c830628cba0482ba9b1136cd9337408938eea6b991fd153900a014867da2f4bb113d4003888a00c5a2f8f279fe2c86831afb5c9578dd1c3be457e3aca3abe439b1a5dd122e676";
    final Bytes encoded = Bytes.fromHexString(encodedString);
    final RLPInput input = RLP.input(encoded);
    final Transaction transaction = Transaction.readFrom(input);
    final BytesValueRLPOutput output = new BytesValueRLPOutput();
    transaction.writeTo(output);
    assertThat(output.encoded().toString()).isEqualTo(encodedString);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Test(org.junit.Test)

Example 8 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class TransactionIntegrationTest method shouldDecodeTransactionWithLargeChainId.

@Test
public void shouldDecodeTransactionWithLargeChainId() {
    final String encodedString = "0xf86a018609184e72a0008276c094d30c3d13b07029deba00de1da369cd69a02c20560180850100000021a07d344f26d7329e8932d2878b99f07b12752bbd13a0b3b822644dbf9600fe718da01d6e6b6c66e1aadf4e33e318a7eef03d3bd3602de52662f0cb5af5b372d44dcd";
    final Bytes encoded = Bytes.fromHexString(encodedString);
    final RLPInput input = RLP.input(encoded);
    final Transaction transaction = Transaction.readFrom(input);
    assertThat(transaction).isNotNull();
    assertThat(transaction.isContractCreation()).isFalse();
    assertThat(transaction.getChainId()).contains(BigInteger.valueOf(2147483647));
    assertThat(transaction.getSender()).isEqualTo(Address.fromHexString("0xdf664d0d2270ef97b48f222e3187bd14c8ca9428"));
    assertThat(transaction.getTo()).contains(Address.fromHexString("0xd30c3d13b07029deba00de1da369cd69a02c2056"));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) Test(org.junit.Test)

Example 9 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class TransactionDecoderTest method decodeGoQuorumPrivateTransactionRlp.

@Test
void decodeGoQuorumPrivateTransactionRlp() {
    boolean goQuorumCompatibilityMode = true;
    RLPInput input = RLP.input(Bytes.fromHexString(GOQUORUM_PRIVATE_TX_RLP));
    final Transaction transaction = TransactionDecoder.decodeForWire(input, goQuorumCompatibilityMode);
    assertThat(transaction).isNotNull();
    assertThat(transaction.getV()).isEqualTo(38);
    assertThat(transaction.getSender()).isEqualByComparingTo(Address.fromHexString("0xed9d02e382b34818e88b88a309c7fe71e65f419d"));
}
Also used : RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Test(org.junit.jupiter.api.Test)

Example 10 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class QbftExtraDataCodec method decodeRaw.

@Override
public BftExtraData decodeRaw(final Bytes input) {
    if (input.isEmpty()) {
        throw new IllegalArgumentException("Invalid Bytes supplied - Bft Extra Data required.");
    }
    final RLPInput rlpInput = new BytesValueRLPInput(input, false);
    // This accounts for the "root node" which contains BFT data items.
    rlpInput.enterList();
    final Bytes vanityData = rlpInput.readBytes();
    final List<Address> validators = rlpInput.readList(Address::readFrom);
    final Optional<Vote> vote;
    if (rlpInput.nextIsList() && rlpInput.nextSize() == 0) {
        vote = Optional.empty();
        rlpInput.skipNext();
    } else {
        vote = Optional.of(decodeVote(rlpInput));
    }
    final int round = rlpInput.readIntScalar();
    final List<SECPSignature> seals = rlpInput.readList(rlp -> SignatureAlgorithmFactory.getInstance().decodeSignature(rlp.readBytes()));
    rlpInput.leaveListLenient();
    return new BftExtraData(vanityData, seals, vote, round, validators);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) Vote(org.hyperledger.besu.consensus.common.bft.Vote) SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Address(org.hyperledger.besu.datatypes.Address) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData)

Aggregations

RLPInput (org.hyperledger.besu.ethereum.rlp.RLPInput)68 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)34 Bytes (org.apache.tuweni.bytes.Bytes)24 Test (org.junit.Test)21 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)15 Hash (org.hyperledger.besu.datatypes.Hash)12 ArrayList (java.util.ArrayList)11 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)11 Block (org.hyperledger.besu.ethereum.core.Block)9 BigInteger (java.math.BigInteger)8 Address (org.hyperledger.besu.datatypes.Address)8 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)7 Transaction (org.hyperledger.besu.ethereum.core.Transaction)7 ArrayDeque (kotlin.collections.ArrayDeque)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 ByteBuffer (java.nio.ByteBuffer)5 Optional (java.util.Optional)5 Wei (org.hyperledger.besu.datatypes.Wei)5 MainnetBlockHeaderFunctions (org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions)5 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)5