Skip to content

Commit

Permalink
Use ssz type to handle json serialization
Browse files Browse the repository at this point in the history
Default parsing can't handle BigInt
  • Loading branch information
nflaig committed Oct 30, 2024
1 parent e26785c commit 01fcea7
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions packages/api/src/keymanager/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {ContainerType, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {Epoch, phase0, ssz, stringType} from "@lodestar/types";
import {Schema, Endpoint, RouteDefinitions} from "../utils/index.js";
import {RecursivePartial} from "@lodestar/utils";
import {Schema, Endpoint, RouteDefinitions, ResponseDataCodec} from "../utils/index.js";
import {WireFormat} from "../utils/wireFormat.js";
import {
EmptyArgs,
Expand Down Expand Up @@ -90,11 +91,28 @@ export const BuilderBoostFactorDataType = new ContainerType(
},
{jsonCase: "eth2"}
);
export const ProposerConfigType = new ContainerType(
{
graffiti: stringType,
strictFeeRecipientCheck: ssz.Boolean,
feeRecipient: stringType,
builder: new ContainerType(
{
gasLimit: ssz.UintNum64,
selection: stringType,
boostFactor: ssz.UintBn64,
},
{jsonCase: "eth2"}
),
},
{jsonCase: "eth2"}
);

export type FeeRecipientData = ValueOf<typeof FeeRecipientDataType>;
export type GraffitiData = ValueOf<typeof GraffitiDataType>;
export type GasLimitData = ValueOf<typeof GasLimitDataType>;
export type BuilderBoostFactorData = ValueOf<typeof BuilderBoostFactorDataType>;
export type ProposerConfig = RecursivePartial<ValueOf<typeof ProposerConfigType>>;

export type SignerDefinition = {
pubkey: PubkeyHex;
Expand All @@ -109,17 +127,6 @@ export type SignerDefinition = {

export type RemoteSignerDefinition = Pick<SignerDefinition, "pubkey" | "url">;

export type ProposerConfig = {
graffiti?: string;
strictFeeRecipientCheck?: boolean;
feeRecipient?: string;
builder?: {
gasLimit?: number;
selection?: string;
boostFactor?: bigint;
};
};

/**
* JSON serialized representation of a single keystore in EIP-2335: BLS12-381 Keystore format.
* ```
Expand Down Expand Up @@ -665,7 +672,11 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
params: {pubkey: Schema.StringRequired},
},
},
resp: JsonOnlyResponseCodec,
resp: {
onlySupport: WireFormat.json,
data: ProposerConfigType as ResponseDataCodec<ProposerConfig, EmptyMeta>,
meta: EmptyMetaCodec,
},
},

signVoluntaryExit: {
Expand Down

0 comments on commit 01fcea7

Please sign in to comment.