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

add zeroFee flag in wallet.sendOffchain method #8

Merged
merged 7 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions src/core/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ export class Wallet implements IWallet {
return txid;
}

async sendOffchain(params: SendBitcoinParams): Promise<string> {
async sendOffchain(
params: SendBitcoinParams,
zeroFee: boolean = false
): Promise<string> {
if (
!this.arkProvider ||
!this.offchainAddress ||
Expand All @@ -260,10 +263,10 @@ export class Wallet implements IWallet {
}

const virtualCoins = await this.getVirtualCoins();
const feeRate = params.feeRate || Wallet.FEE_RATE;

// Ensure fee is an integer by rounding up
const estimatedFee = Math.ceil(174 * feeRate);
const estimatedFee = zeroFee
? 0
: Math.ceil(174 * (params.feeRate || Wallet.FEE_RATE));
const totalNeeded = params.amount + estimatedFee;

const selected = await selectVirtualCoins(virtualCoins, totalNeeded);
Expand Down
3 changes: 2 additions & 1 deletion src/types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export interface Wallet {
getVirtualCoins(): Promise<VirtualCoin[]>;
sendBitcoin(params: SendBitcoinParams): Promise<string>;
sendOnchain(params: SendBitcoinParams): Promise<string>;
sendOffchain(params: SendBitcoinParams): Promise<string>;
// TODO: remove zeroFee with transaction v3
sendOffchain(params: SendBitcoinParams, zeroFee?: boolean): Promise<string>;
signMessage(message: string): Promise<string>;
verifyMessage(
message: string,
Expand Down