From 492df28c1cdf659b2014912c7b9ae260a1b41cce Mon Sep 17 00:00:00 2001 From: Zuhwa Date: Wed, 11 Feb 2026 17:03:05 +0800 Subject: [PATCH] Memo content --- src/acpClient.ts | 4 +++- src/acpJob.ts | 26 ++++++++++++++++++-------- src/interfaces.ts | 8 +++++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/acpClient.ts b/src/acpClient.ts index 4ce37d9..4f4790d 100644 --- a/src/acpClient.ts +++ b/src/acpClient.ts @@ -20,6 +20,7 @@ import { IAcpJob, IAcpMemoData, IAcpResponse, + IAcpMemoContent, } from "./interfaces"; import AcpError from "./acpError"; import { FareAmountBase } from "./acpFare"; @@ -374,6 +375,7 @@ class AcpClient { job.phase, job.context, job.contractAddress, + job.deliverable, job.netPayableAmount ); } catch (err) { @@ -745,7 +747,7 @@ class AcpClient { } async createMemoContent(jobId: number, content: string) { - const response = await this._fetch( + const response = await this._fetch( `/memo-contents`, "POST", {}, diff --git a/src/acpJob.ts b/src/acpJob.ts index adc4397..829de5e 100644 --- a/src/acpJob.ts +++ b/src/acpJob.ts @@ -37,6 +37,7 @@ class AcpJob { public phase: AcpJobPhases, public context: Record, public contractAddress: Address, + public deliverable: DeliverablePayload | null, public netPayableAmount?: number ) { const content = this.memos.find( @@ -90,11 +91,6 @@ class AcpJob { return this.acpContractClient.config.baseFare; } - public get deliverable() { - return this.memos.find((m) => m.nextPhase === AcpJobPhases.COMPLETED) - ?.content; - } - public get rejectionReason() { const requestMemo = this.memos.find( (m) => @@ -436,13 +432,22 @@ class AcpJob { } async deliver(deliverable: DeliverablePayload) { + if (this.phase !== AcpJobPhases.TRANSACTION) { + throw new AcpError("Job is not in transaction phase"); + } + const operations: OperationPayload[] = []; + const memoContent = await this.acpClient.createMemoContent( + this.id, + preparePayload(deliverable) + ); + operations.push( this.acpContractClient.createMemo( this.id, - preparePayload(deliverable), - MemoType.MESSAGE, + memoContent?.url, + MemoType.CONTEXT_URL, true, AcpJobPhases.COMPLETED ) @@ -480,10 +485,15 @@ class AcpJob { const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE && !skipFee; + const memoContent = await this.acpClient.createMemoContent( + this.id, + preparePayload(deliverable) + ); + operations.push( this.acpContractClient.createPayableMemo( this.id, - preparePayload(deliverable), + memoContent.url, amount.amount, this.clientAddress, isPercentagePricing diff --git a/src/interfaces.ts b/src/interfaces.ts index 71f4bc0..0ee95dd 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -20,7 +20,7 @@ export enum AcpMemoState { PENDING, IN_PROGRESS, FAILED, - COMPLETED + COMPLETED, } export interface PayableDetails { @@ -254,3 +254,9 @@ export type CheckTransactionConfig = { }; tag?: "pending"; }; + +export type IAcpMemoContent = { + id: number; + content: string; + url: string; +};