use of org.aion.zero.types.A0BlockHeader in project aion by aionnetwork.
the class ApiWeb3Aion method stratum_getHeaderByBlockNumber.
public Object stratum_getHeaderByBlockNumber(Object _blockNum) {
JSONObject obj = new JSONObject();
if (_blockNum != null && !_blockNum.equals(null)) {
String bnStr = _blockNum + "";
try {
int bnInt = Integer.decode(bnStr);
AionBlock block = getBlockRaw(bnInt);
if (block != null) {
A0BlockHeader header = block.getHeader();
// 0 = success
obj.put("code", 0);
obj.put("nonce", toHexString(header.getNonce()));
obj.put("solution", toHexString(header.getSolution()));
obj.put("headerHash", toHexString(HashUtil.h256(header.getHeaderBytes(false))));
obj.putOpt("blockHeader", header.toJSON());
} else {
obj.put("message", "Fail - Unable to find block" + bnStr);
obj.put("code", -2);
}
} catch (Exception e) {
obj.put("message", bnStr + " must be an integer value");
obj.put("code", -3);
}
} else {
obj.put("message", "Missing block number");
obj.put("code", -1);
}
return obj;
}
use of org.aion.zero.types.A0BlockHeader in project aion by aionnetwork.
the class AionBlock method parseRLP.
public void parseRLP() {
if (this.parsed) {
return;
}
synchronized (this) {
if (this.parsed)
return;
RLPList params = RLP.decode2(rlpEncoded);
RLPList block = (RLPList) params.get(0);
// Parse Header
RLPList header = (RLPList) block.get(0);
this.header = new A0BlockHeader(header);
// Parse Transactions
RLPList txTransactions = (RLPList) block.get(1);
this.parseTxs(this.header.getTxTrieRoot(), txTransactions);
this.parsed = true;
}
}
use of org.aion.zero.types.A0BlockHeader in project aion by aionnetwork.
the class AionBlockHeaderWrapper method parse.
protected void parse(byte[] bytes) {
List<RLPElement> params = RLP.decode2(bytes);
List<RLPElement> wrapper = (RLPList) params.get(0);
byte[] headerBytes = wrapper.get(0).getRLPData();
this.header = new A0BlockHeader(headerBytes);
this.nodeId = wrapper.get(1).getRLPData();
}
use of org.aion.zero.types.A0BlockHeader in project aion by aionnetwork.
the class ResBlocksHeadersTest method testHeaders.
@Test
public void testHeaders() {
int m = 192;
List<A0BlockHeader> bhs1 = new ArrayList<A0BlockHeader>();
for (int i = 0; i < m; i++) {
bhs1.add(bh1);
}
ResBlocksHeaders rbhs1 = new ResBlocksHeaders(bhs1);
byte[] rbhsBytes = rbhs1.encode();
ResBlocksHeaders rbhs2 = ResBlocksHeaders.decode(rbhsBytes);
List<A0BlockHeader> bhs2 = rbhs2.getHeaders();
assertThat(bhs2.size()).isEqualTo(m);
}
use of org.aion.zero.types.A0BlockHeader in project aion by aionnetwork.
the class A0BlockHeaderTest method testBlockHeaderFromSafeBuilder.
@Test
public void testBlockHeaderFromSafeBuilder() {
long time = System.currentTimeMillis() / 1000;
A0BlockHeader.Builder builder = new A0BlockHeader.Builder();
// partial build
builder.withCoinbase(Address.wrap(COINBASE)).withStateRoot(STATE_ROOT).withTxTrieRoot(TRIE_ROOT).withExtraData(EXTRA_DATA).withReceiptTrieRoot(RECEIPT_ROOT).withTimestamp(time).withNumber(NUMBER_BYTES).withEnergyConsumed(ENERGY_CONSUMED_BYTES).withEnergyLimit(ENERGY_LIMIT_BYTES).withParentHash(PARENT_HASH);
A0BlockHeader header = builder.build();
assertThat(header.getCoinbase().toBytes()).isEqualTo(COINBASE);
assertThat(header.getStateRoot()).isEqualTo(STATE_ROOT);
assertThat(header.getTxTrieRoot()).isEqualTo(TRIE_ROOT);
assertThat(header.getExtraData()).isEqualTo(EXTRA_DATA);
assertThat(header.getReceiptsRoot()).isEqualTo(RECEIPT_ROOT);
assertThat(header.getTimestamp()).isEqualTo(time);
assertThat(header.getNumber()).isEqualTo(NUMBER);
assertThat(header.getEnergyConsumed()).isEqualTo(ENERGY_CONSUMED);
assertThat(header.getEnergyLimit()).isEqualTo(ENERGY_LIMIT);
assertThat(header.getSolution()).isEqualTo(new byte[1408]);
}
Aggregations