Java Code Examples for org.ethereum.util.RLP#encodeElement()
The following examples show how to use
org.ethereum.util.RLP#encodeElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockHeader.java From ethereumj with MIT License | 6 votes |
public byte[] getEncoded(boolean withNonce) { byte[] parentHash = RLP.encodeElement(this.parentHash); byte[] unclesHash = RLP.encodeElement(this.unclesHash); byte[] coinbase = RLP.encodeElement(this.coinbase); byte[] stateRoot = RLP.encodeElement(this.stateRoot); byte[] txTrieRoot = RLP.encodeElement(this.txTrieRoot); byte[] difficulty = RLP.encodeElement(this.difficulty); byte[] number = RLP.encodeBigInteger(BigInteger.valueOf(this.number)); byte[] minGasPrice = RLP.encodeBigInteger(BigInteger.valueOf(this.minGasPrice)); byte[] gasLimit = RLP.encodeBigInteger(BigInteger.valueOf(this.gasLimit)); byte[] gasUsed = RLP.encodeBigInteger(BigInteger.valueOf(this.gasUsed)); byte[] timestamp = RLP.encodeBigInteger(BigInteger.valueOf(this.timestamp)); byte[] extraData = RLP.encodeElement(this.extraData); if(withNonce) { byte[] nonce = RLP.encodeElement(this.nonce); return RLP.encodeList(parentHash, unclesHash, coinbase, stateRoot, txTrieRoot, difficulty, number, minGasPrice, gasLimit, gasUsed, timestamp, extraData, nonce); } else { return RLP.encodeList(parentHash, unclesHash, coinbase, stateRoot, txTrieRoot, difficulty, number, minGasPrice, gasLimit, gasUsed, timestamp, extraData); } }
Example 2
Source File: Transaction.java From ethereumj with MIT License | 6 votes |
/** * 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); this.rlpRaw = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value, data); return rlpRaw; }
Example 3
Source File: ContractDetails.java From ethereumj with MIT License | 6 votes |
public byte[] getEncoded() { if (rlpEncoded == null) { int size = storageKeys == null ? 0 : storageKeys.size(); byte[][] keys = new byte[size][]; byte[][] values = new byte[size][]; for (int i = 0; i < size; ++i) { DataWord key = storageKeys.get(i); keys[i] = RLP.encodeElement(key.getData()); } for (int i = 0; i < size; ++i) { DataWord value = storageValues.get(i); values[i] = RLP.encodeElement(value.getNoLeadZeroesData()); } byte[] rlpKeysList = RLP.encodeList(keys); byte[] rlpValuesList = RLP.encodeList(values); byte[] rlpCode = RLP.encodeElement(code); this.rlpEncoded = RLP.encodeList(rlpKeysList, rlpValuesList, rlpCode); } return rlpEncoded; }
Example 4
Source File: Transaction.java From wkcwallet-java with Apache License 2.0 | 6 votes |
public byte[] getEncodedRaw() { if(!this.parsed) { this.rlpParse(); } if(this.rlpRaw != null) { return this.rlpRaw; } else { byte[] nonce = null; if(this.nonce != null && (this.nonce.length != 1 || this.nonce[0] != 0)) { nonce = RLP.encodeElement(this.nonce); } else { nonce = RLP.encodeElement((byte[])null); } 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); this.rlpRaw = RLP.encodeList(new byte[][]{nonce, gasPrice, gasLimit, receiveAddress, value, data}); return this.rlpRaw; } }
Example 5
Source File: AccountState.java From ethereumj with MIT License | 5 votes |
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; }
Example 6
Source File: Transaction.java From ethereumj with MIT License | 5 votes |
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(new byte[0]); r = RLP.encodeElement(new byte[0]); s = RLP.encodeElement(new byte[0]); } this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value, data, v, r, s); return rlpEncoded; }
Example 7
Source File: StatusMessage.java From ethereumj with MIT License | 5 votes |
private void encode() { byte[] command = RLP.encodeByte(STATUS.asByte()); byte[] protocolVersion = RLP.encodeByte(this.protocolVersion); byte[] networkId = RLP.encodeByte(this.networkId); byte[] totalDifficulty = RLP.encodeElement(this.totalDifficulty); byte[] bestHash = RLP.encodeElement(this.bestHash); byte[] genesisHash = RLP.encodeElement(this.genesisHash); this.encoded = RLP.encodeList(command, protocolVersion, networkId, totalDifficulty, bestHash, genesisHash); }
Example 8
Source File: HashUtil.java From ethereumj with MIT License | 5 votes |
/** * The way to calculate new address inside ethereum * * @param addr - creating addres * @param nonce - nonce of creating address * @return new address */ public static byte[] calcNewAddr(byte[] addr, byte[] nonce) { byte[] encSender = RLP.encodeElement(addr); byte[] encNonce = RLP.encodeBigInteger(new BigInteger(1, nonce)); byte[] newAddress = sha3omit12(RLP.encodeList(encSender, encNonce)); return newAddress; }
Example 9
Source File: AccountState.java From nuls with MIT License | 5 votes |
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); byte[] owner = RLP.encodeElement(this.owner); this.rlpEncoded = RLP.encodeList(nonce, balance, stateRoot, codeHash, owner); } return rlpEncoded; }
Example 10
Source File: JournalSource.java From nuls-v2 with MIT License | 5 votes |
public byte[] serialize() { byte[][] insertedBytes = new byte[insertedKeys.size()][]; for (int i = 0; i < insertedBytes.length; i++) { insertedBytes[i] = RLP.encodeElement(insertedKeys.get(i)); } byte[][] deletedBytes = new byte[deletedKeys.size()][]; for (int i = 0; i < deletedBytes.length; i++) { deletedBytes[i] = RLP.encodeElement(deletedKeys.get(i)); } return RLP.encodeList(RLP.encodeElement(updateHash), RLP.encodeList(insertedBytes), RLP.encodeList(deletedBytes)); }
Example 11
Source File: JournalSource.java From nuls with MIT License | 5 votes |
public byte[] serialize() { byte[][] insertedBytes = new byte[insertedKeys.size()][]; for (int i = 0; i < insertedBytes.length; i++) { insertedBytes[i] = RLP.encodeElement(insertedKeys.get(i)); } byte[][] deletedBytes = new byte[deletedKeys.size()][]; for (int i = 0; i < deletedBytes.length; i++) { deletedBytes[i] = RLP.encodeElement(deletedKeys.get(i)); } return RLP.encodeList(RLP.encodeElement(updateHash), RLP.encodeList(insertedBytes), RLP.encodeList(deletedBytes)); }
Example 12
Source File: Transaction.java From wkcwallet-java with Apache License 2.0 | 5 votes |
public byte[] getEncoded() { if(this.rlpEncoded != null) { return this.rlpEncoded; } else { byte[] nonce = null; if(this.nonce != null && (this.nonce.length != 1 || this.nonce[0] != 0)) { nonce = RLP.encodeElement(this.nonce); } else { nonce = RLP.encodeElement((byte[])null); } 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; byte[] r; byte[] s; if(this.signature != null) { v = RLP.encodeByte(this.signature.v); r = RLP.encodeElement(BigIntegers.asUnsignedByteArray(this.signature.r)); s = RLP.encodeElement(BigIntegers.asUnsignedByteArray(this.signature.s)); } else { v = RLP.encodeElement(ByteUtil.EMPTY_BYTE_ARRAY); r = RLP.encodeElement(ByteUtil.EMPTY_BYTE_ARRAY); s = RLP.encodeElement(ByteUtil.EMPTY_BYTE_ARRAY); } this.rlpEncoded = RLP.encodeList(new byte[][]{nonce, gasPrice, gasLimit, receiveAddress, value, data, v, r, s}); this.hash = this.getHash(); return this.rlpEncoded; } }
Example 13
Source File: HashUtil.java From wkcwallet-java with Apache License 2.0 | 5 votes |
/** * The way to calculate new address inside ethereum * * @param addr - creating addres * @param nonce - nonce of creating address * @return new address */ public static byte[] calcNewAddr(byte[] addr, byte[] nonce) { byte[] encSender = RLP.encodeElement(addr); byte[] encNonce = RLP.encodeBigInteger(new BigInteger(1, nonce)); return sha3omit12(RLP.encodeList(encSender, encNonce)); }
Example 14
Source File: AccountState.java From nuls-v2 with MIT License | 5 votes |
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); byte[] owner = RLP.encodeElement(this.owner); this.rlpEncoded = RLP.encodeList(nonce, balance, stateRoot, codeHash, owner); } return rlpEncoded; }
Example 15
Source File: HashUtil.java From nuls-v2 with MIT License | 5 votes |
/** * The way to calculate new address inside ethereum * * @param addr - creating address * @param nonce - nonce of creating address * @return new address */ public static byte[] calcNewAddr(byte[] addr, byte[] nonce) { byte[] encSender = RLP.encodeElement(addr); byte[] encNonce = RLP.encodeBigInteger(new BigInteger(1, nonce)); return sha3omit12(RLP.encodeList(encSender, encNonce)); }
Example 16
Source File: Serializers.java From nuls with MIT License | 4 votes |
@Override public byte[] serialize(DataWord object) { return RLP.encodeElement(object.getNoLeadZeroesData()); }
Example 17
Source File: BlockHeader.java From nuls with MIT License | 4 votes |
public byte[] getEncoded(boolean withNonce) { byte[] parentHash = RLP.encodeElement(this.parentHash); byte[] hash = RLP.encodeElement(this.hash); byte[] number = RLP.encodeBigInteger(BigInteger.valueOf(this.number)); return RLP.encodeList(parentHash, hash, number); }
Example 18
Source File: BlockHeader.java From nuls-v2 with MIT License | 4 votes |
public byte[] getEncoded(boolean withNonce) { byte[] parentHash = RLP.encodeElement(this.parentHash); byte[] hash = RLP.encodeElement(this.hash); byte[] number = RLP.encodeBigInteger(BigInteger.valueOf(this.number)); return RLP.encodeList(parentHash, hash, number); }
Example 19
Source File: GetBlockHashesMessage.java From ethereumj with MIT License | 4 votes |
private void encode() { byte[] command = RLP.encodeByte(GET_BLOCK_HASHES.asByte()); byte[] hash = RLP.encodeElement(this.bestHash); byte[] maxBlocks = RLP.encodeInt(this.maxBlocks); this.encoded = RLP.encodeList(command, hash, maxBlocks); }
Example 20
Source File: Serializers.java From nuls-v2 with MIT License | 4 votes |
@Override public byte[] serialize(DataWord object) { return RLP.encodeElement(object.getNoLeadZeroesData()); }