Skip to content

Commit

Permalink
feat(psbt): allow custom fee rate in createPsbt (#27)
Browse files Browse the repository at this point in the history
* Accept custom satsPerByte fee rate

* Update send example
  • Loading branch information
jordankzf authored Jul 26, 2023
1 parent c64d4e2 commit d37bc74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/node/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ordit } from "@sadoprotocol/ordit-sdk"; //import Ordit
async function main() {
// Replace accordingly
const psbtTemplate = {
satsPerByte: 1,
format: "p2wpkh",
network: "testnet",
pubKey: "02950611fedb407d34cc845101f2bdfb2e7e3ec075e1424015bbf2db75c8ebe696",
Expand Down
13 changes: 11 additions & 2 deletions packages/sdk/src/transactions/psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import { Network, Psbt } from "bitcoinjs-lib";
import { createTransaction, getNetwork } from "../utils";
import { GetWalletOptions, getWalletWithBalances } from "../wallet";

export async function createPsbt({ network, format, pubKey, ins, outs, safeMode = "on" }: CreatePsbtOptions) {
export async function createPsbt({
network,
format,
pubKey,
ins,
outs,
safeMode = "on",
satsPerByte
}: CreatePsbtOptions) {
const netWorkObj = getNetwork(network);
const bip32 = BIP32Factory(ecc);

Expand All @@ -26,7 +34,7 @@ export async function createPsbt({ network, format, pubKey, ins, outs, safeMode
let change = 0;
const dust = 600;
let inputs_used = 0;
const sats_per_byte = 10;
const sats_per_byte = satsPerByte ?? 10;
let total_cardinals_to_send = 0;
let total_cardinals_available = 0;
const unsupported_inputs = [];
Expand Down Expand Up @@ -195,6 +203,7 @@ function addInputToPsbtByType(spendable: any, type: string, psbt: Psbt, bip32: B
}

export type CreatePsbtOptions = GetWalletOptions & {
satsPerByte?: number;
ins: any[];
outs: any[];
};

0 comments on commit d37bc74

Please sign in to comment.