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