Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RPC proxy submission params a string to preserve field order #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ContactlessPaymentTxOrMsg" ALTER COLUMN "rpcProxySubmissionParams" SET DATA TYPE TEXT;
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ model ContactlessPaymentTxOrMsg {
payloadType String
chainId String
txParams Json?
rpcProxySubmissionParams Json?
rpcProxySubmissionParams String? // stored as a stringified Json to preserve field order
additionalPayload Json?
dappName String?
dappUrl String?
Expand Down
8 changes: 5 additions & 3 deletions src/services/paymentTxOrMsgService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const createPaymentTxOrMsg = async (payload: Payload) => {
dappName: payload.dappName,
payloadType: payload.payloadType,
additionalPayload: payload.additionalPayload,
rpcProxySubmissionParams: payload.rpcProxySubmissionParams,
rpcProxySubmissionParams: JSON.stringify(payload.rpcProxySubmissionParams), // we stringify ths object to store it in the database to preserve field order
};

let txParams: Prisma.JsonValue;
Expand All @@ -47,7 +47,8 @@ export const createPaymentTxOrMsg = async (payload: Payload) => {
paymentTx: payload.paymentTx,
};
} else if (isEip712Payload(payload)) {
txParams = { message: payload.message };
// noop, rpcProxySubmissionParams contains the message needed to be signed and submitted
txParams = {};
} else {
throw new Error('Invalid payload type');
}
Expand Down Expand Up @@ -75,9 +76,10 @@ export const getPaymentTxOrMsg = async (uuid: string) => {
}

// remove the txParams prop and flatten
const { txParams, ...rest } = paymentTxOrMsg;
const { txParams, rpcProxySubmissionParams, ...rest } = paymentTxOrMsg;
return {
...rest,
rpcProxySubmissionParams: typeof rpcProxySubmissionParams === 'string' ? JSON.parse(rpcProxySubmissionParams) : undefined,
...(txParams as Record<string, unknown>),
};
};
Loading