@bsv/wallet-toolbox-mobile 2.3.2 → 2.3.3
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/out/src/monitor/Monitor.d.ts +3 -4
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js +1 -1
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/tasks/TaskArcSSE.d.ts +5 -3
- package/out/src/monitor/tasks/TaskArcSSE.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskArcSSE.js +42 -55
- package/out/src/monitor/tasks/TaskArcSSE.js.map +1 -1
- package/out/src/sdk/WalletServices.interfaces.d.ts +23 -1
- package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
- package/out/src/services/Services.d.ts +3 -0
- package/out/src/services/Services.d.ts.map +1 -1
- package/out/src/services/Services.js +20 -1
- package/out/src/services/Services.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts +2 -0
- package/out/src/services/chaintracker/chaintracks/Chaintracks.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Chaintracks.js +29 -1
- package/out/src/services/chaintracker/chaintracks/Chaintracks.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/GoChaintracksServiceClient.d.ts +52 -0
- package/out/src/services/chaintracker/chaintracks/GoChaintracksServiceClient.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/GoChaintracksServiceClient.js +228 -0
- package/out/src/services/chaintracker/chaintracks/GoChaintracksServiceClient.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorChaintracksSSE.d.ts +24 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorChaintracksSSE.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorChaintracksSSE.js +55 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorChaintracksSSE.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts +13 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +45 -7
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.mobile.d.ts +2 -0
- package/out/src/services/chaintracker/chaintracks/index.mobile.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.mobile.js +2 -0
- package/out/src/services/chaintracker/chaintracks/index.mobile.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts +8 -0
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js +53 -10
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.d.ts +19 -1
- package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.js +49 -2
- package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/out/src/services/providers/ARC.d.ts +4 -0
- package/out/src/services/providers/ARC.d.ts.map +1 -1
- package/out/src/services/providers/ARC.js +65 -4
- package/out/src/services/providers/ARC.js.map +1 -1
- package/out/src/services/providers/ArcSSEClient.d.ts +1 -0
- package/out/src/services/providers/ArcSSEClient.d.ts.map +1 -1
- package/out/src/services/providers/ArcSSEClient.js +12 -9
- package/out/src/services/providers/ArcSSEClient.js.map +1 -1
- package/out/src/services/providers/Arcade.d.ts +72 -0
- package/out/src/services/providers/Arcade.d.ts.map +1 -0
- package/out/src/services/providers/Arcade.js +299 -0
- package/out/src/services/providers/Arcade.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,12 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ARC = void 0;
|
|
4
|
+
exports.isArcAcceptedTxStatus = isArcAcceptedTxStatus;
|
|
5
|
+
exports.isArcDoubleSpendTxStatus = isArcDoubleSpendTxStatus;
|
|
6
|
+
exports.isArcInvalidTxStatus = isArcInvalidTxStatus;
|
|
7
|
+
exports.isArcServiceErrorStatus = isArcServiceErrorStatus;
|
|
4
8
|
const sdk_1 = require("@bsv/sdk");
|
|
5
9
|
const utilityHelpers_1 = require("../../utility/utilityHelpers");
|
|
6
10
|
const WalletError_1 = require("../../sdk/WalletError");
|
|
7
11
|
function defaultDeploymentId() {
|
|
8
12
|
return `ts-sdk-${sdk_1.Utils.toHex((0, sdk_1.Random)(16))}`;
|
|
9
13
|
}
|
|
14
|
+
const arcAcceptedTxStatuses = new Set([
|
|
15
|
+
'RECEIVED',
|
|
16
|
+
'SENT_TO_NETWORK',
|
|
17
|
+
'ANNOUNCED_TO_NETWORK',
|
|
18
|
+
'ACCEPTED_BY_NETWORK',
|
|
19
|
+
'SEEN_ON_NETWORK',
|
|
20
|
+
'STORED',
|
|
21
|
+
'MINED',
|
|
22
|
+
'IMMUTABLE'
|
|
23
|
+
]);
|
|
24
|
+
const arcDoubleSpendTxStatuses = new Set([
|
|
25
|
+
'DOUBLE_SPEND_ATTEMPTED',
|
|
26
|
+
'SEEN_IN_ORPHAN_MEMPOOL'
|
|
27
|
+
]);
|
|
28
|
+
const arcInvalidTxStatuses = new Set([
|
|
29
|
+
'INVALID',
|
|
30
|
+
'MALFORMED',
|
|
31
|
+
'REJECTED'
|
|
32
|
+
]);
|
|
33
|
+
function isArcAcceptedTxStatus(txStatus) {
|
|
34
|
+
return txStatus != null && arcAcceptedTxStatuses.has(txStatus);
|
|
35
|
+
}
|
|
36
|
+
function isArcDoubleSpendTxStatus(txStatus) {
|
|
37
|
+
return txStatus != null && arcDoubleSpendTxStatuses.has(txStatus);
|
|
38
|
+
}
|
|
39
|
+
function isArcInvalidTxStatus(txStatus) {
|
|
40
|
+
return txStatus != null && arcInvalidTxStatuses.has(txStatus);
|
|
41
|
+
}
|
|
42
|
+
function isArcServiceErrorStatus(status, detail) {
|
|
43
|
+
if (status == null)
|
|
44
|
+
return true;
|
|
45
|
+
if (status === 408 || status === 429 || status === 476 || status >= 500)
|
|
46
|
+
return true;
|
|
47
|
+
if (detail == null)
|
|
48
|
+
return false;
|
|
49
|
+
const d = detail.toLowerCase();
|
|
50
|
+
return d.includes('maximum batch size') ||
|
|
51
|
+
d.includes('too many requests') ||
|
|
52
|
+
d.includes('rate limit') ||
|
|
53
|
+
d.includes('timeout') ||
|
|
54
|
+
d.includes('temporarily') ||
|
|
55
|
+
d.includes('backpressure') ||
|
|
56
|
+
d.includes('unavailable');
|
|
57
|
+
}
|
|
10
58
|
/**
|
|
11
59
|
* Represents an ARC transaction broadcaster.
|
|
12
60
|
*/
|
|
@@ -113,7 +161,7 @@ class ARC {
|
|
|
113
161
|
if (r.txid !== txid)
|
|
114
162
|
r.data += ` txid altered from ${r.txid} to ${txid}`;
|
|
115
163
|
r.txid = txid;
|
|
116
|
-
if (txStatus
|
|
164
|
+
if (isArcDoubleSpendTxStatus(txStatus)) {
|
|
117
165
|
r.status = 'error';
|
|
118
166
|
r.doubleSpend = true;
|
|
119
167
|
r.competingTxs = competingTxs;
|
|
@@ -131,8 +179,6 @@ class ARC {
|
|
|
131
179
|
}
|
|
132
180
|
else {
|
|
133
181
|
r.status = 'error';
|
|
134
|
-
// Treat unknown errors as service errors
|
|
135
|
-
r.serviceError = true;
|
|
136
182
|
const n = {
|
|
137
183
|
...nn(),
|
|
138
184
|
...nne(),
|
|
@@ -142,9 +188,17 @@ class ARC {
|
|
|
142
188
|
const ed = {};
|
|
143
189
|
r.data = ed;
|
|
144
190
|
const st = typeof response.status;
|
|
191
|
+
let status;
|
|
145
192
|
if (st === 'number' || st === 'string') {
|
|
146
193
|
n.status = response.status;
|
|
147
194
|
ed.status = response.status.toString();
|
|
195
|
+
if (typeof response.status === 'number')
|
|
196
|
+
status = response.status;
|
|
197
|
+
else {
|
|
198
|
+
const parsed = Number(response.status);
|
|
199
|
+
if (Number.isFinite(parsed))
|
|
200
|
+
status = parsed;
|
|
201
|
+
}
|
|
148
202
|
}
|
|
149
203
|
else {
|
|
150
204
|
n.status = st;
|
|
@@ -163,6 +217,7 @@ class ARC {
|
|
|
163
217
|
n.detail = ed.detail;
|
|
164
218
|
}
|
|
165
219
|
}
|
|
220
|
+
r.serviceError = isArcServiceErrorStatus(status, ed.detail);
|
|
166
221
|
r.notes.push(n);
|
|
167
222
|
}
|
|
168
223
|
}
|
|
@@ -228,7 +283,7 @@ class ARC {
|
|
|
228
283
|
returnedTxid: dr.txid
|
|
229
284
|
});
|
|
230
285
|
}
|
|
231
|
-
else if (dr.txStatus
|
|
286
|
+
else if (isArcAcceptedTxStatus(dr.txStatus)) {
|
|
232
287
|
tr.data = dr.txStatus;
|
|
233
288
|
tr.notes.push({
|
|
234
289
|
...nn(),
|
|
@@ -240,6 +295,12 @@ class ARC {
|
|
|
240
295
|
else {
|
|
241
296
|
tr.status = 'error';
|
|
242
297
|
tr.data = dr;
|
|
298
|
+
tr.serviceError = !isArcInvalidTxStatus(dr.txStatus);
|
|
299
|
+
if (isArcDoubleSpendTxStatus(dr.txStatus)) {
|
|
300
|
+
tr.doubleSpend = true;
|
|
301
|
+
tr.competingTxs = dr.competingTxs ?? undefined;
|
|
302
|
+
tr.serviceError = undefined;
|
|
303
|
+
}
|
|
243
304
|
tr.notes.push({
|
|
244
305
|
...nn(),
|
|
245
306
|
what: 'postBeefGetTxDataError',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ARC.js","sourceRoot":"","sources":["../../../../../src/services/providers/ARC.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ARC.js","sourceRoot":"","sources":["../../../../../src/services/providers/ARC.ts"],"names":[],"mappings":";;;AA0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;IACV,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS,CAAE,IAAY;QAC3B,MAAM,cAAc,GAA6B;YAC/C,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE;SAC/B,CAAA;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAoB,GAAG,IAAI,CAAC,GAAG,UAAU,IAAI,EAAE,EAAE,cAAc,CAAC,CAAA;QAE9G,OAAO,QAAQ,CAAC,IAAI,CAAA;IACtB,CAAC;CACF;AAvSD,kBAuSC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcSSEClient.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/ArcSSEClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAA;IACf,6EAA6E;IAC7E,aAAa,EAAE,MAAM,CAAA;IACrB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;IACrC,4CAA4C;IAC5C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sEAAsE;IACtE,oBAAoB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAA;IACpD,6FAA6F;IAC7F,gBAAgB,EAAE,GAAG,CAAA;CACtB;AAED,qBAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"ArcSSEClient.d.ts","sourceRoot":"","sources":["../../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
18
18
|
_lastEventId;
|
|
19
19
|
es = null;
|
|
20
20
|
url;
|
|
21
|
+
displayUrl;
|
|
21
22
|
connected = false;
|
|
22
23
|
connecting = false;
|
|
23
24
|
constructor(options) {
|
|
@@ -28,6 +29,7 @@ class ArcSSEClient {
|
|
|
28
29
|
base = base.slice(0, -1);
|
|
29
30
|
}
|
|
30
31
|
this.url = `${base}/events?callbackToken=${encodeURIComponent(options.callbackToken)}`;
|
|
32
|
+
this.displayUrl = `${base}/events?callbackToken=<redacted>`;
|
|
31
33
|
}
|
|
32
34
|
get lastEventId() {
|
|
33
35
|
return this._lastEventId;
|
|
@@ -36,19 +38,19 @@ class ArcSSEClient {
|
|
|
36
38
|
* Open the SSE connection. Events will be dispatched via onEvent as they arrive.
|
|
37
39
|
*/
|
|
38
40
|
connect() {
|
|
39
|
-
if (this.es) {
|
|
41
|
+
if (this.es != null) {
|
|
40
42
|
console.log(`${TAG} already connected`);
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
45
|
this.connecting = true;
|
|
44
46
|
const ESClass = this.options.EventSourceClass;
|
|
45
47
|
const headers = {
|
|
46
|
-
'Last-Event-ID': this._lastEventId
|
|
48
|
+
'Last-Event-ID': this._lastEventId ?? '0'
|
|
47
49
|
};
|
|
48
|
-
if (this.options.arcApiKey) {
|
|
50
|
+
if (this.options.arcApiKey != null && this.options.arcApiKey !== '') {
|
|
49
51
|
headers.Authorization = `Bearer ${this.options.arcApiKey}`;
|
|
50
52
|
}
|
|
51
|
-
console.log(`${TAG} connecting to ${this.
|
|
53
|
+
console.log(`${TAG} connecting to ${this.displayUrl} (Last-Event-ID: ${headers['Last-Event-ID']})`);
|
|
52
54
|
this.es = new ESClass(this.url, {
|
|
53
55
|
headers,
|
|
54
56
|
debug: true,
|
|
@@ -63,7 +65,7 @@ class ArcSSEClient {
|
|
|
63
65
|
try {
|
|
64
66
|
const data = JSON.parse(event.data);
|
|
65
67
|
console.log(`${TAG} event: txid=${data.txid} status=${data.txStatus}`);
|
|
66
|
-
if (event.lastEventId) {
|
|
68
|
+
if (typeof event.lastEventId === 'string' && event.lastEventId !== '') {
|
|
67
69
|
this._lastEventId = event.lastEventId;
|
|
68
70
|
this.options.onLastEventIdChanged?.(event.lastEventId);
|
|
69
71
|
}
|
|
@@ -77,12 +79,13 @@ class ArcSSEClient {
|
|
|
77
79
|
console.log(`${TAG} error:`, JSON.stringify(event));
|
|
78
80
|
this.connected = false;
|
|
79
81
|
this.connecting = false;
|
|
80
|
-
|
|
82
|
+
const message = typeof event.message === 'string' && event.message !== '' ? event.message : 'SSE error';
|
|
83
|
+
this.options.onError?.(new Error(message));
|
|
81
84
|
});
|
|
82
85
|
}
|
|
83
86
|
/** Close the connection and clean up */
|
|
84
87
|
close() {
|
|
85
|
-
if (this.es) {
|
|
88
|
+
if (this.es != null) {
|
|
86
89
|
console.log(`${TAG} closing`);
|
|
87
90
|
this.es.close();
|
|
88
91
|
this.es = null;
|
|
@@ -96,10 +99,10 @@ class ArcSSEClient {
|
|
|
96
99
|
* Returns immediately — events arrive asynchronously via onEvent callback.
|
|
97
100
|
*/
|
|
98
101
|
async fetchEvents() {
|
|
99
|
-
if (
|
|
102
|
+
if (this.es == null && !this.connecting) {
|
|
100
103
|
this.connect();
|
|
101
104
|
}
|
|
102
|
-
else if (this.es && !this.connected && !this.connecting) {
|
|
105
|
+
else if (this.es != null && !this.connected && !this.connecting) {
|
|
103
106
|
// Connection exists but failed — reconnect
|
|
104
107
|
this.close();
|
|
105
108
|
this.connect();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArcSSEClient.js","sourceRoot":"","sources":["../../../../../src/services/providers/ArcSSEClient.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,MAAM,GAAG,GAAG,UAAU,CAAA;AA2BtB,MAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"ArcSSEClient.js","sourceRoot":"","sources":["../../../../../src/services/providers/ArcSSEClient.ts"],"names":[],"mappings":";A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IAAI,CAAC,OAAO,EAAE,CAAA;QAChB,CAAC;aAAM,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAClE,2CAA2C;YAC3C,IAAI,CAAC,KAAK,EAAE,CAAA;YACZ,IAAI,CAAC,OAAO,EAAE,CAAA;QAChB,CAAC;QACD,sFAAsF;QACtF,OAAO,CAAC,CAAA;IACV,CAAC;CACF;AA1GD,oCA0GC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Beef, HexString } from '@bsv/sdk';
|
|
2
|
+
import { GetMerklePathResult, PostBeefResult, PostTxResultForTxid, WalletServices } from '../../sdk/WalletServices.interfaces';
|
|
3
|
+
import { ArcConfig, ArcMinerGetTxData } from './ARC';
|
|
4
|
+
/**
|
|
5
|
+
* Broadcaster for bsv-blockchain/arcade — the Teranode-native, ARC-compatible broadcaster.
|
|
6
|
+
*
|
|
7
|
+
* Arcade is intentionally a separate, self-contained class (not a subclass of {@link ARC}) so
|
|
8
|
+
* the audited ARC transport is never altered. It is ARC-compatible on headers, configuration and
|
|
9
|
+
* the `getTxData` response shape — but differs where it must:
|
|
10
|
+
*
|
|
11
|
+
* - Endpoints are served at the root: `/tx` and `/tx/{txid}` (no `/v1` prefix).
|
|
12
|
+
* - A submit returns HTTP 202; HTTP 400 is a terminal validation failure (REJECTED) and is
|
|
13
|
+
* surfaced as an invalid-transaction status error rather than a transient service error.
|
|
14
|
+
* - Submission encoding is Extended Format (EF), not BEEF: Arcade's `/tx` parser rejects BEEF
|
|
15
|
+
* ("failed to parse transaction") and runs fee/script validation that needs per-input source
|
|
16
|
+
* data, which EF carries inline.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Arcade {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly URL: string;
|
|
21
|
+
readonly apiKey: string | undefined;
|
|
22
|
+
readonly deploymentId: string;
|
|
23
|
+
readonly callbackUrl: string | undefined;
|
|
24
|
+
readonly callbackToken: string | undefined;
|
|
25
|
+
readonly headers: Record<string, string> | undefined;
|
|
26
|
+
private readonly httpClient;
|
|
27
|
+
/**
|
|
28
|
+
* @param URL - The Arcade endpoint base URL.
|
|
29
|
+
* @param config - Arcade configuration (shares ARC's {@link ArcConfig} shape).
|
|
30
|
+
*/
|
|
31
|
+
constructor(URL: string, config?: ArcConfig, name?: string);
|
|
32
|
+
constructor(URL: string, apiKey?: string, name?: string);
|
|
33
|
+
/** Constructs a dictionary of the default & supplied request headers. */
|
|
34
|
+
private requestHeaders;
|
|
35
|
+
/**
|
|
36
|
+
* Submit a single transaction to Arcade's `POST /tx` endpoint.
|
|
37
|
+
*
|
|
38
|
+
* `rawTx` must be a single (raw or Extended Format) transaction hex — NOT BEEF. The canonical
|
|
39
|
+
* txid is taken from `txids` when supplied (Arcade derives the same txid from the parsed tx).
|
|
40
|
+
*/
|
|
41
|
+
postRawTx(rawTx: HexString, txids?: string[]): Promise<PostTxResultForTxid>;
|
|
42
|
+
/**
|
|
43
|
+
* Post each tx of interest as Extended Format (EF).
|
|
44
|
+
*
|
|
45
|
+
* EF needs each input's source output (satoshis + locking script). For a BEEF that carries every
|
|
46
|
+
* direct parent transaction in full (e.g. the atomic BEEF produced by createAction), that data is
|
|
47
|
+
* present and {@link Transaction.fromBEEF} can reconstruct EF. A BEEF is NOT guaranteed to contain
|
|
48
|
+
* it, however: BEEF V2 `txidOnly` entries (or an otherwise pruned BEEF) can reference a direct
|
|
49
|
+
* parent without its bytes, leaving no source output to embed — so BEEF -> EF is not always
|
|
50
|
+
* possible. When EF cannot be built for a txid, it is recorded as a (non-terminal) service error
|
|
51
|
+
* so cross-provider aggregation falls through to a BEEF-capable broadcaster, which can still
|
|
52
|
+
* broadcast the (valid) transaction.
|
|
53
|
+
*/
|
|
54
|
+
postBeef(beef: Beef, txids: string[]): Promise<PostBeefResult>;
|
|
55
|
+
/** Look up a transaction's current status (and merkle path once mined) via `GET /tx/{txid}`. */
|
|
56
|
+
getTxData(txid: string): Promise<ArcMinerGetTxData>;
|
|
57
|
+
/**
|
|
58
|
+
* `getMerklePath` provider: obtain a BUMP merkle proof for a mined transaction from Arcade.
|
|
59
|
+
*
|
|
60
|
+
* Arcade only has a proof for transactions it tracked (i.e. broadcast through it) that have
|
|
61
|
+
* been mined while tracked; for anything else `GET /tx/{txid}` reports a non-mined status (or
|
|
62
|
+
* 404) and this returns no `merklePath`, so {@link Services.getMerklePath} falls through to the
|
|
63
|
+
* other providers (WhatsOnChain/Bitails).
|
|
64
|
+
*
|
|
65
|
+
* The proof is NOT trusted blindly: the canonical block header is resolved from the wallet's
|
|
66
|
+
* own chaintracker via `services.hashToHeader(blockHash)` (which only knows real, mined blocks),
|
|
67
|
+
* and the BUMP's computed merkle root must equal that header's `merkleRoot`. Only then is the
|
|
68
|
+
* proof returned, with the canonical `header` that downstream proof completion requires.
|
|
69
|
+
*/
|
|
70
|
+
getMerklePath(txid: string, services: WalletServices): Promise<GetMerklePathResult>;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=Arcade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Arcade.d.ts","sourceRoot":"","sources":["../../../../../src/services/providers/Arcade.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAEJ,SAAS,EAOV,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EAEnB,cAAc,EACf,MAAM,qCAAqC,CAAA;AAM5C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAqD,MAAM,OAAO,CAAA;AAMvG;;;;;;;;;;;;;GAaG;AACH,qBAAa,MAAM;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IACxC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAA;IACpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC;;;OAGG;gBACU,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM;gBAC9C,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAsBxD,yEAAyE;IACzE,OAAO,CAAC,cAAc;IA2BtB;;;;;OAKG;IACG,SAAS,CAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgHlF;;;;;;;;;;;OAWG;IACG,QAAQ,CAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAmCrE,gGAAgG;IAC1F,SAAS,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAW1D;;;;;;;;;;;;OAYG;IACG,aAAa,CAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAkC3F"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Arcade = void 0;
|
|
4
|
+
const sdk_1 = require("@bsv/sdk");
|
|
5
|
+
const utilityHelpers_1 = require("../../utility/utilityHelpers");
|
|
6
|
+
const WalletError_1 = require("../../sdk/WalletError");
|
|
7
|
+
// Shared wire-contract types only (no behavior coupling): Arcade is ARC-compatible on the
|
|
8
|
+
// configuration and `getTxData` response shape, so it reuses those interfaces.
|
|
9
|
+
const ARC_1 = require("./ARC");
|
|
10
|
+
function defaultDeploymentId() {
|
|
11
|
+
return `ts-sdk-${sdk_1.Utils.toHex((0, sdk_1.Random)(16))}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Broadcaster for bsv-blockchain/arcade — the Teranode-native, ARC-compatible broadcaster.
|
|
15
|
+
*
|
|
16
|
+
* Arcade is intentionally a separate, self-contained class (not a subclass of {@link ARC}) so
|
|
17
|
+
* the audited ARC transport is never altered. It is ARC-compatible on headers, configuration and
|
|
18
|
+
* the `getTxData` response shape — but differs where it must:
|
|
19
|
+
*
|
|
20
|
+
* - Endpoints are served at the root: `/tx` and `/tx/{txid}` (no `/v1` prefix).
|
|
21
|
+
* - A submit returns HTTP 202; HTTP 400 is a terminal validation failure (REJECTED) and is
|
|
22
|
+
* surfaced as an invalid-transaction status error rather than a transient service error.
|
|
23
|
+
* - Submission encoding is Extended Format (EF), not BEEF: Arcade's `/tx` parser rejects BEEF
|
|
24
|
+
* ("failed to parse transaction") and runs fee/script validation that needs per-input source
|
|
25
|
+
* data, which EF carries inline.
|
|
26
|
+
*/
|
|
27
|
+
class Arcade {
|
|
28
|
+
name;
|
|
29
|
+
URL;
|
|
30
|
+
apiKey;
|
|
31
|
+
deploymentId;
|
|
32
|
+
callbackUrl;
|
|
33
|
+
callbackToken;
|
|
34
|
+
headers;
|
|
35
|
+
httpClient;
|
|
36
|
+
constructor(URL, config, name) {
|
|
37
|
+
this.name = name ?? 'arcade';
|
|
38
|
+
this.URL = URL;
|
|
39
|
+
if (typeof config === 'string') {
|
|
40
|
+
this.apiKey = config;
|
|
41
|
+
this.httpClient = (0, sdk_1.defaultHttpClient)();
|
|
42
|
+
this.deploymentId = defaultDeploymentId();
|
|
43
|
+
this.callbackToken = undefined;
|
|
44
|
+
this.callbackUrl = undefined;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const configObj = config ?? {};
|
|
48
|
+
const { apiKey, deploymentId, httpClient, callbackToken, callbackUrl, headers } = configObj;
|
|
49
|
+
this.apiKey = apiKey;
|
|
50
|
+
this.httpClient = httpClient ?? (0, sdk_1.defaultHttpClient)();
|
|
51
|
+
this.deploymentId = deploymentId ?? defaultDeploymentId();
|
|
52
|
+
this.callbackToken = callbackToken;
|
|
53
|
+
this.callbackUrl = callbackUrl;
|
|
54
|
+
this.headers = headers;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Constructs a dictionary of the default & supplied request headers. */
|
|
58
|
+
requestHeaders() {
|
|
59
|
+
const headers = {
|
|
60
|
+
'Content-Type': 'application/json',
|
|
61
|
+
'XDeployment-ID': this.deploymentId
|
|
62
|
+
};
|
|
63
|
+
if (this.apiKey != null && this.apiKey !== '') {
|
|
64
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
65
|
+
}
|
|
66
|
+
if (this.callbackUrl != null && this.callbackUrl !== '') {
|
|
67
|
+
headers['X-CallbackUrl'] = this.callbackUrl;
|
|
68
|
+
}
|
|
69
|
+
if (this.callbackToken != null && this.callbackToken !== '') {
|
|
70
|
+
headers['X-CallbackToken'] = this.callbackToken;
|
|
71
|
+
}
|
|
72
|
+
if (this.headers != null) {
|
|
73
|
+
for (const key in this.headers) {
|
|
74
|
+
headers[key] = this.headers[key];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return headers;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Submit a single transaction to Arcade's `POST /tx` endpoint.
|
|
81
|
+
*
|
|
82
|
+
* `rawTx` must be a single (raw or Extended Format) transaction hex — NOT BEEF. The canonical
|
|
83
|
+
* txid is taken from `txids` when supplied (Arcade derives the same txid from the parsed tx).
|
|
84
|
+
*/
|
|
85
|
+
async postRawTx(rawTx, txids) {
|
|
86
|
+
let txid = sdk_1.Utils.toHex((0, utilityHelpers_1.doubleSha256BE)(sdk_1.Utils.toArray(rawTx, 'hex')));
|
|
87
|
+
if (txids == null) {
|
|
88
|
+
txids = [txid];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
txid = txids.at(-1);
|
|
92
|
+
}
|
|
93
|
+
const requestOptions = {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: this.requestHeaders(),
|
|
96
|
+
data: { rawTx },
|
|
97
|
+
signal: AbortSignal.timeout(1000 * 30) // 30 seconds timeout, error.code will be 'ABORT_ERR'
|
|
98
|
+
};
|
|
99
|
+
const r = {
|
|
100
|
+
txid,
|
|
101
|
+
status: 'success',
|
|
102
|
+
notes: []
|
|
103
|
+
};
|
|
104
|
+
const url = `${this.URL}/tx`;
|
|
105
|
+
const nn = () => ({ name: this.name, when: new Date().toISOString() });
|
|
106
|
+
const nne = () => ({ ...nn(), rawTx, txids: txids.join(','), url });
|
|
107
|
+
try {
|
|
108
|
+
const response = await this.httpClient.request(url, requestOptions);
|
|
109
|
+
const { txid, extraInfo, txStatus, competingTxs } = response.data;
|
|
110
|
+
const nnr = () => ({
|
|
111
|
+
txid,
|
|
112
|
+
extraInfo,
|
|
113
|
+
txStatus,
|
|
114
|
+
competingTxs: competingTxs?.join(',')
|
|
115
|
+
});
|
|
116
|
+
if (response.ok) {
|
|
117
|
+
// Arcade's 202 submit response omits extraInfo; avoid a trailing 'undefined'.
|
|
118
|
+
r.data = extraInfo != null && extraInfo !== '' ? `${txStatus} ${extraInfo}` : `${txStatus}`;
|
|
119
|
+
if (r.txid !== txid)
|
|
120
|
+
r.data += ` txid altered from ${r.txid} to ${txid}`;
|
|
121
|
+
r.txid = txid;
|
|
122
|
+
if ((0, ARC_1.isArcDoubleSpendTxStatus)(txStatus)) {
|
|
123
|
+
r.status = 'error';
|
|
124
|
+
r.doubleSpend = true;
|
|
125
|
+
r.competingTxs = competingTxs;
|
|
126
|
+
r.notes.push({ ...nne(), ...nnr(), what: 'postRawTxDoubleSpend' });
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
r.notes.push({ ...nn(), ...nnr(), what: 'postRawTxSuccess' });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (typeof response === 'string') {
|
|
133
|
+
r.notes.push({ ...nne(), what: 'postRawTxString', response });
|
|
134
|
+
r.status = 'error';
|
|
135
|
+
// response is not normally a string
|
|
136
|
+
r.serviceError = true;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
r.status = 'error';
|
|
140
|
+
// Arcade returns HTTP 400 for terminal validation errors — surface those as
|
|
141
|
+
// invalid-transaction status errors while keeping rate limits, batch limits,
|
|
142
|
+
// 5xx/backpressure and unknown failures as service errors.
|
|
143
|
+
const n = {
|
|
144
|
+
...nn(),
|
|
145
|
+
...nne(),
|
|
146
|
+
...nnr(),
|
|
147
|
+
what: 'postRawTxError'
|
|
148
|
+
};
|
|
149
|
+
const ed = {};
|
|
150
|
+
r.data = ed;
|
|
151
|
+
const st = typeof response.status;
|
|
152
|
+
let status;
|
|
153
|
+
if (st === 'number' || st === 'string') {
|
|
154
|
+
n.status = response.status;
|
|
155
|
+
ed.status = response.status.toString();
|
|
156
|
+
if (typeof response.status === 'number')
|
|
157
|
+
status = response.status;
|
|
158
|
+
else {
|
|
159
|
+
const parsed = Number(response.status);
|
|
160
|
+
if (Number.isFinite(parsed))
|
|
161
|
+
status = parsed;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
n.status = st;
|
|
166
|
+
ed.status = 'ERR_UNKNOWN';
|
|
167
|
+
}
|
|
168
|
+
const d = response.data;
|
|
169
|
+
if (d && typeof d === 'string') {
|
|
170
|
+
n.data = response.data.slice(0, 128);
|
|
171
|
+
}
|
|
172
|
+
else if (d && typeof d === 'object') {
|
|
173
|
+
ed.more = d;
|
|
174
|
+
ed.detail = d.detail;
|
|
175
|
+
if (typeof ed.detail !== 'string')
|
|
176
|
+
ed.detail = undefined;
|
|
177
|
+
if (ed.detail) {
|
|
178
|
+
n.detail = ed.detail;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
r.serviceError = (0, ARC_1.isArcServiceErrorStatus)(status, ed.detail);
|
|
182
|
+
r.notes.push(n);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (error_) {
|
|
186
|
+
const e = WalletError_1.WalletError.fromUnknown(error_);
|
|
187
|
+
r.status = 'error';
|
|
188
|
+
r.serviceError = true;
|
|
189
|
+
r.data = `${e.code} ${e.message}`;
|
|
190
|
+
r.notes.push({
|
|
191
|
+
...nne(),
|
|
192
|
+
what: 'postRawTxCatch',
|
|
193
|
+
code: e.code,
|
|
194
|
+
description: e.description
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return r;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Post each tx of interest as Extended Format (EF).
|
|
201
|
+
*
|
|
202
|
+
* EF needs each input's source output (satoshis + locking script). For a BEEF that carries every
|
|
203
|
+
* direct parent transaction in full (e.g. the atomic BEEF produced by createAction), that data is
|
|
204
|
+
* present and {@link Transaction.fromBEEF} can reconstruct EF. A BEEF is NOT guaranteed to contain
|
|
205
|
+
* it, however: BEEF V2 `txidOnly` entries (or an otherwise pruned BEEF) can reference a direct
|
|
206
|
+
* parent without its bytes, leaving no source output to embed — so BEEF -> EF is not always
|
|
207
|
+
* possible. When EF cannot be built for a txid, it is recorded as a (non-terminal) service error
|
|
208
|
+
* so cross-provider aggregation falls through to a BEEF-capable broadcaster, which can still
|
|
209
|
+
* broadcast the (valid) transaction.
|
|
210
|
+
*/
|
|
211
|
+
async postBeef(beef, txids) {
|
|
212
|
+
const r = {
|
|
213
|
+
name: this.name,
|
|
214
|
+
status: 'success',
|
|
215
|
+
txidResults: [],
|
|
216
|
+
notes: []
|
|
217
|
+
};
|
|
218
|
+
const nn = () => ({ name: this.name, when: new Date().toISOString() });
|
|
219
|
+
const beefBin = beef.toBinary();
|
|
220
|
+
for (const txid of txids) {
|
|
221
|
+
let efHex;
|
|
222
|
+
try {
|
|
223
|
+
efHex = sdk_1.Transaction.fromBEEF(beefBin, txid).toHexEF();
|
|
224
|
+
}
|
|
225
|
+
catch (error_) {
|
|
226
|
+
const e = WalletError_1.WalletError.fromUnknown(error_);
|
|
227
|
+
r.status = 'error';
|
|
228
|
+
const tr = {
|
|
229
|
+
txid,
|
|
230
|
+
status: 'error',
|
|
231
|
+
serviceError: true,
|
|
232
|
+
notes: [{ ...nn(), what: 'arcadeEfBuildFailed', txid, code: e.code, description: e.description }]
|
|
233
|
+
};
|
|
234
|
+
r.txidResults.push(tr);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const prtr = await this.postRawTx(efHex, [txid]);
|
|
238
|
+
r.txidResults.push(prtr);
|
|
239
|
+
if (prtr.status === 'error')
|
|
240
|
+
r.status = 'error';
|
|
241
|
+
}
|
|
242
|
+
return r;
|
|
243
|
+
}
|
|
244
|
+
/** Look up a transaction's current status (and merkle path once mined) via `GET /tx/{txid}`. */
|
|
245
|
+
async getTxData(txid) {
|
|
246
|
+
const requestOptions = {
|
|
247
|
+
method: 'GET',
|
|
248
|
+
headers: this.requestHeaders()
|
|
249
|
+
};
|
|
250
|
+
const response = await this.httpClient.request(`${this.URL}/tx/${txid}`, requestOptions);
|
|
251
|
+
return response.data;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* `getMerklePath` provider: obtain a BUMP merkle proof for a mined transaction from Arcade.
|
|
255
|
+
*
|
|
256
|
+
* Arcade only has a proof for transactions it tracked (i.e. broadcast through it) that have
|
|
257
|
+
* been mined while tracked; for anything else `GET /tx/{txid}` reports a non-mined status (or
|
|
258
|
+
* 404) and this returns no `merklePath`, so {@link Services.getMerklePath} falls through to the
|
|
259
|
+
* other providers (WhatsOnChain/Bitails).
|
|
260
|
+
*
|
|
261
|
+
* The proof is NOT trusted blindly: the canonical block header is resolved from the wallet's
|
|
262
|
+
* own chaintracker via `services.hashToHeader(blockHash)` (which only knows real, mined blocks),
|
|
263
|
+
* and the BUMP's computed merkle root must equal that header's `merkleRoot`. Only then is the
|
|
264
|
+
* proof returned, with the canonical `header` that downstream proof completion requires.
|
|
265
|
+
*/
|
|
266
|
+
async getMerklePath(txid, services) {
|
|
267
|
+
const r = { name: this.name, notes: [] };
|
|
268
|
+
const nn = () => ({ name: this.name, when: new Date().toISOString() });
|
|
269
|
+
try {
|
|
270
|
+
const data = await this.getTxData(txid);
|
|
271
|
+
const mined = data.txStatus === 'MINED' || data.txStatus === 'IMMUTABLE';
|
|
272
|
+
if (!mined || data.merklePath == null || data.merklePath === '' || data.blockHash == null || data.blockHash === '') {
|
|
273
|
+
// No proof from Arcade yet (not mined / untracked / 404) — fall through to other providers.
|
|
274
|
+
r.notes.push({ ...nn(), what: 'getMerklePathArcadeNoProof', txid, txStatus: data.txStatus });
|
|
275
|
+
return r;
|
|
276
|
+
}
|
|
277
|
+
const merklePath = sdk_1.MerklePath.fromHex(data.merklePath);
|
|
278
|
+
// Resolve the canonical header from our own chaintracker; throws if the block is unknown.
|
|
279
|
+
const header = await services.hashToHeader(data.blockHash);
|
|
280
|
+
const computedRoot = merklePath.computeRoot(txid);
|
|
281
|
+
if (computedRoot !== header.merkleRoot) {
|
|
282
|
+
// Arcade's BUMP does not reconcile with the canonical block — reject and fall through.
|
|
283
|
+
r.notes.push({ ...nn(), what: 'getMerklePathArcadeRootMismatch', txid, computedRoot, headerRoot: header.merkleRoot, blockHash: data.blockHash });
|
|
284
|
+
return r;
|
|
285
|
+
}
|
|
286
|
+
r.merklePath = merklePath;
|
|
287
|
+
r.header = header;
|
|
288
|
+
r.notes.push({ ...nn(), what: 'getMerklePathArcadeSuccess', txid, height: header.height, blockHash: header.hash });
|
|
289
|
+
}
|
|
290
|
+
catch (error_) {
|
|
291
|
+
const e = WalletError_1.WalletError.fromUnknown(error_);
|
|
292
|
+
r.error = e;
|
|
293
|
+
r.notes.push({ ...nn(), what: 'getMerklePathArcadeError', txid, code: e.code, description: e.description });
|
|
294
|
+
}
|
|
295
|
+
return r;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.Arcade = Arcade;
|
|
299
|
+
//# sourceMappingURL=Arcade.js.map
|