@wopr-network/platform-core 1.35.2 → 1.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/billing/crypto/btc/watcher.d.ts +4 -1
- package/dist/billing/crypto/btc/watcher.js +16 -2
- package/dist/billing/crypto/unified-checkout.d.ts +2 -0
- package/dist/billing/crypto/unified-checkout.js +1 -1
- package/package.json +1 -1
- package/src/billing/crypto/btc/watcher.ts +20 -2
- package/src/billing/crypto/unified-checkout.ts +8 -1
|
@@ -24,7 +24,10 @@ export declare class BtcWatcher {
|
|
|
24
24
|
constructor(opts: BtcWatcherOpts);
|
|
25
25
|
/** Update the set of watched addresses. */
|
|
26
26
|
setWatchedAddresses(addresses: string[]): void;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Import an address into bitcoind's wallet (watch-only).
|
|
29
|
+
* Uses `importdescriptors` (modern bitcoind v24+) with fallback to legacy `importaddress`.
|
|
30
|
+
*/
|
|
28
31
|
importAddress(address: string): Promise<void>;
|
|
29
32
|
/** Poll for confirmed payments to watched addresses. */
|
|
30
33
|
poll(): Promise<void>;
|
|
@@ -21,9 +21,23 @@ export class BtcWatcher {
|
|
|
21
21
|
for (const a of addresses)
|
|
22
22
|
this.addresses.add(a);
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Import an address into bitcoind's wallet (watch-only).
|
|
26
|
+
* Uses `importdescriptors` (modern bitcoind v24+) with fallback to legacy `importaddress`.
|
|
27
|
+
*/
|
|
25
28
|
async importAddress(address) {
|
|
26
|
-
|
|
29
|
+
try {
|
|
30
|
+
// Modern bitcoind: get descriptor checksum, then import
|
|
31
|
+
const info = (await this.rpc("getdescriptorinfo", [`addr(${address})`]));
|
|
32
|
+
const result = (await this.rpc("importdescriptors", [[{ desc: info.descriptor, timestamp: 0 }]]));
|
|
33
|
+
if (result[0] && !result[0].success) {
|
|
34
|
+
throw new Error(result[0].error?.message ?? "importdescriptors failed");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Fallback: legacy importaddress (bitcoind <v24)
|
|
39
|
+
await this.rpc("importaddress", [address, "", false]);
|
|
40
|
+
}
|
|
27
41
|
this.addresses.add(address);
|
|
28
42
|
}
|
|
29
43
|
/** Poll for confirmed payments to watched addresses. */
|
|
@@ -7,6 +7,8 @@ export interface UnifiedCheckoutDeps {
|
|
|
7
7
|
oracle: IPriceOracle;
|
|
8
8
|
evmXpub: string;
|
|
9
9
|
btcXpub?: string;
|
|
10
|
+
/** UTXO network override (auto-detected from node in production). Default: "mainnet". */
|
|
11
|
+
utxoNetwork?: "mainnet" | "testnet" | "regtest";
|
|
10
12
|
}
|
|
11
13
|
export interface UnifiedCheckoutResult {
|
|
12
14
|
depositAddress: string;
|
|
@@ -77,7 +77,7 @@ async function handleNativeUtxo(deps, method, tenant, amountUsdCents, amountUsd)
|
|
|
77
77
|
depositAddress = deriveP2pkhAddress(xpub, derivationIndex, "dogecoin");
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
|
-
depositAddress = deriveAddress(xpub, derivationIndex, "mainnet", method.chain);
|
|
80
|
+
depositAddress = deriveAddress(xpub, derivationIndex, deps.utxoNetwork ?? "mainnet", method.chain);
|
|
81
81
|
}
|
|
82
82
|
const referenceId = `${method.token.toLowerCase()}:${depositAddress}`;
|
|
83
83
|
try {
|
package/package.json
CHANGED
|
@@ -48,9 +48,27 @@ export class BtcWatcher {
|
|
|
48
48
|
for (const a of addresses) this.addresses.add(a);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Import an address into bitcoind's wallet (watch-only).
|
|
53
|
+
* Uses `importdescriptors` (modern bitcoind v24+) with fallback to legacy `importaddress`.
|
|
54
|
+
*/
|
|
52
55
|
async importAddress(address: string): Promise<void> {
|
|
53
|
-
|
|
56
|
+
try {
|
|
57
|
+
// Modern bitcoind: get descriptor checksum, then import
|
|
58
|
+
const info = (await this.rpc("getdescriptorinfo", [`addr(${address})`])) as {
|
|
59
|
+
descriptor: string;
|
|
60
|
+
};
|
|
61
|
+
const result = (await this.rpc("importdescriptors", [[{ desc: info.descriptor, timestamp: 0 }]])) as Array<{
|
|
62
|
+
success: boolean;
|
|
63
|
+
error?: { message: string };
|
|
64
|
+
}>;
|
|
65
|
+
if (result[0] && !result[0].success) {
|
|
66
|
+
throw new Error(result[0].error?.message ?? "importdescriptors failed");
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
// Fallback: legacy importaddress (bitcoind <v24)
|
|
70
|
+
await this.rpc("importaddress", [address, "", false]);
|
|
71
|
+
}
|
|
54
72
|
this.addresses.add(address);
|
|
55
73
|
}
|
|
56
74
|
|
|
@@ -13,6 +13,8 @@ export interface UnifiedCheckoutDeps {
|
|
|
13
13
|
oracle: IPriceOracle;
|
|
14
14
|
evmXpub: string;
|
|
15
15
|
btcXpub?: string;
|
|
16
|
+
/** UTXO network override (auto-detected from node in production). Default: "mainnet". */
|
|
17
|
+
utxoNetwork?: "mainnet" | "testnet" | "regtest";
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export interface UnifiedCheckoutResult {
|
|
@@ -133,7 +135,12 @@ async function handleNativeUtxo(
|
|
|
133
135
|
if (method.chain === "dogecoin") {
|
|
134
136
|
depositAddress = deriveP2pkhAddress(xpub, derivationIndex, "dogecoin");
|
|
135
137
|
} else {
|
|
136
|
-
depositAddress = deriveAddress(
|
|
138
|
+
depositAddress = deriveAddress(
|
|
139
|
+
xpub,
|
|
140
|
+
derivationIndex,
|
|
141
|
+
deps.utxoNetwork ?? "mainnet",
|
|
142
|
+
method.chain as "bitcoin" | "litecoin",
|
|
143
|
+
);
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
const referenceId = `${method.token.toLowerCase()}:${depositAddress}`;
|