mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-05 11:18:24 +00:00
Fix transactions failure if mint issues non-sats currency unit only.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "minibits_wallet",
|
||||
"version": "0.1.8-beta.23",
|
||||
"version": "0.1.8-beta.24",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"android:clean": "cd android && ./gradlew clean",
|
||||
|
||||
@@ -63,7 +63,7 @@ index 1491934..7852bd1 100644
|
||||
* Requests the mint to perform token minting after the LN invoice has been paid
|
||||
* @param mintUrl
|
||||
diff --git a/node_modules/@cashu/cashu-ts/src/CashuWallet.ts b/node_modules/@cashu/cashu-ts/src/CashuWallet.ts
|
||||
index 6d3a0b4..02ddb59 100644
|
||||
index 6d3a0b4..e4cd79b 100644
|
||||
--- a/node_modules/@cashu/cashu-ts/src/CashuWallet.ts
|
||||
+++ b/node_modules/@cashu/cashu-ts/src/CashuWallet.ts
|
||||
@@ -1,7 +1,7 @@
|
||||
@@ -96,7 +96,15 @@ index 6d3a0b4..02ddb59 100644
|
||||
import { validateMnemonic } from '@scure/bip39';
|
||||
import { wordlist } from '@scure/bip39/wordlists/english';
|
||||
import { createP2PKsecret, getSignedProofs } from '@cashu/crypto/modules/client/NUT11';
|
||||
@@ -113,6 +113,7 @@ class CashuWallet {
|
||||
@@ -106,6 +106,7 @@ class CashuWallet {
|
||||
async receive(
|
||||
token: string | Token,
|
||||
options?: {
|
||||
+ keysetId?: string;
|
||||
preference?: Array<AmountPreference>;
|
||||
counter?: number;
|
||||
pubkey?: string;
|
||||
@@ -113,6 +114,7 @@ class CashuWallet {
|
||||
}
|
||||
): Promise<ReceiveResponse> {
|
||||
let decodedToken: Array<TokenEntry>;
|
||||
@@ -104,12 +112,13 @@ index 6d3a0b4..02ddb59 100644
|
||||
if (typeof token === 'string') {
|
||||
decodedToken = cleanToken(getDecodedToken(token)).token;
|
||||
} else {
|
||||
@@ -125,25 +126,26 @@ class CashuWallet {
|
||||
@@ -125,25 +127,27 @@ class CashuWallet {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
- const { proofs, proofsWithError } = await this.receiveTokenEntry(tokenEntry, {
|
||||
+ const { proofs, proofsWithError, error } = await this.receiveTokenEntry(tokenEntry, {
|
||||
+ keysetId: options?.keysetId,
|
||||
preference: options?.preference,
|
||||
counter: options?.counter,
|
||||
pubkey: options?.pubkey,
|
||||
@@ -136,7 +145,15 @@ index 6d3a0b4..02ddb59 100644
|
||||
};
|
||||
}
|
||||
|
||||
@@ -167,6 +169,7 @@ class CashuWallet {
|
||||
@@ -159,6 +163,7 @@ class CashuWallet {
|
||||
async receiveTokenEntry(
|
||||
tokenEntry: TokenEntry,
|
||||
options?: {
|
||||
+ keysetId?: string;
|
||||
preference?: Array<AmountPreference>;
|
||||
counter?: number;
|
||||
pubkey?: string;
|
||||
@@ -167,13 +172,14 @@ class CashuWallet {
|
||||
): Promise<ReceiveTokenEntryResponse> {
|
||||
const proofsWithError: Array<Proof> = [];
|
||||
const proofs: Array<Proof> = [];
|
||||
@@ -144,7 +161,15 @@ index 6d3a0b4..02ddb59 100644
|
||||
try {
|
||||
const amount = tokenEntry.proofs.reduce((total, curr) => total + curr.amount, 0);
|
||||
let preference = options?.preference;
|
||||
@@ -192,12 +195,13 @@ class CashuWallet {
|
||||
if (!preference) {
|
||||
preference = getDefaultAmountPreference(amount);
|
||||
}
|
||||
- const keys = await this.getKeys();
|
||||
+ const keys = await this.getKeys(options?.keysetId);
|
||||
const { payload, blindedMessages } = this.createSplitPayload(
|
||||
amount,
|
||||
tokenEntry.proofs,
|
||||
@@ -192,12 +198,13 @@ class CashuWallet {
|
||||
);
|
||||
proofs.push(...newProofs);
|
||||
} catch (error) {
|
||||
@@ -160,7 +185,24 @@ index 6d3a0b4..02ddb59 100644
|
||||
};
|
||||
}
|
||||
|
||||
@@ -317,7 +321,7 @@ class CashuWallet {
|
||||
@@ -217,6 +224,7 @@ class CashuWallet {
|
||||
amount: number,
|
||||
proofs: Array<Proof>,
|
||||
options?: {
|
||||
+ keysetId?: string;
|
||||
preference?: Array<AmountPreference>;
|
||||
counter?: number;
|
||||
pubkey?: string;
|
||||
@@ -226,7 +234,7 @@ class CashuWallet {
|
||||
if (options?.preference) {
|
||||
amount = options?.preference?.reduce((acc, curr) => acc + curr.amount * curr.count, 0);
|
||||
}
|
||||
- const keyset = await this.getKeys();
|
||||
+ const keyset = await this.getKeys(options?.keysetId);
|
||||
let amountAvailable = 0;
|
||||
const proofsToSend: Array<Proof> = [];
|
||||
const proofsToKeep: Array<Proof> = [];
|
||||
@@ -317,7 +325,7 @@ class CashuWallet {
|
||||
/**
|
||||
* Initialize the wallet with the mints public keys
|
||||
*/
|
||||
@@ -169,7 +211,7 @@ index 6d3a0b4..02ddb59 100644
|
||||
if (!this._keys || this._keys.id !== keysetId) {
|
||||
const allKeys = await this.mint.getKeys(keysetId);
|
||||
let keys;
|
||||
@@ -564,7 +568,7 @@ class CashuWallet {
|
||||
@@ -564,7 +572,7 @@ class CashuWallet {
|
||||
* @param proofs (only the 'Y' field is required)
|
||||
* @returns
|
||||
*/
|
||||
@@ -178,7 +220,7 @@ index 6d3a0b4..02ddb59 100644
|
||||
const enc = new TextEncoder();
|
||||
const Ys = proofs.map((p) => dhke.hashToCurve(enc.encode(p.secret)).toHex(true));
|
||||
const payload = {
|
||||
@@ -573,10 +577,17 @@ class CashuWallet {
|
||||
@@ -573,11 +581,20 @@ class CashuWallet {
|
||||
};
|
||||
const { states } = await this.mint.check(payload);
|
||||
|
||||
@@ -195,8 +237,11 @@ index 6d3a0b4..02ddb59 100644
|
||||
+
|
||||
+ return {spent, pending}
|
||||
}
|
||||
+
|
||||
+
|
||||
private splitReceive(
|
||||
amount: number,
|
||||
amountAvailable: number
|
||||
diff --git a/node_modules/@cashu/cashu-ts/src/DHKE.ts b/node_modules/@cashu/cashu-ts/src/DHKE.ts
|
||||
index da1dfe6..99f60a2 100644
|
||||
--- a/node_modules/@cashu/cashu-ts/src/DHKE.ts
|
||||
|
||||
@@ -261,8 +261,9 @@ export const RemoteRecoveryScreen: FC<AppStackScreenProps<'RemoteRecovery'>> = o
|
||||
recoveredMint.increaseProofsCounter(selectedKeyset.id as string, Math.abs(endIndex - startIndex))
|
||||
|
||||
const {spent, pending} = await MintClient.getSpentOrPendingProofsFromMint(
|
||||
proofs as Proof[],
|
||||
recoveredMint.mintUrl,
|
||||
proofs as Proof[]
|
||||
selectedKeyset.unit as MintUnit,
|
||||
)
|
||||
|
||||
log.debug('[restore]', `Spent and pending proofs`, {spent: spent.length, pending: pending.length})
|
||||
|
||||
@@ -209,6 +209,7 @@ const receiveFromMint = async function (
|
||||
|
||||
// this method returns quite a mess, we normalize naming of returned parameters
|
||||
const {token, tokensWithErrors, errors} = await cashuWallet.receive(decodedToken, {
|
||||
keysetId: cashuWallet.keys.id,
|
||||
preference: amountPreferences,
|
||||
counter,
|
||||
pubkey: undefined,
|
||||
@@ -248,6 +249,7 @@ const sendFromMint = async function (
|
||||
amountToSend,
|
||||
proofsToSendFrom,
|
||||
{
|
||||
keysetId: cashuWallet.keys.id,
|
||||
preference: amountPreferences,
|
||||
counter,
|
||||
pubkey: undefined,
|
||||
@@ -302,13 +304,13 @@ const sendFromMint = async function (
|
||||
|
||||
|
||||
const getSpentOrPendingProofsFromMint = async function (
|
||||
mintUrl: string,
|
||||
// unit: MintUnit,
|
||||
proofs: Proof[],
|
||||
mintUrl: string,
|
||||
unit: MintUnit,
|
||||
) {
|
||||
try {
|
||||
// use default unit as check does not need it
|
||||
const cashuWallet = await getWallet(mintUrl, 'sat', {withSeed: true})
|
||||
|
||||
const cashuWallet = await getWallet(mintUrl, unit, {withSeed: true})
|
||||
|
||||
const spentPendingProofs = await cashuWallet.checkProofsSpent(proofs)
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ export const transferTask = async function (
|
||||
|
||||
// I have no idea yet if this can happen, unpaid call throws, return sent Proofs to the store an track tx as Reverted
|
||||
if (!isPaid) {
|
||||
const { amountPendingByMint } = await _moveProofsFromPending(proofsToPay, mintUrl, transactionId)
|
||||
const { amountPendingByMint } = await _moveProofsFromPending(proofsToPay, mintUrl, unit, transactionId)
|
||||
// release lock
|
||||
mintInstance.resetInFlight(transactionId)
|
||||
|
||||
@@ -244,7 +244,7 @@ export const transferTask = async function (
|
||||
const {
|
||||
amountToMove,
|
||||
amountPendingByMint
|
||||
} = await _moveProofsFromPending(proofsToPay, mintUrl, transactionId)
|
||||
} = await _moveProofsFromPending(proofsToPay, mintUrl, unit, transactionId)
|
||||
|
||||
// keep tx as pending if proofs were not added because of a mint that keeps them as pending for timed out in-flight payment
|
||||
if(amountPendingByMint > 0) {
|
||||
@@ -301,6 +301,7 @@ export const transferTask = async function (
|
||||
const _moveProofsFromPending = async function (
|
||||
proofsToMove: CashuProof[],
|
||||
mintUrl: string,
|
||||
unit: MintUnit,
|
||||
transactionId: number,
|
||||
): Promise<{
|
||||
amountToMove: number,
|
||||
@@ -321,8 +322,9 @@ const _moveProofsFromPending = async function (
|
||||
// due to the timeout but mint's node keeps the payment as in-flight (e.g. receiving node holds the invoice)
|
||||
// In this case we need to keep such proofs as pending and not move them back to wallet as in other payment failures.
|
||||
const {pending: pendingByMint} = await MintClient.getSpentOrPendingProofsFromMint(
|
||||
mintUrl,
|
||||
proofsToMove as Proof[],
|
||||
mintUrl,
|
||||
unit,
|
||||
)
|
||||
|
||||
let amountPendingByMint: number = 0
|
||||
|
||||
@@ -356,14 +356,15 @@ const _handleSpentByMintTask = async function (
|
||||
proofsCount: 0,
|
||||
proofsAmount: 0
|
||||
} as WalletTaskResult
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
spent: spentProofs,
|
||||
pending: pendingProofs
|
||||
} = await MintClient.getSpentOrPendingProofsFromMint(
|
||||
mintUrl,
|
||||
proofsFromMint,
|
||||
mintUrl,
|
||||
mint && mint.units ? mint.units[0] : 'sat'
|
||||
)
|
||||
|
||||
if(mint) {
|
||||
@@ -602,8 +603,9 @@ const _handleInFlightByMintTask = async function (mint: Mint, seed: Uint8Array):
|
||||
}
|
||||
|
||||
const {spent, pending} = await MintClient.getSpentOrPendingProofsFromMint(
|
||||
proofs as Proof[],
|
||||
mint.mintUrl,
|
||||
proofs as Proof[]
|
||||
mint.units ? mint.units[0] : 'sat'
|
||||
)
|
||||
|
||||
const spentCount = spent.length
|
||||
|
||||
Reference in New Issue
Block a user