mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-05 19:28:26 +00:00
removeMeltCounterValue impl
This commit is contained in:
Vendored
+1
-1
@@ -1 +1 @@
|
||||
019abb40-c0a1-7e6b-ace7-718e3894cbee
|
||||
019acc82-c83f-745c-b197-db89afcc5a30
|
||||
@@ -921,7 +921,7 @@ export const WalletStoreModel = types
|
||||
recoverMeltQuoteChange: flow(function* recoverMeltQuoteChange(
|
||||
mintUrl: string,
|
||||
meltQuote: MeltQuoteResponse,
|
||||
txId: number
|
||||
transactionId: number
|
||||
) {
|
||||
try {
|
||||
const mintInstance = self.getMintModelInstance(mintUrl)
|
||||
@@ -939,10 +939,10 @@ export const WalletStoreModel = types
|
||||
)
|
||||
|
||||
const currentCounter = mintInstance.getProofsCounterByKeysetId!(cashuWallet.keysetId)
|
||||
const counterValueForMelt = currentCounter.getMeltCounterValue(txId)?.counterAtMelt
|
||||
const counterValueForMelt = currentCounter.getMeltCounterValue(transactionId)?.counterAtMelt
|
||||
|
||||
if(counterValueForMelt === undefined) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'No melt counter value stored for provided transaction id', {mintUrl, txId})
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Change already claimed - counterAtMelt not available for this transaction', {mintUrl, transactionId})
|
||||
}
|
||||
|
||||
const {change}: MeltProofsResponse = yield cashuWallet.recoverMeltQuoteChange(
|
||||
@@ -952,6 +952,8 @@ export const WalletStoreModel = types
|
||||
counter: counterValueForMelt
|
||||
}
|
||||
)
|
||||
|
||||
currentCounter.removeMeltCounterValue(transactionId)
|
||||
|
||||
log.info('[recoverMeltQuoteChange]', {change})
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ export const transferTask = async function (
|
||||
totalFeePaid = totalFeePaid - returnedAmount
|
||||
lightningFeePaid = totalFeePaid - meltFeeReserve
|
||||
}
|
||||
|
||||
|
||||
const balanceAfter = proofsStore.getUnitBalance(unit)?.unitBalance
|
||||
|
||||
// build consolidated update payload
|
||||
@@ -338,33 +338,16 @@ export const transferTask = async function (
|
||||
message = `Lightning invoice has been successfully paid, however some error occured: ${e.message}`
|
||||
|
||||
taskResult.preimage = refreshedMeltQuote.payment_preimage
|
||||
taskResult.message = message
|
||||
taskResult.message = message
|
||||
|
||||
const change = await walletStore.recoverMeltQuoteChange(
|
||||
mintUrl as string,
|
||||
refreshedMeltQuote,
|
||||
transaction.id
|
||||
)
|
||||
|
||||
let recoveredChangeAmount = 0
|
||||
|
||||
if(change && change.length > 0) {
|
||||
|
||||
const {updatedAmount} = proofsStore.addOrUpdate(change,
|
||||
{
|
||||
mintUrl,
|
||||
tId: transaction.id,
|
||||
unit,
|
||||
isPending: false,
|
||||
isSpent: false
|
||||
}
|
||||
)
|
||||
|
||||
recoveredChangeAmount += updatedAmount
|
||||
}
|
||||
const {recoveredAmount} = await WalletTask.recoverMeltQuoteChange({
|
||||
mintUrl,
|
||||
meltQuote: refreshedMeltQuote,
|
||||
})
|
||||
|
||||
|
||||
log.error('[transfer]', message, {
|
||||
recoveredChangeAmount,
|
||||
recoveredAmount,
|
||||
error: e.message,
|
||||
refreshedMeltQuote,
|
||||
unit,
|
||||
|
||||
@@ -148,7 +148,7 @@ type WalletTaskService = {
|
||||
}) => Promise<{recoveredAmount: number}>
|
||||
recoverMeltQuoteChange: (params: {
|
||||
mintUrl: string,
|
||||
meltQuote: string
|
||||
meltQuote: string | MeltQuoteResponse
|
||||
}) => Promise<{recoveredAmount: number}>
|
||||
}
|
||||
|
||||
@@ -1608,7 +1608,7 @@ const recoverMintQuote = async (
|
||||
const recoverMeltQuoteChange = async (
|
||||
params: {
|
||||
mintUrl: string
|
||||
meltQuote: string
|
||||
meltQuote: string | MeltQuoteResponse
|
||||
}
|
||||
): Promise<{ recoveredAmount: number }> => {
|
||||
const { mintUrl, meltQuote } = params
|
||||
@@ -1620,14 +1620,14 @@ const recoverMintQuote = async (
|
||||
}
|
||||
|
||||
log.trace('[recoverMeltQuoteChange] start', { mintUrl, meltQuote })
|
||||
|
||||
const response = await walletStore.checkLightningMeltQuote(mintUrl, meltQuote)
|
||||
const { quote, state, change, amount } = response
|
||||
|
||||
if (quote !== meltQuote) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Mint returned mismatched melt quote', { meltQuote, returned: quote })
|
||||
}
|
||||
|
||||
|
||||
const meltQuoteResponse: MeltQuoteResponse =
|
||||
typeof meltQuote === 'string'
|
||||
? await walletStore.checkLightningMeltQuote(mintUrl, meltQuote)
|
||||
: meltQuote
|
||||
|
||||
const { quote, state, change } = meltQuoteResponse
|
||||
|
||||
switch (state) {
|
||||
case MeltQuoteState.UNPAID:
|
||||
throw new AppError(Err.VALIDATION_ERROR, `Melt quote ${meltQuote} was not paid`)
|
||||
@@ -1640,7 +1640,7 @@ const recoverMintQuote = async (
|
||||
throw new AppError(Err.VALIDATION_ERROR, `No change available for melt quote ${meltQuote}`)
|
||||
}
|
||||
|
||||
let tx = transactionsStore.findLastBy({ quote: meltQuote })
|
||||
let tx = transactionsStore.findLastBy({ quote })
|
||||
|
||||
if (!tx) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'Original melt transaction not found', { meltQuote })
|
||||
@@ -1650,7 +1650,7 @@ const recoverMintQuote = async (
|
||||
|
||||
try {
|
||||
// Recover blind signatures requires original counter value to produce valid proofs
|
||||
const change = await walletStore.recoverMeltQuoteChange(mintUrl, response, tx.id)
|
||||
const change = await walletStore.recoverMeltQuoteChange(mintUrl, meltQuoteResponse, tx.id)
|
||||
|
||||
// Make sure we do not recover already received change
|
||||
const newChange = change.filter(proof => !proofsStore.alreadyExists(proof))
|
||||
|
||||
Reference in New Issue
Block a user