Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:add support for amountless in mintinfo and createMeltQuote #230

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,25 @@ class CashuWallet {
* @param invoice LN invoice that needs to get a fee estimate
* @returns the mint will create and return a melt quote for the invoice with an amount and fee reserve
*/
async createMeltQuote(invoice: string): Promise<MeltQuoteResponse> {
async createMeltQuote(invoice: string, amount?: number): Promise<MeltQuoteResponse> {
const meltQuotePayload: MeltQuotePayload = {
unit: this._unit,
request: invoice
};

if (this._mintInfo?.amountless) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only be adding the amount, if the caller explicitly passes amount. Otherwise this implementation defaults to 0 and mints that support this will throw an error if amount != invoiceAmount.

Also amount passed needs to be in msats

const meltQuotePayload: MeltQuotePayload = {
unit: this._unit,
request: invoice,
options: {
amountless: {
amount_msat: amount ?? 0
}
}
};
const meltQuote = await this.mint.createMeltQuote(meltQuotePayload);
return meltQuote;
}
const meltQuote = await this.mint.createMeltQuote(meltQuotePayload);
return meltQuote;
}
Expand Down
3 changes: 3 additions & 0 deletions src/model/MintInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,7 @@ export class MintInfo {
get motd() {
return this._mintInfo.motd;
}
get amountless() {
return this._mintInfo.amountless;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mint signals support via the MeltMethodOptions, not on the root level of the InfoReponse. Please check the PR again and make sure to adjust this accordingly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can't seem to find MeltMethodOptions , is this something that already exist or we have to create a new one for it @Egge21M

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is there, but it might need some refactoring for this PR. You can find it as GetInfoResponse.nuts.5.methods

}
}
1 change: 1 addition & 0 deletions src/model/types/mint/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type GetInfoResponse = {
};
};
motd?: string;
amountless?: boolean;
};

/**
Expand Down
17 changes: 17 additions & 0 deletions src/model/types/wallet/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ export type MeltQuotePayload = {
* Request to be melted to
*/
request: string;

options?: MeltQuotePayloadAmountLess;
};

/**
* Payload for a melt quote with an optional amountless option.
*/
export type MeltQuotePayloadAmountLess = {
/**
* Optional property for specifying an amountless option.
*/
amountless?: {
/**
* The amount in milli-satoshis.
*/
amount_msat: number;
};
};

/**
Expand Down
Loading