Fixed BlockMessage parsing for POC-5
This commit is contained in:
parent
812a2c224e
commit
c1d619bc92
|
@ -109,10 +109,11 @@ public class Block {
|
||||||
// extradata, nonce]
|
// extradata, nonce]
|
||||||
private void parseRLP() {
|
private void parseRLP() {
|
||||||
|
|
||||||
this.hash = HashUtil.sha3(rawData.getRLPData());
|
|
||||||
|
|
||||||
RLPList params = (RLPList) rawData.get(0);
|
RLPList params = (RLPList) rawData.get(0);
|
||||||
|
|
||||||
|
this.hash = HashUtil.sha3(params.getRLPData());
|
||||||
|
|
||||||
|
|
||||||
this.parentHash = ((RLPItem) params.get(0)).getData();
|
this.parentHash = ((RLPItem) params.get(0)).getData();
|
||||||
this.unclesHash = ((RLPItem) params.get(1)).getData();
|
this.unclesHash = ((RLPItem) params.get(1)).getData();
|
||||||
this.coinbase = ((RLPItem) params.get(2)).getData();
|
this.coinbase = ((RLPItem) params.get(2)).getData();
|
||||||
|
@ -120,7 +121,7 @@ public class Block {
|
||||||
this.txTrieRoot = ((RLPItem) params.get(4)).getData();
|
this.txTrieRoot = ((RLPItem) params.get(4)).getData();
|
||||||
this.difficulty = ((RLPItem) params.get(5)).getData();
|
this.difficulty = ((RLPItem) params.get(5)).getData();
|
||||||
|
|
||||||
byte[] tsBytes = ((RLPItem) params.get(6)).getData();
|
byte[] tsBytes = ((RLPItem) params.get(6)).getData();
|
||||||
byte[] nrBytes = ((RLPItem) params.get(7)).getData();
|
byte[] nrBytes = ((RLPItem) params.get(7)).getData();
|
||||||
byte[] gpBytes = ((RLPItem) params.get(8)).getData();
|
byte[] gpBytes = ((RLPItem) params.get(8)).getData();
|
||||||
byte[] glBytes = ((RLPItem) params.get(9)).getData();
|
byte[] glBytes = ((RLPItem) params.get(9)).getData();
|
||||||
|
@ -128,9 +129,9 @@ public class Block {
|
||||||
|
|
||||||
this.timestamp = (new BigInteger(tsBytes)).longValue();
|
this.timestamp = (new BigInteger(tsBytes)).longValue();
|
||||||
this.number = (new BigInteger(nrBytes)).longValue();
|
this.number = (new BigInteger(nrBytes)).longValue();
|
||||||
this.minGasPrice = (new BigInteger(gpBytes)).longValue();
|
this.minGasPrice = gpBytes == null ? 0 : (new BigInteger(gpBytes)).longValue();
|
||||||
this.gasLimit = (new BigInteger(glBytes)).longValue();
|
this.gasLimit = glBytes == null ? 0 : (new BigInteger(glBytes)).longValue();
|
||||||
this.gasUsed = (new BigInteger(guBytes)).longValue();
|
this.gasUsed = guBytes == null ? 0 : (new BigInteger(guBytes)).longValue();
|
||||||
|
|
||||||
this.extraData = ((RLPItem) params.get(11)).getData();
|
this.extraData = ((RLPItem) params.get(11)).getData();
|
||||||
this.nonce = ((RLPItem) params.get(12)).getData();
|
this.nonce = ((RLPItem) params.get(12)).getData();
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class BlocksMessage extends Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
if (!parsed) parseRLP();
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (Block blockData : this.getBlockDataList()) {
|
for (Block blockData : this.getBlockDataList()) {
|
||||||
|
|
|
@ -187,6 +187,22 @@ public class BlockTest {
|
||||||
Block blockData = new Block(rlpList);
|
Block blockData = new Block(rlpList);
|
||||||
RLPList.recursivePrint(rlpList);
|
RLPList.recursivePrint(rlpList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test /* create BlockData from part of real RLP BLOCKS message POC-5 */
|
||||||
|
public void test4(){
|
||||||
|
|
||||||
|
String blocksMsg = "F8D1A0085F6A51A63D1FBA43D6E5FE166A47BED64A8B93A99012537D50F3279D4CEA52A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934794D8758B101609A9F2A881A017BA86CBE6B7F0581DA068472689EA736CFC6B18FCAE9BA7454BADF9C65333A0317DFEFAE1D4AFFF6F90A000000000000000000000000000000000000000000000000000000000000000008401EDF1A18222778609184E72A0008080845373B0B180A0000000000000000000000000000000000000000000000000D1C0D8BC6D744943C0C0";
|
||||||
|
|
||||||
|
byte[] payload = Hex.decode(blocksMsg);
|
||||||
|
|
||||||
|
RLPList rlpList = RLP.decode2(payload);
|
||||||
|
|
||||||
|
Block blockData = new Block(rlpList);
|
||||||
|
|
||||||
|
System.out.println(blockData.toString());
|
||||||
|
RLPList.recursivePrint(rlpList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -463,5 +463,23 @@ public class MessagesTest {
|
||||||
assertEquals("E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138",
|
assertEquals("E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138",
|
||||||
Utils.toHexString(notInChainMessage.getHash()).toUpperCase());
|
Utils.toHexString(notInChainMessage.getHash()).toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test /* BlocksMessage POC-5 real msg*/
|
||||||
|
public void test12(){
|
||||||
|
|
||||||
|
String blocksRaw = "F8D813F8D5F8D1A0085F6A51A63D1FBA43D6E5FE166A47BED64A8B93A99012537D50F3279D4CEA52A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934794D8758B101609A9F2A881A017BA86CBE6B7F0581DA068472689EA736CFC6B18FCAE9BA7454BADF9C65333A0317DFEFAE1D4AFFF6F90A000000000000000000000000000000000000000000000000000000000000000008401EDF1A18222778609184E72A0008080845373B0B180A0000000000000000000000000000000000000000000000000D1C0D8BC6D744943C0C0";
|
||||||
|
|
||||||
|
byte[] payload = Hex.decode(blocksRaw);
|
||||||
|
RLPList rlpList = RLP.decode2(payload);
|
||||||
|
|
||||||
|
BlocksMessage blocksMessage = new BlocksMessage(rlpList);
|
||||||
|
List<Block> list = blocksMessage.getBlockDataList();
|
||||||
|
System.out.println(blocksMessage);
|
||||||
|
|
||||||
|
|
||||||
|
Block block = list.get(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue