@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
33 lines • 1.34 kB
JavaScript
import { Interface } from "@ethersproject/abi";
import { ssz } from "@lodestar/types";
import { fromHex } from "@lodestar/utils";
const depositEventFragment = "event DepositEvent(bytes pubkey, bytes withdrawal_credentials, bytes amount, bytes signature, bytes index)";
const depositContractInterface = new Interface([depositEventFragment]);
/**
* Precomputed topics of DepositEvent logs
*/
export const depositEventTopics = [depositContractInterface.getEventTopic("DepositEvent")];
/**
* Parse DepositEvent log
*/
export function parseDepositLog(log) {
const event = depositContractInterface.parseLog(log);
const values = event.args;
if (values === undefined)
throw Error(`DepositEvent at ${log.blockNumber} has no values`);
return {
blockNumber: log.blockNumber,
index: parseHexNumLittleEndian(values.index),
depositData: {
pubkey: fromHex(values.pubkey),
withdrawalCredentials: fromHex(values.withdrawal_credentials),
amount: parseHexNumLittleEndian(values.amount),
signature: fromHex(values.signature),
},
};
}
function parseHexNumLittleEndian(hex) {
// Can't use parseInt() because amount is a hex string in little endian
return ssz.UintNum64.deserialize(fromHex(hex));
}
//# sourceMappingURL=depositContract.js.map