@@ -1100,7 +1100,31 @@ proc readValue*[BlockType: Web3SignerForkedBeaconBlock](
11001100 capellaData: res.get ())
11011101
11021102proc writeValue * [
1103- BlockType: Web3SignerForkedBeaconBlock | ForkedBeaconBlock | ForkedBlindedBeaconBlock ](
1103+ BlockType: Web3SignerForkedBeaconBlock ](
1104+ writer: var JsonWriter [RestJson ],
1105+ value: BlockType ) {.raises : [IOError , Defect ].} =
1106+ template forkIdentifier (id: string ): auto = (static toUpperAscii id)
1107+
1108+ # https://consensys.github.io/web3signer/web3signer-eth2.html#tag/Signing/operation/ETH2_SIGN
1109+ # https://github.com/ConsenSys/web3signer/blob/d51337e96ba5ce410222943556bed7c4856b8e57/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/signing/eth2/json/BlockRequestDeserializer.java#L42-L58
1110+ writer.beginRecord ()
1111+ case value.kind
1112+ of BeaconBlockFork .Phase0 :
1113+ writer.writeField (" version" , forkIdentifier " phase0" )
1114+ writer.writeField (" block" , value.phase0Data)
1115+ of BeaconBlockFork .Altair :
1116+ writer.writeField (" version" , forkIdentifier " altair" )
1117+ writer.writeField (" block" , value.altairData)
1118+ of BeaconBlockFork .Bellatrix :
1119+ writer.writeField (" version" , forkIdentifier " bellatrix" )
1120+ writer.writeField (" block_header" , value.bellatrixData)
1121+ of BeaconBlockFork .Capella :
1122+ writer.writeField (" version" , forkIdentifier " capella" )
1123+ writer.writeField (" block_header" , value.capellaData)
1124+ writer.endRecord ()
1125+
1126+ proc writeValue * [
1127+ BlockType: ForkedBeaconBlock | ForkedBlindedBeaconBlock ](
11041128 writer: var JsonWriter [RestJson ],
11051129 value: BlockType ) {.raises : [IOError , Defect ].} =
11061130
@@ -1702,9 +1726,9 @@ proc writeValue*(writer: var JsonWriter[RestJson],
17021726 if isSome (value.signingRoot):
17031727 writer.writeField (" signingRoot" , value.signingRoot)
17041728
1705- # https://github.com/ConsenSys/web3signer/blob/41834a927088f1bde7a097e17d19e954d0058e54/core/src/main/resources/openapi-specs/eth2/signing/schemas.yaml#L421-L425 (branch v22.7.0)
1706- # It's the "beacon_block" field even when it's not a block, but a header
1729+ # https://github.com/ConsenSys/web3signer/blob/41c0cbfabcb1fca9587b59e058b7eb29f152c60c/core/src/main/resources/openapi-specs/eth2/signing/schemas.yaml#L418-L497
17071730 writer.writeField (" beacon_block" , value.beaconBlock)
1731+
17081732 of Web3SignerRequestKind .Deposit :
17091733 writer.writeField (" type" , " DEPOSIT" )
17101734 if isSome (value.signingRoot):
0 commit comments