Skip to content

Commit 687166d

Browse files
committed
chore: rebuild dark-forest SDK with on-chain recordPayment
1 parent a123d04 commit 687166d

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

dark-forest/dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export declare class DarkForestPayments {
9393
verifyTeeAttestation(escrowId: number, attestationReport: Buffer, teePubkey: number[], signatureInstruction?: TransactionInstruction): Promise<string>;
9494
recordSettlement(escrowId: number, totalPaidSol: number): Promise<string>;
9595
startPrivateSession(escrowId: number, jobPubkey: PublicKey, config: MppSessionConfig): Promise<MppSessionState>;
96-
recordPayment(escrowId: number, amountLamports: number): Promise<void>;
96+
recordPayment(escrowId: number, amountLamports: number): Promise<string>;
9797
closeSession(escrowId: number): Promise<string>;
9898
getActiveSession(escrowId: number): Promise<MppSessionState | undefined>;
9999
getEscrow(escrowId: number): Promise<EscrowState | null>;

dark-forest/dist/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,22 @@ class DarkForestPayments {
184184
const session = await this.sessionStore.get(escrowId);
185185
if (!session || !session.isActive)
186186
throw new Error('No active session for this escrow');
187+
const [escrowPda] = deriveEscrowPda(escrowId);
188+
// On-chain enforced metering — budget check + caller auth happens on-chain
189+
const tx = await this.program.methods
190+
.recordPayment(new anchor_1.BN(escrowId), new anchor_1.BN(amountLamports))
191+
.accounts({
192+
escrow: escrowPda,
193+
caller: this.provider.wallet.publicKey,
194+
})
195+
.rpc();
196+
// Update local session store for fast reads
187197
await this.sessionStore.set({
188198
...session,
189199
totalPaid: session.totalPaid + amountLamports,
190200
requestCount: session.requestCount + 1,
191201
});
202+
return tx;
192203
}
193204
async closeSession(escrowId) {
194205
const session = await this.sessionStore.get(escrowId);

0 commit comments

Comments
 (0)