use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class BlockGenerator method removeLastElement.
private static byte[] removeLastElement(byte[] rlpEncoded) {
ArrayList<RLPElement> params = RLP.decode2(rlpEncoded);
RLPList block = (RLPList) params.get(0);
RLPList header = (RLPList) block.get(0);
if (header.size() < 20) {
return rlpEncoded;
}
// remove last element
header.remove(header.size() - 1);
// remove second last element
header.remove(header.size() - 1);
List<byte[]> newHeader = new ArrayList<>();
for (int i = 0; i < header.size(); i++) {
byte[] e = nullReplace(header.get(i).getRLPData());
if (// fix bad feePaid
(e.length > 32) && (i == 15))
e = new byte[32];
newHeader.add(RLP.encodeElement(e));
}
byte[][] newHeaderElements = newHeader.toArray(new byte[newHeader.size()][]);
byte[] newEncodedHeader = RLP.encodeList(newHeaderElements);
return RLP.encodeList(newEncodedHeader, // very weird.
nullReplace(block.get(1).getRLPData()), nullReplace(block.get(2).getRLPData()));
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class FreeBlock method parseRLP.
private void parseRLP() {
ArrayList<RLPElement> params = RLP.decode2(rlpEncoded);
RLPList block = (RLPList) params.get(0);
// Parse Header
RLPList header = (RLPList) block.get(0);
this.header = new FreeBlockHeader(header);
// Parse Transactions
RLPList txTransactions = (RLPList) block.get(1);
this.transactionsList = parseTxs(txTransactions);
byte[] calculatedRoot = getTxTrie(this.transactionsList).getHash().getBytes();
// Parse Uncles
RLPList uncleBlocks = (RLPList) block.get(2);
for (RLPElement rawUncle : uncleBlocks) {
RLPList uncleHeader = (RLPList) rawUncle;
FreeBlockHeader blockData = new FreeBlockHeader(uncleHeader);
this.uncleList.add(blockData);
}
this.parsed = true;
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class FindNodePeerMessage method parse.
@Override
public final void parse(byte[] data) {
RLPList dataList = (RLPList) RLP.decode2OneItem(data, 0);
RLPItem chk = (RLPItem) dataList.get(1);
this.messageId = new String(chk.getRLPData(), Charset.forName("UTF-8"));
RLPItem nodeRlp = (RLPItem) dataList.get(0);
this.nodeId = nodeRlp.getRLPData();
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class PingPeerMessage method parse.
@Override
public final void parse(byte[] data) {
RLPList dataList = (RLPList) RLP.decode2OneItem(data, 0);
RLPList fromList = (RLPList) dataList.get(1);
RLPItem chk = (RLPItem) dataList.get(2);
byte[] ipB = fromList.get(0).getRLPData();
this.host = new String(ipB, Charset.forName("UTF-8"));
this.port = ByteUtil.byteArrayToInt(fromList.get(1).getRLPData());
this.messageId = new String(chk.getRLPData(), Charset.forName("UTF-8"));
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class RskMessage method parse.
protected void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
this.message = Message.create((RLPList) paramsList.get(0));
this.parsed = true;
}
Aggregations