diff --git a/src/ancillary/anchor-request-params-parser.ts b/src/ancillary/anchor-request-params-parser.ts index 10d9b4580..7a0dcb13f 100644 --- a/src/ancillary/anchor-request-params-parser.ts +++ b/src/ancillary/anchor-request-params-parser.ts @@ -1,6 +1,5 @@ import type { Request as ExpReq } from 'express' import type { CID } from 'multiformats/cid' -import type { StreamID } from '@ceramicnetwork/streamid' import { CARFactory, type CAR } from 'cartonne' import { ServiceMetrics as Metrics } from '@ceramicnetwork/observability' import { METRIC_NAMES } from '../settings.js' @@ -23,6 +22,8 @@ import { isLeft, decode, validate, + type, + union, type TypeOf, type Decoder, type Validation, @@ -49,15 +50,25 @@ const RequestAnchorParamsV2Root = strict({ tip: cid, }) -export type RequestAnchorParamsV2 = { - streamId: StreamID - timestamp: Date - cid: CID - genesisFields: GenesisFields -} +/** + * Used to encode request params for logging purposes + */ +export const RequestAnchorParamsV2 = type({ + streamId: streamIdAsString, + timestamp: date, + cid: cidAsString, + genesisFields: GenesisFields, +}) + +export type RequestAnchorParamsV2 = TypeOf export type RequestAnchorParams = RequestAnchorParamsV1 | RequestAnchorParamsV2 +/** + * Encode request params for logging purposes. + */ +export const RequestAnchorParamsCodec = union([RequestAnchorParamsV1, RequestAnchorParamsV2]) + const DAG_JOSE_CODE = 133 const DAG_CBOR_CODE = 113 diff --git a/src/controllers/request-controller.ts b/src/controllers/request-controller.ts index 1a776dacc..2e129a84e 100644 --- a/src/controllers/request-controller.ts +++ b/src/controllers/request-controller.ts @@ -11,6 +11,7 @@ import { METRIC_NAMES } from '../settings.js' import { AnchorRequestParamsParser, RequestAnchorParams, + RequestAnchorParamsCodec, } from '../ancillary/anchor-request-params-parser.js' import bodyParser from 'body-parser' import type { RequestService } from '../services/request-service.js' @@ -94,8 +95,6 @@ export class RequestController { async createRequest(req: ExpReq, res: ExpRes): Promise> { const origin = parseOrigin(req) - logger.debug(`Create request ${JSON.stringify(req.body)}`) - const validation = this.anchorRequestParamsParser.parse(req) if (isLeft(validation)) { @@ -108,6 +107,8 @@ export class RequestController { } const requestParams = validation.right + logger.debug(`Create request ${JSON.stringify(RequestAnchorParamsCodec.encode(requestParams))}`) + try { const found = await this.requestService.findByCid(requestParams.cid) if (found) {