public static PongMessage create(byte[] token, String host, int port, ECKey privKey) { long expiration = 90 * 60 + System.currentTimeMillis() / 1000; byte[] rlpIp = RLP.encodeElement(host.getBytes()); byte[] tmpPort = longToBytes(port); byte[] rlpPort = RLP.encodeElement(stripLeadingZeroes(tmpPort)); byte[] rlpToList = RLP.encodeList(rlpIp, rlpPort, rlpPort); /* RLP Encode data */ byte[] rlpToken = RLP.encodeElement(token); byte[] tmpExp = longToBytes(expiration); byte[] rlpExp = RLP.encodeElement(stripLeadingZeroes(tmpExp)); byte[] type = new byte[] {2}; byte[] data = RLP.encodeList(rlpToList, rlpToken, rlpExp); PongMessage pong = new PongMessage(); pong.encode(type, data, privKey); pong.token = token; pong.expires = expiration; return pong; }
public byte[] getEncoded() { if (rlpEncoded == null) { byte[] nonce = RLP.encodeBigInteger(this.nonce); byte[] balance = RLP.encodeBigInteger(this.balance); byte[] stateRoot = RLP.encodeElement(this.stateRoot); byte[] codeHash = RLP.encodeElement(this.codeHash); this.rlpEncoded = RLP.encodeList(nonce, balance, stateRoot, codeHash); } return rlpEncoded; }
static PongMessage create(byte[] token, ECKey privKey, long expiration) { /* RLP Encode data */ byte[] rlpToken = RLP.encodeElement(token); byte[] rlpExp = RLP.encodeElement(ByteUtil.longToBytes(expiration)); byte[] type = new byte[] {2}; byte[] data = RLP.encodeList(rlpToken, rlpExp); PongMessage pong = new PongMessage(); pong.encode(type, data, privKey); pong.token = token; pong.expires = expiration; return pong; }
/* [receipt, blockHash, index] */ public byte[] getEncoded() { byte[] receiptRLP = this.receipt.getEncoded(); byte[] blockHashRLP = RLP.encodeElement(blockHash); byte[] indexRLP = RLP.encodeInt(index); byte[] rlpEncoded = RLP.encodeList(receiptRLP, blockHashRLP, indexRLP); return rlpEncoded; }
@Override public byte[] getStorageHash() { SecureTrie storageTrie = new SecureTrie(null); for (DataWord key : storage.keySet()) { DataWord value = storage.get(key); storageTrie.update(key.getData(), RLP.encodeElement(value.getNoLeadZeroesData())); } return storageTrie.getRootHash(); }
@Override public byte[] getEncoded() { byte[][] keys = new byte[storage.size()][]; byte[][] values = new byte[storage.size()][]; int i = 0; for (DataWord key : storage.keySet()) { DataWord value = storage.get(key); keys[i] = RLP.encodeElement(key.getData()); values[i] = RLP.encodeElement(value.getNoLeadZeroesData()); ++i; } byte[] rlpKeysList = RLP.encodeList(keys); byte[] rlpValuesList = RLP.encodeList(values); byte[] rlpCode = RLP.encodeElement(code); return RLP.encodeList(rlpKeysList, rlpValuesList, rlpCode); }
/** For signatures you have to keep also RLP of the transaction without any signature data */ public byte[] getEncodedRaw() { if (!parsed) rlpParse(); if (rlpRaw != null) return rlpRaw; // parse null as 0 for nonce byte[] nonce = null; if (this.nonce == null || this.nonce.length == 1 && this.nonce[0] == 0) { nonce = RLP.encodeElement(null); } else { nonce = RLP.encodeElement(this.nonce); } byte[] gasPrice = RLP.encodeElement(this.gasPrice); byte[] gasLimit = RLP.encodeElement(this.gasLimit); byte[] receiveAddress = RLP.encodeElement(this.receiveAddress); byte[] value = RLP.encodeElement(this.value); byte[] data = RLP.encodeElement(this.data); rlpRaw = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value, data); return rlpRaw; }
public byte[] getEncoded() { if (rlpEncoded != null) return rlpEncoded; // parse null as 0 for nonce byte[] nonce = null; if (this.nonce == null || this.nonce.length == 1 && this.nonce[0] == 0) { nonce = RLP.encodeElement(null); } else { nonce = RLP.encodeElement(this.nonce); } byte[] gasPrice = RLP.encodeElement(this.gasPrice); byte[] gasLimit = RLP.encodeElement(this.gasLimit); byte[] receiveAddress = RLP.encodeElement(this.receiveAddress); byte[] value = RLP.encodeElement(this.value); byte[] data = RLP.encodeElement(this.data); byte[] v, r, s; if (signature != null) { v = RLP.encodeByte(signature.v); r = RLP.encodeElement(BigIntegers.asUnsignedByteArray(signature.r)); s = RLP.encodeElement(BigIntegers.asUnsignedByteArray(signature.s)); } else { v = RLP.encodeElement(EMPTY_BYTE_ARRAY); r = RLP.encodeElement(EMPTY_BYTE_ARRAY); s = RLP.encodeElement(EMPTY_BYTE_ARRAY); } this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value, data, v, r, s); this.hash = this.getHash(); return rlpEncoded; }