Skip to content

Commit

Permalink
feat(providers): separate tx body
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Oct 27, 2024
1 parent c73a8b9 commit 90c0a38
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 38 deletions.
9 changes: 2 additions & 7 deletions apps/klesia/src/methods/mina.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { gql } from "@urql/core";
import { calculateQuantile } from "bigint-quantile";
import { match } from "ts-pattern";
import {
SendDelegationBodySchema,
SendTransactionBodySchema,
SendZkAppBodySchema,
} from "../schema";
import { SendTransactionBodySchema, SendZkAppBodySchema } from "../schema";
import { getNodeClient } from "../utils/node";

export const PRIORITY = {
Expand Down Expand Up @@ -113,7 +108,7 @@ const sendTransaction = async ({
})
.with("delegation", async () => {
const { signature, input } =
SendDelegationBodySchema.parse(signedTransaction);
SendTransactionBodySchema.parse(signedTransaction);
const { data } = await client.mutation(
gql`
mutation {
Expand Down
13 changes: 2 additions & 11 deletions apps/klesia/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
PublicKeySchema,
TransportableDelegationPayload,
TransportableTransactionPayload,
} from "@mina-js/utils";
import { PublicKeySchema, TransactionPayload } from "@mina-js/utils";
import { z } from "zod";
import { SendZkappInput } from "./zkapp";

Expand All @@ -16,19 +12,14 @@ export const SignatureSchema = z.union([
z.object({ field: z.string(), scalar: z.string() }),
]);
export const SendTransactionBodySchema = z.object({
input: TransportableTransactionPayload,
signature: SignatureSchema,
});
export const SendDelegationBodySchema = z.object({
input: TransportableDelegationPayload,
input: TransactionPayload,
signature: SignatureSchema,
});
export const SendZkAppBodySchema = z.object({
input: SendZkappInput,
});
export const SendableSchema = z.union([
SendTransactionBodySchema,
SendDelegationBodySchema,
SendZkAppBodySchema,
]);
export const SendTransactionSchema = z.tuple([
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FieldSchema, TransactionPayload } from "@mina-js/utils";
import { FieldSchema, TransactionBody } from "@mina-js/utils";
import { z } from "zod";

export const SignFieldsParamsSchema = z
Expand All @@ -21,6 +21,6 @@ export const CreateNullifierParamsSchema = z

export const SignTransactionParamsSchema = z
.object({
transaction: TransactionPayload,
transaction: TransactionBody,
})
.strict();
23 changes: 5 additions & 18 deletions packages/utils/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,24 @@ export const FeePayerSchema = z
})
.strict();

export const DelegationPayload = z
export const TransactionBody = z
.object({
from: PublicKeySchema,
to: PublicKeySchema,
memo: z.string().optional(),
fee: z.coerce.string(),
nonce: z.coerce.string(),
validUntil: z.coerce.string().optional(),
amount: z.coerce.string().optional(),
})
.strict();

export const TransportableDelegationPayload = z
export const TransactionPayload = z
.object({
from: PublicKeySchema,
to: PublicKeySchema,
memo: z.string().optional(),
fee: z.coerce.string(),
nonce: z.coerce.string(),
validUntil: z.coerce.string().optional(),
transaction: TransactionBody,
})
.strict();

export const TransactionPayload = DelegationPayload.extend({
amount: z.coerce.string(),
}).strict();

export const TransportableTransactionPayload =
TransportableDelegationPayload.extend({
amount: z.coerce.string(),
}).strict();

export const PartiallyFormedTransactionPayload = TransactionPayload.extend({
fee: z.coerce.string().optional(),
nonce: z.coerce.string().optional(),
Expand Down Expand Up @@ -125,7 +112,7 @@ export const SignedTransactionSchema = z
.object({
signature: SignatureSchema,
publicKey: PublicKeySchema,
data: TransactionPayload,
data: TransactionBody,
})
.strict();

Expand Down

0 comments on commit 90c0a38

Please sign in to comment.