Skip to content

Commit

Permalink
Update checkProofsStates to return proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed Dec 10, 2024
1 parent 0a9d4fc commit 60df270
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
MintQuoteResponse,
MintQuoteState,
MeltQuoteState,
SerializedDLEQ
SerializedDLEQ,
CheckStateEnum
} from './model/types/index';
import {
bytesToNumber,
Expand Down Expand Up @@ -875,7 +876,10 @@ class CashuWallet {
* @param proofs (only the `secret` field is required)
* @returns
*/
async checkProofsStates(proofs: Array<Proof>): Promise<Array<ProofState>> {
async checkProofsStates(proofs: Array<Proof>): Promise<{
[CheckStateEnum: string]: Proof[]
}
> {
const enc = new TextEncoder();
const Ys = proofs.map((p: Proof) => hashToCurve(enc.encode(p.secret)).toHex(true));
// TODO: Replace this with a value from the info endpoint of the mint eventually
Expand All @@ -898,7 +902,15 @@ class CashuWallet {
states.push(state);
}
}
return states;

const proofsByState = {
SPENT: proofs.filter(p => states.some(s => s.Y === hashToCurve(enc.encode(p.secret)).toHex(true) && s.state === CheckStateEnum.SPENT)),
PENDING: proofs.filter(p => states.some(s => s.Y === hashToCurve(enc.encode(p.secret)).toHex(true) && s.state === CheckStateEnum.PENDING)),
UNSEPNT: proofs.filter(p => states.some(s => s.Y === hashToCurve(enc.encode(p.secret)).toHex(true) && s.state === CheckStateEnum.UNSPENT))
}

return proofsByState;

}

/**
Expand Down

0 comments on commit 60df270

Please sign in to comment.