mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-22 19:19:05 +00:00
Get author field for block data
This commit is contained in:
parent
30f3c9e694
commit
86dcee12f7
@ -38,6 +38,7 @@ export interface Block {
|
||||
difficulty: string;
|
||||
gasLimit: string;
|
||||
gasUsed: string;
|
||||
author: string;
|
||||
}
|
||||
|
||||
export interface EventData {
|
||||
@ -329,7 +330,8 @@ export const createBlock = async (instanceExports: any, blockData: Block): Promi
|
||||
const tdStringPtr = await __newString(blockData.td);
|
||||
const totalDifficulty = await BigInt.fromString(tdStringPtr);
|
||||
|
||||
const authorPtr = await Address.zero();
|
||||
const authorStringPtr = await __newString(blockData.author);
|
||||
const authorPtr = await Address.fromString(authorStringPtr);
|
||||
|
||||
const sizePtr = await __newString('0');
|
||||
const size = await BigInt.fromString(sizePtr);
|
||||
|
@ -19,30 +19,26 @@ function decodeNumber (value : string, defaultValue?: number): number | undefine
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
function decodeHex (hex: string): any {
|
||||
return Buffer.from(hex.slice(2), 'hex');
|
||||
}
|
||||
|
||||
export function decodeHeader (rlp : Uint8Array): any {
|
||||
try {
|
||||
const data = utils.RLP.decode(rlp);
|
||||
|
||||
try {
|
||||
return {
|
||||
Parent: decodeHex(data[0]),
|
||||
UnclesDigest: decodeHex(data[1]),
|
||||
Beneficiary: decodeHex(data[2]),
|
||||
StateRoot: decodeHex(data[4]),
|
||||
TxRoot: decodeHex(data[4]),
|
||||
RctRoot: decodeHex(data[5]),
|
||||
Bloom: decodeHex(data[6]),
|
||||
Parent: data[0],
|
||||
UnclesDigest: data[1],
|
||||
Beneficiary: data[2],
|
||||
StateRoot: data[4],
|
||||
TxRoot: data[4],
|
||||
RctRoot: data[5],
|
||||
Bloom: data[6],
|
||||
Difficulty: decodeInteger(data[7], BigInt(0)),
|
||||
Number: decodeInteger(data[8], BigInt(0)),
|
||||
GasLimit: decodeInteger(data[9], BigInt(0)),
|
||||
GasUsed: decodeInteger(data[10], BigInt(0)),
|
||||
Time: decodeNumber(data[11]) || 0,
|
||||
Extra: decodeHex(data[12]),
|
||||
MixDigest: decodeHex(data[13]),
|
||||
Extra: data[12],
|
||||
MixDigest: data[13],
|
||||
Nonce: decodeInteger(data[14], BigInt(0)),
|
||||
BaseFee: decodeInteger(data[15])
|
||||
};
|
||||
|
@ -189,8 +189,7 @@ export const getFullBlock = async (ethClient: EthClient, blockHash: string): Pro
|
||||
assert(header);
|
||||
|
||||
// TODO:
|
||||
// 1. Get author
|
||||
// 2. Calculate size
|
||||
// 1. Calculate size
|
||||
return {
|
||||
cid: fullBlock.cid,
|
||||
blockNumber: fullBlock.blockNumber,
|
||||
@ -204,6 +203,7 @@ export const getFullBlock = async (ethClient: EthClient, blockHash: string): Pro
|
||||
uncleHash: fullBlock.uncleRoot,
|
||||
difficulty: header.Difficulty.toString(),
|
||||
gasLimit: header.GasLimit.toString(),
|
||||
gasUsed: header.GasUsed.toString()
|
||||
gasUsed: header.GasUsed.toString(),
|
||||
author: header.Beneficiary
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user