use of org.ethereum.util.RLPElement in project rskj by rsksmart.
the class Block method parseTxs.
private List<Transaction> parseTxs(RLPList txTransactions) {
List<Transaction> parsedTxs = new ArrayList<>();
for (int i = 0; i < txTransactions.size(); i++) {
RLPElement transactionRaw = txTransactions.get(i);
Transaction tx = new ImmutableTransaction(transactionRaw.getRLPData());
if (isRemascTransaction(tx, i, txTransactions.size())) {
// It is the remasc transaction
tx = new RemascTransaction(transactionRaw.getRLPData());
}
parsedTxs.add(tx);
}
return Collections.unmodifiableList(parsedTxs);
}
use of org.ethereum.util.RLPElement 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.RLPElement in project rskj by rsksmart.
the class FreeBlock method parseTxs.
private static List<Transaction> parseTxs(RLPList txTransactions) {
List<Transaction> parsedTxs = new ArrayList<>();
for (int i = 0; i < txTransactions.size(); i++) {
RLPElement transactionRaw = txTransactions.get(i);
Transaction tx = new ImmutableTransaction(transactionRaw.getRLPData());
parsedTxs.add(tx);
}
return Collections.unmodifiableList(parsedTxs);
}
use of org.ethereum.util.RLPElement 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.RLPElement in project rskj by rsksmart.
the class ProofOfWorkRule method validFallbackBlockSignature.
public static boolean validFallbackBlockSignature(Constants constants, BlockHeader header, byte[] signatureBytesRLP) {
if (header.getBitcoinMergedMiningCoinbaseTransaction() != null) {
return false;
}
if (header.getBitcoinMergedMiningMerkleProof() != null) {
return false;
}
byte[] fallbackMiningPubKeyBytes;
boolean isEvenBlockNumber = header.getNumber() % 2 == 0;
if (isEvenBlockNumber) {
fallbackMiningPubKeyBytes = constants.getFallbackMiningPubKey0();
} else {
fallbackMiningPubKeyBytes = constants.getFallbackMiningPubKey1();
}
ECKey fallbackMiningPubKey = ECKey.fromPublicOnly(fallbackMiningPubKeyBytes);
List<RLPElement> signatureRLP = (RLPList) RLP.decode2(signatureBytesRLP).get(0);
if (signatureRLP.size() != 3) {
return false;
}
byte[] v = signatureRLP.get(0).getRLPData();
byte[] r = signatureRLP.get(1).getRLPData();
byte[] s = signatureRLP.get(2).getRLPData();
ECKey.ECDSASignature signature = ECKey.ECDSASignature.fromComponents(r, s, v[0]);
return fallbackMiningPubKey.verify(header.getHashForMergedMining(), signature);
}
Aggregations