Skip to content

Commit

Permalink
Added logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HiroyukiNaito committed Mar 15, 2024
1 parent cfb3704 commit 7359cad
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions packages/beacon-node/src/api/impl/builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
import {routes, ServerApi} from "@lodestar/api";
import {Slot} from "@lodestar/types";
import {getExpectedWithdrawals} from "@lodestar/state-transition";
import {CachedBeaconStateCapella} from "@lodestar/state-transition/src/types.js";
import {ExpectedWithdrawals} from "@lodestar/api/src/beacon/routes/builder.js";
import {ApiModules} from "../types.js";
import {resolveStateId} from "../beacon/state/utils.js";

export function getBuilderApi({chain, config}: Pick<ApiModules, "chain" | "config">): ServerApi<routes.builder.Api> {
export function getBuilderApi({chain}: Pick<ApiModules, "chain" | "config">): ServerApi<routes.builder.Api> {
return {
async getExpectedWithdrawals(stateId: routes.beacon.StateId, proposalSlot?: Slot | undefined) {
const {state, executionOptimistic} = await resolveStateId(chain, stateId, {allowRegen: true});
const expectedWithdrawals = getExpectedWithdrawals(state as CachedBeaconStateCapella).withdrawals;
// eslint-disable-next-line no-console
console.log(chain, config, stateId, proposalSlot);
console.log("Prolosal Slot", proposalSlot, "State data", state, "expectedWithdrawlsData", expectedWithdrawals);
return {
executionOptimistic: false,
data: [
{
index: 1,
validatorIndex: 1,
address: "0xAbcF8e0d4e9587369b2301D0790347320302cc09",
amount: 1,
},
],
executionOptimistic: executionOptimistic,
data: expectedWithdrawals.map((item: {address: Uint8Array}) => ({
...item,
address: Buffer.from(item.address).toString("hex"), // Convert Uint8Array to hexadecimal string
})) as ExpectedWithdrawals[],
};
},
};
}

// data: [
// {
// index: 1,
// validatorIndex: 1,
// address: "0xAbcF8e0d4e9587369b2301D0790347320302cc09",
// amount: 1,
// },
// ],

0 comments on commit 7359cad

Please sign in to comment.