Skip to content

Commit a95cfd0

Browse files
feat: add claims missing fields
1 parent bd32dd7 commit a95cfd0

File tree

3 files changed

+113
-11
lines changed

3 files changed

+113
-11
lines changed

src/postgres/claim.ts

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export type ClaimCollection = {
1616
invalidated: number;
1717
state: number;
1818
payments: any; // JSON
19+
escrowAccount?: string;
20+
intents?: number;
1921
};
2022

2123
const createClaimCollectionSql = `
22-
INSERT INTO "public"."ClaimCollection" ( "id", "entity", "admin", "protocol", "startDate", "endDate", "quota", "count", "evaluated", "approved", "rejected", "disputed", "invalidated", "state", "payments")
23-
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15 );
24+
INSERT INTO "public"."ClaimCollection" ( "id", "entity", "admin", "protocol", "startDate", "endDate", "quota", "count", "evaluated", "approved", "rejected", "disputed", "invalidated", "state", "payments", "escrowAccount", "intents")
25+
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17 );
2426
`;
2527
export const createClaimCollection = async (
2628
p: ClaimCollection
@@ -41,6 +43,8 @@ export const createClaimCollection = async (
4143
p.invalidated,
4244
p.state,
4345
JSON.stringify(p.payments),
46+
p.escrowAccount,
47+
p.intents,
4448
]);
4549
};
4650

@@ -59,9 +63,11 @@ UPDATE "public"."ClaimCollection" SET
5963
"disputed" = $11,
6064
"invalidated" = $12,
6165
"state" = $13,
62-
"payments" = $14
66+
"payments" = $14,
67+
"escrowAccount" = $15,
68+
"intents" = $16
6369
WHERE
64-
"id" = $15;
70+
"id" = $17;
6571
`;
6672
export const updateClaimCollection = async (
6773
p: ClaimCollection
@@ -81,6 +87,8 @@ export const updateClaimCollection = async (
8187
p.invalidated,
8288
p.state,
8389
JSON.stringify(p.payments),
90+
p.escrowAccount,
91+
p.intents,
8492
p.id,
8593
]);
8694
};
@@ -94,11 +102,16 @@ export type Claim = {
94102
schemaType?: string;
95103
collectionId: string;
96104
evaluation?: Evaluation;
105+
useIntent?: boolean;
106+
amount?: any; // JSON
107+
cw20Payment?: any; // JSON
108+
cw1155Payment?: any; // JSON
109+
cw1155IntentPayment?: any; // JSON
97110
};
98111

99112
const createClaimSql = `
100-
INSERT INTO "public"."Claim" ( "claimId", "agentDid", "agentAddress", "submissionDate", "paymentsStatus", "schemaType", "collectionId")
101-
VALUES ( $1, $2, $3, $4, $5, $6, $7 );
113+
INSERT INTO "public"."Claim" ( "claimId", "agentDid", "agentAddress", "submissionDate", "paymentsStatus", "schemaType", "collectionId", "useIntent", "amount", "cw20Payment", "cw1155Payment", "cw1155IntentPayment")
114+
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 );
102115
`;
103116
export const createClaim = async (p: Claim): Promise<void> => {
104117
await dbQuery(createClaimSql, [
@@ -109,6 +122,11 @@ export const createClaim = async (p: Claim): Promise<void> => {
109122
JSON.stringify(p.paymentsStatus),
110123
p.schemaType,
111124
p.collectionId,
125+
p.useIntent,
126+
p.amount ? JSON.stringify(p.amount) : null,
127+
p.cw20Payment ? JSON.stringify(p.cw20Payment) : null,
128+
p.cw1155Payment ? JSON.stringify(p.cw1155Payment) : null,
129+
p.cw1155IntentPayment ? JSON.stringify(p.cw1155IntentPayment) : null,
112130
]);
113131
};
114132

@@ -119,9 +137,14 @@ UPDATE "public"."Claim" SET
119137
"submissionDate" = $3,
120138
"paymentsStatus" = $4,
121139
"schemaType" = $5,
122-
"collectionId" = $6
140+
"collectionId" = $6,
141+
"useIntent" = $7,
142+
"amount" = $8,
143+
"cw20Payment" = $9,
144+
"cw1155Payment" = $10,
145+
"cw1155IntentPayment" = $11
123146
WHERE
124-
"claimId" = $7;
147+
"claimId" = $12;
125148
`;
126149
export const updateClaim = async (p: Claim): Promise<void> => {
127150
await dbQuery(updateClaimSql, [
@@ -131,6 +154,11 @@ export const updateClaim = async (p: Claim): Promise<void> => {
131154
JSON.stringify(p.paymentsStatus),
132155
p.schemaType,
133156
p.collectionId,
157+
p.useIntent,
158+
p.amount ? JSON.stringify(p.amount) : null,
159+
p.cw20Payment ? JSON.stringify(p.cw20Payment) : null,
160+
p.cw1155Payment ? JSON.stringify(p.cw1155Payment) : null,
161+
p.cw1155IntentPayment ? JSON.stringify(p.cw1155IntentPayment) : null,
134162
p.claimId,
135163
]);
136164

@@ -146,6 +174,15 @@ export const updateClaim = async (p: Claim): Promise<void> => {
146174
JSON.stringify(p.evaluation.amount),
147175
p.evaluation.evaluationDate,
148176
p.evaluation.claimId,
177+
p.evaluation.cw20Payment
178+
? JSON.stringify(p.evaluation.cw20Payment)
179+
: null,
180+
p.evaluation.cw1155Payment
181+
? JSON.stringify(p.evaluation.cw1155Payment)
182+
: null,
183+
p.evaluation.cw1155IntentPayment
184+
? JSON.stringify(p.evaluation.cw1155IntentPayment)
185+
: null,
149186
]);
150187
}
151188
};
@@ -161,11 +198,14 @@ export type Evaluation = {
161198
amount: any; // JSON
162199
evaluationDate: Date;
163200
claimId: string;
201+
cw20Payment?: any; // JSON
202+
cw1155Payment?: any; // JSON
203+
cw1155IntentPayment?: any; // JSON
164204
};
165205

166206
const upsertEvaluationSql = `
167-
INSERT INTO "public"."Evaluation" ( "collectionId", "oracle", "agentDid", "agentAddress", "status", "reason", "verificationProof", "amount", "evaluationDate", "claimId")
168-
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10 )
207+
INSERT INTO "public"."Evaluation" ( "collectionId", "oracle", "agentDid", "agentAddress", "status", "reason", "verificationProof", "amount", "evaluationDate", "claimId", "cw20Payment", "cw1155Payment", "cw1155IntentPayment")
208+
VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13 )
169209
ON CONFLICT("claimId") DO UPDATE SET
170210
"collectionId" = EXCLUDED."collectionId",
171211
"oracle" = EXCLUDED."oracle",
@@ -175,7 +215,10 @@ ON CONFLICT("claimId") DO UPDATE SET
175215
"reason" = EXCLUDED."reason",
176216
"verificationProof" = EXCLUDED."verificationProof",
177217
"amount" = EXCLUDED."amount",
178-
"evaluationDate" = EXCLUDED."evaluationDate"
218+
"evaluationDate" = EXCLUDED."evaluationDate",
219+
"cw20Payment" = EXCLUDED."cw20Payment",
220+
"cw1155Payment" = EXCLUDED."cw1155Payment",
221+
"cw1155IntentPayment" = EXCLUDED."cw1155IntentPayment"
179222
WHERE "Evaluation"."claimId" = EXCLUDED."claimId";
180223
`;
181224

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Up Migration
2+
-- Add new fields for claims module intents feature (added in later chain upgrade)
3+
4+
-- ClaimCollection: escrow account and intents option
5+
ALTER TABLE "ClaimCollection" ADD COLUMN "escrowAccount" TEXT;
6+
ALTER TABLE "ClaimCollection" ADD COLUMN "intents" INTEGER;
7+
8+
-- Claim: intent-related fields and custom payment amounts
9+
ALTER TABLE "Claim" ADD COLUMN "useIntent" BOOLEAN;
10+
ALTER TABLE "Claim" ADD COLUMN "amount" JSONB;
11+
ALTER TABLE "Claim" ADD COLUMN "cw20Payment" JSONB;
12+
ALTER TABLE "Claim" ADD COLUMN "cw1155Payment" JSONB;
13+
ALTER TABLE "Claim" ADD COLUMN "cw1155IntentPayment" JSONB;
14+
15+
-- Evaluation: custom payment amounts (amount already exists)
16+
ALTER TABLE "Evaluation" ADD COLUMN "cw20Payment" JSONB;
17+
ALTER TABLE "Evaluation" ADD COLUMN "cw1155Payment" JSONB;
18+
ALTER TABLE "Evaluation" ADD COLUMN "cw1155IntentPayment" JSONB;
19+
20+
-- Down Migration
21+
-- ALTER TABLE "Evaluation" DROP COLUMN "cw1155IntentPayment";
22+
-- ALTER TABLE "Evaluation" DROP COLUMN "cw1155Payment";
23+
-- ALTER TABLE "Evaluation" DROP COLUMN "cw20Payment";
24+
-- ALTER TABLE "Claim" DROP COLUMN "cw1155IntentPayment";
25+
-- ALTER TABLE "Claim" DROP COLUMN "cw1155Payment";
26+
-- ALTER TABLE "Claim" DROP COLUMN "cw20Payment";
27+
-- ALTER TABLE "Claim" DROP COLUMN "amount";
28+
-- ALTER TABLE "Claim" DROP COLUMN "useIntent";
29+
-- ALTER TABLE "ClaimCollection" DROP COLUMN "intents";
30+
-- ALTER TABLE "ClaimCollection" DROP COLUMN "escrowAccount";
31+

src/sync_handlers/event_data_sync.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { smartAccountAuthenticatorQuery } from "../util/archive-queries";
5353
import { queueBroadcast } from "../websocket/broadcast_queue";
5454

5555
export const syncEventData = async (event: EventCore, block: BlockCore) => {
56+
const blockHeight = block.height;
5657
try {
5758
switch (event.type) {
5859
// ==========================================================
@@ -175,6 +176,13 @@ export const syncEventData = async (event: EventCore, block: BlockCore) => {
175176
invalidated: Number(cCollection.invalidated ?? 0),
176177
state: ixo.claims.v1beta1.collectionStateFromJSON(cCollection.state),
177178
payments: cCollection.payments,
179+
escrowAccount: cCollection.escrow_account ?? undefined,
180+
intents:
181+
cCollection.intents != null
182+
? ixo.claims.v1beta1.collectionIntentOptionsFromJSON(
183+
cCollection.intents
184+
)
185+
: undefined,
178186
});
179187
break;
180188
case EventTypes.updateCollection:
@@ -198,6 +206,13 @@ export const syncEventData = async (event: EventCore, block: BlockCore) => {
198206
invalidated: Number(uCollection.invalidated ?? 0),
199207
state: ixo.claims.v1beta1.collectionStateFromJSON(uCollection.state),
200208
payments: uCollection.payments,
209+
escrowAccount: uCollection.escrow_account ?? undefined,
210+
intents:
211+
uCollection.intents != null
212+
? ixo.claims.v1beta1.collectionIntentOptionsFromJSON(
213+
uCollection.intents
214+
)
215+
: undefined,
201216
});
202217
break;
203218
case EventTypes.submitClaim:
@@ -212,6 +227,11 @@ export const syncEventData = async (event: EventCore, block: BlockCore) => {
212227
agentAddress: cClaim.agent_address,
213228
submissionDate: cClaim.submission_date as any,
214229
paymentsStatus: cClaim.payments_status,
230+
useIntent: cClaim.use_intent ?? undefined,
231+
amount: cClaim.amount?.length ? cClaim.amount : undefined,
232+
cw20Payment: cClaim.cw20_payment,
233+
cw1155Payment: cClaim.cw1155_payment,
234+
cw1155IntentPayment: cClaim.cw1155_intent_payment,
215235
});
216236
break;
217237
case EventTypes.updateClaim:
@@ -233,6 +253,9 @@ export const syncEventData = async (event: EventCore, block: BlockCore) => {
233253
evaluationDate: uClaim.evaluation!.evaluation_date as any,
234254
amount: uClaim.evaluation!.amount,
235255
claimId: uClaim.claim_id,
256+
cw20Payment: uClaim.evaluation?.cw20_payment,
257+
cw1155Payment: uClaim.evaluation?.cw1155_payment,
258+
cw1155IntentPayment: uClaim.evaluation?.cw1155_intent_payment,
236259
}
237260
: undefined;
238261
await updateClaim({
@@ -243,6 +266,11 @@ export const syncEventData = async (event: EventCore, block: BlockCore) => {
243266
submissionDate: uClaim.submission_date as any,
244267
paymentsStatus: uClaim.payments_status,
245268
evaluation,
269+
useIntent: uClaim.use_intent ?? undefined,
270+
amount: uClaim.amount?.length ? uClaim.amount : undefined,
271+
cw20Payment: uClaim.cw20_payment,
272+
cw1155Payment: uClaim.cw1155_payment,
273+
cw1155IntentPayment: uClaim.cw1155_intent_payment,
246274
});
247275
break;
248276
case EventTypes.disputeClaim:

0 commit comments

Comments
 (0)