@wopr-network/platform-core 1.36.0 → 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.
|
@@ -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. */
|
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
|
|