Skip to content

Commit

Permalink
feat: implement sendToAddress for mm-snap
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
gregdhill committed Sep 5, 2024
1 parent 9a13153 commit 93dd54d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
15 changes: 9 additions & 6 deletions packages/sats-wagmi/src/connectors/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ abstract class SatsConnector {
* const txId = await connector.sendToAddress(toAddress, amount);
* ```
*/
abstract sendToAddress(toAddress: string, amount: number): Promise<string>;
async sendToAddress(toAddress: string, amount: number): Promise<string> {
const esploraClient = this.esploraClient;
const signedTx = await this.createAndSignTx(toAddress, amount);
const txId = await esploraClient.broadcastTx(signedTx);

return txId;
}

/** Send BTC to an address with data in an OP_RETURN output
* @param toAddress - The address to send BTC to. Can be any valid BTC address.
Expand All @@ -232,9 +238,7 @@ abstract class SatsConnector {
*/
async sendToAddressWithOpReturn(toAddress: string, amount: number, data: string): Promise<string> {
const esploraClient = this.esploraClient;

const signedTx = await this.createTxWithOpReturn(toAddress, amount, data);

const signedTx = await this.createAndSignTx(toAddress, amount, data);
const txId = await esploraClient.broadcastTx(signedTx);

return txId;
Expand All @@ -254,9 +258,8 @@ abstract class SatsConnector {
* const signedTx = await connector.createTxWithOpReturn(toAddress, amount, data);
* ```
*/
async createTxWithOpReturn(toAddress: string, amount: number, data: string): Promise<string> {
async createAndSignTx(toAddress: string, amount: number, data?: string): Promise<string> {
this.validatePaymentAddress();

const psbtBase64 = await createBitcoinPsbt(this.paymentAddress, toAddress, amount, this.publicKey, data);

return this.signAllInputs(psbtBase64);
Expand Down
5 changes: 0 additions & 5 deletions packages/sats-wagmi/src/connectors/mm-snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,6 @@ class MMSnapConnector extends SatsConnector {
throw new Error('Not implemented');
}

// FIXME: Refactor using btc-signer
sendToAddress(): Promise<string> {
throw new Error('Method not implemented.');
}

async signInput(inputIndex: number, psbt: Psbt) {
try {
const psbtBase64 = await ethereum.request({
Expand Down
5 changes: 0 additions & 5 deletions playgrounds/vite-react/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Buffer } from 'buffer';

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import React from 'react';
Expand All @@ -8,9 +6,6 @@ import { Network, SatsWagmiConfig } from '@gobob/sats-wagmi';

import './index.css';

// `@coinbase-wallet/sdk` uses `Buffer`
globalThis.Buffer = Buffer;

import App from './App.tsx';

const queryClient = new QueryClient({
Expand Down

0 comments on commit 93dd54d

Please sign in to comment.