Skip to content

Commit e36e2d3

Browse files
feature: add transparent -> spark address fund sending functionality
1 parent 0d16daa commit e36e2d3

8 files changed

Lines changed: 1074 additions & 5 deletions

File tree

packages/extension/src/libs/spark-handler/callRPC.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const rpcURL = "https://firo-rpc.publicnode.com/";
44

55
export async function callRPC<T = any>(
66
method: string,
7-
params = []
7+
params?: object
88
): Promise<T> {
99
try {
1010
const response = await axios.post(
@@ -13,7 +13,7 @@ export async function callRPC<T = any>(
1313
jsonrpc: "1.0",
1414
id: "js-client",
1515
method: method,
16-
params: params,
16+
params: params ?? [],
1717
},
1818
{
1919
headers: {

packages/extension/src/libs/spark-handler/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ export async function generateSparkAddress(): Promise<string> {
1818
const newSparkAddress = await callRPC<string[]>("getnewsparkaddress");
1919
return newSparkAddress[0];
2020
}
21+
22+
export async function sendToSparkAddress(to: string, amount: string) {
23+
return await callRPC<string[]>("mintspark", [
24+
{
25+
[to]: { amount: Number(amount) },
26+
},
27+
]);
28+
}

packages/extension/src/providers/bitcoin/libs/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import BigNumber from 'bignumber.js';
66
import { BitcoinNetwork } from '../types/bitcoin-network';
77
import { BTCTxInfo } from '../ui/types';
88

9+
export const isSparkAddress = (address = "") => {
10+
if (address.length === 144 && address.startsWith("sm1")) {
11+
// TODO: hack, change in future
12+
return true;
13+
}
14+
return false;
15+
};
16+
917
const isAddress = (address: string, network: BitcoinNetworkInfo): boolean => {
1018
try {
1119
BTCAddress.toOutputScript(address, network);

0 commit comments

Comments
 (0)