use of org.ethereum.util.RLPElement 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());
}
use of org.ethereum.util.RLPElement 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());
}
use of org.ethereum.util.RLPElement 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());
}
Aggregations