Skip to content

Commit

Permalink
Add senderAddress and allow multiple recipients (#10)
Browse files Browse the repository at this point in the history
* Add senderAddress and allow multiple recipients

* Use Recipient in payload

* Use bigint type for amountSats
  • Loading branch information
Imamah-Zafar authored Jul 10, 2023
1 parent 138b2d8 commit 830800b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/transactions/sendBtcTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { createUnsecuredToken, Json } from 'jsontokens';
import { BitcoinNetwork, GetBitcoinProviderFunc, getDefaultProvider } from '../provider';

export interface Recipient {
address: string;
amountSats: bigint;
}

export interface SendBtcTransactionPayload {
network: BitcoinNetwork;
amountSats: string;
recipientAddress: string;
recipients: Recipient[]
senderAddress: string;
message?: string;
}

Expand All @@ -16,17 +21,18 @@ export interface SendBtcTransactionOptions {
}

export const sendBtcTransaction = async (options: SendBtcTransactionOptions) => {
const { recipients, senderAddress } = options.payload;
const { getProvider = getDefaultProvider } = options;
const provider = await getProvider();

if (!provider) {
throw new Error('No Bitcoin Wallet installed');
}
const { amountSats, recipientAddress } = options.payload;
if (!amountSats) {
throw new Error('a value for amount to be transferred is required');
if (!recipients) {
throw new Error('Recipient is required');
}
if (!recipientAddress) {
throw new Error('the recipient address is required');
if (!senderAddress) {
throw new Error('Sender address is required');
}
try {
const request = createUnsecuredToken(options.payload as unknown as Json);
Expand Down

0 comments on commit 830800b

Please sign in to comment.