Skip to content

Commit

Permalink
feature: add transparent -> spark address fund sending functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
narekpetrosyan committed Dec 23, 2024
1 parent 0d16daa commit e36e2d3
Show file tree
Hide file tree
Showing 8 changed files with 1,074 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/extension/src/libs/spark-handler/callRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const rpcURL = "https://firo-rpc.publicnode.com/";

export async function callRPC<T = any>(
method: string,
params = []
params?: object
): Promise<T> {
try {
const response = await axios.post(
Expand All @@ -13,7 +13,7 @@ export async function callRPC<T = any>(
jsonrpc: "1.0",
id: "js-client",
method: method,
params: params,
params: params ?? [],
},
{
headers: {
Expand Down
8 changes: 8 additions & 0 deletions packages/extension/src/libs/spark-handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export async function generateSparkAddress(): Promise<string> {
const newSparkAddress = await callRPC<string[]>("getnewsparkaddress");
return newSparkAddress[0];
}

export async function sendToSparkAddress(to: string, amount: string) {
return await callRPC<string[]>("mintspark", [
{
[to]: { amount: Number(amount) },
},
]);
}
8 changes: 8 additions & 0 deletions packages/extension/src/providers/bitcoin/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import BigNumber from 'bignumber.js';
import { BitcoinNetwork } from '../types/bitcoin-network';
import { BTCTxInfo } from '../ui/types';

export const isSparkAddress = (address = "") => {
if (address.length === 144 && address.startsWith("sm1")) {
// TODO: hack, change in future
return true;
}
return false;
};

const isAddress = (address: string, network: BitcoinNetworkInfo): boolean => {
try {
BTCAddress.toOutputScript(address, network);
Expand Down
Loading

0 comments on commit e36e2d3

Please sign in to comment.