Search in sources :

Example 56 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class RLPTest method encodeDecodeShortListWithTwoByteArraysWithElementsLength55.

@Test
public void encodeDecodeShortListWithTwoByteArraysWithElementsLength55() {
    byte[] value1 = new byte[25];
    byte[] value2 = new byte[28];
    byte[] element1 = RLP.encodeElement(value1);
    byte[] element2 = RLP.encodeElement(value2);
    byte[] encoded = RLP.encodeList(element1, element2);
    Assert.assertNotNull(encoded);
    Assert.assertEquals(1 + 1 + 25 + 1 + 28, encoded.length);
    Assert.assertEquals((byte) (192 + 55), encoded[0]);
    ArrayList<RLPElement> list = RLP.decode2(encoded);
    Assert.assertNotNull(list);
    Assert.assertEquals(1, list.size());
    RLPList list2 = (RLPList) list.get(0);
    Assert.assertNotNull(list2);
    Assert.assertEquals(2, list2.size());
    Assert.assertArrayEquals(value1, list2.get(0).getRLPData());
    Assert.assertArrayEquals(value2, list2.get(1).getRLPData());
}
Also used : RLPElement(org.ethereum.util.RLPElement) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Example 57 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class RLPTest method encodeDecodeShortListWithTwoByteArrays.

@Test
public void encodeDecodeShortListWithTwoByteArrays() {
    byte[] value1 = new byte[] { 0x01, 0x02 };
    byte[] value2 = new byte[] { 0x03, 0x04 };
    byte[] element1 = RLP.encodeElement(value1);
    byte[] element2 = RLP.encodeElement(value2);
    byte[] encoded = RLP.encodeList(element1, element2);
    Assert.assertNotNull(encoded);
    Assert.assertEquals(1 + 3 + 3, encoded.length);
    Assert.assertEquals((byte) (192 + 3 + 3), encoded[0]);
    ArrayList<RLPElement> list = RLP.decode2(encoded);
    Assert.assertNotNull(list);
    Assert.assertEquals(1, list.size());
    RLPList list2 = (RLPList) list.get(0);
    Assert.assertNotNull(list2);
    Assert.assertEquals(2, list2.size());
    Assert.assertArrayEquals(value1, list2.get(0).getRLPData());
    Assert.assertArrayEquals(value2, list2.get(1).getRLPData());
}
Also used : RLPElement(org.ethereum.util.RLPElement) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Example 58 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class RLPTest method encodeDecodeShortListWithTwoByteArraysWithThreeBytesLength.

@Test
public void encodeDecodeShortListWithTwoByteArraysWithThreeBytesLength() {
    byte[] value1 = new byte[128 * 256 - 3];
    byte[] value2 = new byte[128 * 256 - 3];
    byte[] element1 = RLP.encodeElement(value1);
    byte[] element2 = RLP.encodeElement(value2);
    byte[] encoded = RLP.encodeList(element1, element2);
    Assert.assertNotNull(encoded);
    Assert.assertEquals(1 + 3 + 3 + (128 * 256 - 3) + 3 + (128 * 256 - 3), encoded.length);
    Assert.assertEquals((byte) (247 + 3), encoded[0]);
    Assert.assertEquals((byte) (1), encoded[1]);
    Assert.assertEquals((byte) (0), encoded[2]);
    Assert.assertEquals((byte) (0), encoded[3]);
    ArrayList<RLPElement> list = RLP.decode2(encoded);
    Assert.assertNotNull(list);
    Assert.assertEquals(1, list.size());
    RLPList list2 = (RLPList) list.get(0);
    Assert.assertNotNull(list2);
    Assert.assertEquals(2, list2.size());
    Assert.assertArrayEquals(value1, list2.get(0).getRLPData());
    Assert.assertArrayEquals(value2, list2.get(1).getRLPData());
}
Also used : RLPElement(org.ethereum.util.RLPElement) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Example 59 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class RLPTest method encodeDecodeShortListWithShortBytes.

@Test
public void encodeDecodeShortListWithShortBytes() {
    byte[] value1 = new byte[] { 0x01 };
    byte[] value2 = new byte[] { 0x02 };
    byte[] element1 = RLP.encodeElement(value1);
    byte[] element2 = RLP.encodeElement(value2);
    byte[] encoded = RLP.encodeList(element1, element2);
    Assert.assertNotNull(encoded);
    Assert.assertEquals(3, encoded.length);
    Assert.assertEquals((byte) (192 + 2), encoded[0]);
    ArrayList<RLPElement> list = RLP.decode2(encoded);
    Assert.assertNotNull(list);
    Assert.assertEquals(1, list.size());
    RLPList list2 = (RLPList) list.get(0);
    Assert.assertNotNull(list2);
    Assert.assertEquals(2, list2.size());
    Assert.assertArrayEquals(value1, list2.get(0).getRLPData());
    Assert.assertArrayEquals(value2, list2.get(1).getRLPData());
}
Also used : RLPElement(org.ethereum.util.RLPElement) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Example 60 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class ContractDetailsImpl method decode.

@Override
public final void decode(byte[] rlpBytes) {
    ArrayList<RLPElement> rlpData = RLP.decode2(rlpBytes);
    RLPList rlpList = (RLPList) rlpData.get(0);
    RLPItem rlpAddress = (RLPItem) rlpList.get(0);
    RLPItem rlpIsExternalStorage = (RLPItem) rlpList.get(1);
    RLPItem rlpStorage = (RLPItem) rlpList.get(2);
    RLPElement rlpCode = rlpList.get(3);
    RLPList rlpKeys = (RLPList) rlpList.get(4);
    this.address = rlpAddress.getRLPData();
    this.externalStorage = rlpIsExternalStorage.getRLPData() != null;
    this.originalExternalStorage = this.externalStorage;
    if (this.externalStorage) {
        Keccak256 snapshotHash = new Keccak256(rlpStorage.getRLPData());
        this.trie = new TrieImpl(new TrieStoreImpl(levelDbByName(config, getDataSourceName())), true).getSnapshotTo(snapshotHash);
    } else {
        this.trie = TrieImpl.deserialize(rlpStorage.getRLPData());
    }
    this.code = (rlpCode.getRLPData() == null) ? EMPTY_BYTE_ARRAY : rlpCode.getRLPData();
    for (RLPElement key : rlpKeys) {
        addKey(key.getRLPData());
    }
    logger.trace("decoding contract details from bytes, hash {}, address {}, storage size {}, has external storage {}", this.getStorageHashAsString(), this.getAddressAsString(), this.getStorageSize(), this.hasExternalStorage());
}
Also used : RLPItem(org.ethereum.util.RLPItem) RLPElement(org.ethereum.util.RLPElement) Keccak256(co.rsk.crypto.Keccak256) RLPList(org.ethereum.util.RLPList)

Aggregations

RLPList (org.ethereum.util.RLPList)60 RLPElement (org.ethereum.util.RLPElement)19 Test (org.junit.Test)13 Keccak256 (co.rsk.crypto.Keccak256)8 RskAddress (co.rsk.core.RskAddress)7 BigInteger (java.math.BigInteger)5 RLPItem (org.ethereum.util.RLPItem)5 LogInfo (org.ethereum.vm.LogInfo)5 Script (co.rsk.bitcoinj.script.Script)3 ScriptChunk (co.rsk.bitcoinj.script.ScriptChunk)3 Coin (co.rsk.core.Coin)3 RepositoryImpl (co.rsk.db.RepositoryImpl)3 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)3 BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2