@1sat/wallet-toolbox 0.0.2 → 0.0.4
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/OneSatWallet.d.ts +97 -70
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3430 -405
- package/dist/indexers/types.d.ts +4 -0
- package/dist/services/OneSatServices.d.ts +7 -7
- package/dist/services/client/ArcadeClient.d.ts +1 -1
- package/dist/services/client/BeefClient.d.ts +1 -1
- package/dist/services/client/Bsv21Client.d.ts +1 -1
- package/dist/services/client/ChaintracksClient.d.ts +1 -1
- package/dist/services/client/OrdfsClient.d.ts +29 -14
- package/dist/services/client/OwnerClient.d.ts +5 -22
- package/dist/services/client/TxoClient.d.ts +8 -13
- package/dist/services/types.d.ts +50 -23
- package/dist/sync/IndexedDbSyncQueue.d.ts +30 -0
- package/dist/sync/SqliteSyncQueue.d.ts +54 -0
- package/dist/sync/index.d.ts +3 -0
- package/dist/sync/types.d.ts +129 -0
- package/package.json +1 -1
package/dist/indexers/types.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export interface Bsv21TransactionData {
|
|
|
42
42
|
export interface IndexData {
|
|
43
43
|
data: unknown;
|
|
44
44
|
tags: string[];
|
|
45
|
+
/** Optional text content (e.g., from text inscriptions). */
|
|
46
|
+
content?: string;
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* IndexSummary contains transaction-level summary information
|
|
@@ -60,6 +62,8 @@ export interface ParseResult {
|
|
|
60
62
|
tags: string[];
|
|
61
63
|
owner?: string;
|
|
62
64
|
basket?: string;
|
|
65
|
+
/** Optional text content (e.g., from text inscriptions). Truncated to 1000 chars when stored. */
|
|
66
|
+
content?: string;
|
|
63
67
|
}
|
|
64
68
|
/**
|
|
65
69
|
* Transaction output structure used during parsing
|
|
@@ -13,13 +13,13 @@ export type { SyncOutput };
|
|
|
13
13
|
* interface required by wallet-toolbox.
|
|
14
14
|
*
|
|
15
15
|
* API Routes:
|
|
16
|
-
* - /
|
|
17
|
-
* - /
|
|
18
|
-
* - /
|
|
19
|
-
* - /
|
|
20
|
-
* - /
|
|
21
|
-
* - /
|
|
22
|
-
* - /
|
|
16
|
+
* - /1sat/chaintracks/* - Block headers and chain tracking
|
|
17
|
+
* - /1sat/beef/* - Raw transactions and proofs
|
|
18
|
+
* - /1sat/arcade/* - Transaction broadcasting
|
|
19
|
+
* - /1sat/bsv21/* - BSV21 token data
|
|
20
|
+
* - /1sat/txo/* - Transaction outputs
|
|
21
|
+
* - /1sat/owner/* - Address queries and sync
|
|
22
|
+
* - /1sat/ordfs/* - Content/inscription serving
|
|
23
23
|
*/
|
|
24
24
|
export declare class OneSatServices implements WalletServices {
|
|
25
25
|
chain: Chain;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ClientOptions, Policy, SubmitOptions, TransactionStatus } from "../types";
|
|
2
2
|
import { BaseClient } from "./BaseClient";
|
|
3
3
|
/**
|
|
4
|
-
* Client for /
|
|
4
|
+
* Client for /1sat/arcade/* routes.
|
|
5
5
|
* Provides transaction broadcast and status checking.
|
|
6
6
|
*
|
|
7
7
|
* Routes:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Bsv21TokenDetails, Bsv21TransactionData, ClientOptions, IndexedOutput } from "../types";
|
|
2
2
|
import { BaseClient } from "./BaseClient";
|
|
3
3
|
/**
|
|
4
|
-
* Client for /
|
|
4
|
+
* Client for /1sat/bsv21/* routes.
|
|
5
5
|
* Provides BSV21 token queries.
|
|
6
6
|
*
|
|
7
7
|
* Routes:
|
|
@@ -2,7 +2,7 @@ import type { ChainTracker } from "@bsv/sdk";
|
|
|
2
2
|
import type { BlockHeader, ClientOptions } from "../types";
|
|
3
3
|
import { BaseClient } from "./BaseClient";
|
|
4
4
|
/**
|
|
5
|
-
* Client for /
|
|
5
|
+
* Client for /1sat/chaintracks/* routes.
|
|
6
6
|
* Provides block header data and implements ChainTracker interface.
|
|
7
7
|
*
|
|
8
8
|
* Routes:
|
|
@@ -1,32 +1,47 @@
|
|
|
1
|
-
import type { ClientOptions, OrdfsMetadata } from "../types";
|
|
1
|
+
import type { ClientOptions, OrdfsContentOptions, OrdfsContentResponse, OrdfsMetadata } from "../types";
|
|
2
2
|
import { BaseClient } from "./BaseClient";
|
|
3
3
|
/**
|
|
4
4
|
* Client for ordfs routes.
|
|
5
5
|
* Provides inscription content and metadata.
|
|
6
6
|
*
|
|
7
|
-
* Content is served from
|
|
8
|
-
* API routes use /
|
|
7
|
+
* Content is served from /1sat/content (e.g., https://api.1sat.app/1sat/content/:outpoint)
|
|
8
|
+
* API routes use /1sat/ordfs (e.g., https://api.1sat.app/1sat/ordfs/metadata/:outpoint)
|
|
9
9
|
*/
|
|
10
10
|
export declare class OrdfsClient extends BaseClient {
|
|
11
|
+
private readonly contentBaseUrl;
|
|
11
12
|
constructor(baseUrl: string, options?: ClientOptions);
|
|
12
13
|
/**
|
|
13
14
|
* Get metadata for an inscription
|
|
15
|
+
* @param outpoint - Outpoint (txid_vout) or txid
|
|
16
|
+
* @param seq - Optional sequence number (-1 for latest)
|
|
14
17
|
*/
|
|
15
|
-
getMetadata(outpoint: string): Promise<OrdfsMetadata>;
|
|
18
|
+
getMetadata(outpoint: string, seq?: number): Promise<OrdfsMetadata>;
|
|
16
19
|
/**
|
|
17
|
-
* Get inscription content
|
|
20
|
+
* Get inscription content with full response headers
|
|
21
|
+
* @param outpoint - Outpoint (txid_vout) or txid
|
|
22
|
+
* @param options - Content request options
|
|
18
23
|
*/
|
|
19
|
-
getContent(outpoint: string): Promise<
|
|
24
|
+
getContent(outpoint: string, options?: OrdfsContentOptions): Promise<OrdfsContentResponse>;
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
26
|
+
* Preview base64-encoded HTML content
|
|
27
|
+
* @param b64HtmlData - Base64-encoded HTML
|
|
22
28
|
*/
|
|
23
|
-
|
|
24
|
-
data: Uint8Array;
|
|
25
|
-
contentType: string;
|
|
26
|
-
}>;
|
|
29
|
+
previewHtml(b64HtmlData: string): Promise<string>;
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
31
|
+
* Preview content by posting it directly
|
|
32
|
+
* @param content - Content to preview
|
|
33
|
+
* @param contentType - Content type header
|
|
30
34
|
*/
|
|
31
|
-
|
|
35
|
+
previewContent(content: Uint8Array, contentType: string): Promise<Uint8Array>;
|
|
36
|
+
/**
|
|
37
|
+
* Get the URL for fetching inscription content directly.
|
|
38
|
+
* Useful for displaying in img/video tags.
|
|
39
|
+
* @param outpoint - Outpoint (txid_vout) or txid
|
|
40
|
+
* @param options - Content request options
|
|
41
|
+
*/
|
|
42
|
+
getContentUrl(outpoint: string, options?: OrdfsContentOptions): string;
|
|
43
|
+
/**
|
|
44
|
+
* Parse response headers into structured object
|
|
45
|
+
*/
|
|
46
|
+
private parseResponseHeaders;
|
|
32
47
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { BalanceResponse, ClientOptions, IndexedOutput, SyncOutput, TxoQueryOptions } from "../types";
|
|
2
2
|
import { BaseClient } from "./BaseClient";
|
|
3
3
|
/**
|
|
4
|
-
* Client for /
|
|
4
|
+
* Client for /1sat/owner/* routes.
|
|
5
5
|
* Provides owner (address) queries and sync.
|
|
6
6
|
*
|
|
7
7
|
* Routes:
|
|
8
8
|
* - GET /:owner/txos - Get TXOs for owner
|
|
9
9
|
* - GET /:owner/balance - Get balance
|
|
10
|
-
* - GET
|
|
10
|
+
* - GET /sync?owner=... - SSE stream of outputs for sync (supports multiple owners)
|
|
11
11
|
*/
|
|
12
12
|
export declare class OwnerClient extends BaseClient {
|
|
13
13
|
constructor(baseUrl: string, options?: ClientOptions);
|
|
@@ -22,19 +22,7 @@ export declare class OwnerClient extends BaseClient {
|
|
|
22
22
|
*/
|
|
23
23
|
getBalance(owner: string): Promise<BalanceResponse>;
|
|
24
24
|
/**
|
|
25
|
-
* Sync outputs for
|
|
26
|
-
* Returns an EventSource that emits SyncOutput events.
|
|
27
|
-
*
|
|
28
|
-
* @param owner - Address/owner to sync
|
|
29
|
-
* @param onOutput - Callback for each output
|
|
30
|
-
* @param from - Starting score (for pagination/resumption)
|
|
31
|
-
* @param onDone - Callback when sync completes (client should retry after delay)
|
|
32
|
-
* @param onError - Callback for errors
|
|
33
|
-
* @returns Unsubscribe function
|
|
34
|
-
*/
|
|
35
|
-
sync(owner: string, onOutput: (output: SyncOutput) => void, from?: number, onDone?: () => void, onError?: (error: Error) => void): () => void;
|
|
36
|
-
/**
|
|
37
|
-
* Sync outputs for multiple owners via SSE stream.
|
|
25
|
+
* Sync outputs for owner(s) via SSE stream.
|
|
38
26
|
* The server merges results from all owners in score order.
|
|
39
27
|
*
|
|
40
28
|
* @param owners - Array of addresses/owners to sync
|
|
@@ -44,15 +32,10 @@ export declare class OwnerClient extends BaseClient {
|
|
|
44
32
|
* @param onError - Callback for errors
|
|
45
33
|
* @returns Unsubscribe function
|
|
46
34
|
*/
|
|
47
|
-
|
|
35
|
+
sync(owners: string[], onOutput: (output: SyncOutput) => void, from?: number, onDone?: () => void, onError?: (error: Error) => void): () => void;
|
|
48
36
|
/**
|
|
49
37
|
* Sync outputs as an async iterator.
|
|
50
38
|
* Yields SyncOutput objects until the stream is done.
|
|
51
39
|
*/
|
|
52
|
-
syncIterator(
|
|
53
|
-
/**
|
|
54
|
-
* Sync outputs for multiple owners as an async iterator.
|
|
55
|
-
* Yields SyncOutput objects until the stream is done.
|
|
56
|
-
*/
|
|
57
|
-
syncMultiIterator(owners: string[], from?: number): AsyncGenerator<SyncOutput, void, unknown>;
|
|
40
|
+
syncIterator(owners: string[], from?: number): AsyncGenerator<SyncOutput, void, unknown>;
|
|
58
41
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { ClientOptions, IndexedOutput,
|
|
1
|
+
import type { ClientOptions, IndexedOutput, TxoQueryOptions } from "../types";
|
|
2
2
|
import { BaseClient } from "./BaseClient";
|
|
3
3
|
/**
|
|
4
|
-
* Client for /
|
|
4
|
+
* Client for /1sat/txo/* routes.
|
|
5
5
|
* Provides TXO (transaction output) lookup and search.
|
|
6
6
|
*
|
|
7
7
|
* Routes:
|
|
8
|
-
* - GET
|
|
9
|
-
* - GET
|
|
8
|
+
* - GET /:outpoint - Get single TXO (outpoint pattern-matched)
|
|
9
|
+
* - GET /:outpoint/spend - Get spend info
|
|
10
10
|
* - POST /outpoints - Get multiple TXOs
|
|
11
|
-
* - POST /
|
|
11
|
+
* - POST /spends - Get multiple spends
|
|
12
12
|
* - GET /tx/:txid - Get all TXOs for a transaction
|
|
13
|
-
* - GET /search
|
|
14
|
-
* - POST /search - Search by multiple keys
|
|
13
|
+
* - GET /search?key=... - Search by key(s)
|
|
15
14
|
*/
|
|
16
15
|
export declare class TxoClient extends BaseClient {
|
|
17
16
|
constructor(baseUrl: string, options?: ClientOptions);
|
|
@@ -36,11 +35,7 @@ export declare class TxoClient extends BaseClient {
|
|
|
36
35
|
*/
|
|
37
36
|
getByTxid(txid: string, opts?: TxoQueryOptions): Promise<IndexedOutput[]>;
|
|
38
37
|
/**
|
|
39
|
-
* Search TXOs by
|
|
38
|
+
* Search TXOs by key(s)
|
|
40
39
|
*/
|
|
41
|
-
search(
|
|
42
|
-
/**
|
|
43
|
-
* Search TXOs by multiple keys
|
|
44
|
-
*/
|
|
45
|
-
searchMultiple(req: SearchRequest): Promise<IndexedOutput[]>;
|
|
40
|
+
search(keys: string | string[], opts?: TxoQueryOptions): Promise<IndexedOutput[]>;
|
|
46
41
|
}
|
package/dist/services/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface ClientOptions {
|
|
|
12
12
|
fetch?: typeof fetch;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Server capabilities returned by /
|
|
15
|
+
* Server capabilities returned by /1sat/capabilities endpoint.
|
|
16
16
|
* These match the actual capability names from 1sat-stack.
|
|
17
17
|
*/
|
|
18
18
|
export type Capability = "beef" | "pubsub" | "txo" | "owner" | "indexer" | "bsv21" | "ordfs" | "chaintracks" | "arcade" | "overlay";
|
|
@@ -74,19 +74,19 @@ export interface Policy {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* Indexed transaction output
|
|
77
|
+
* Indexed transaction output.
|
|
78
|
+
* Base fields (outpoint, score) are always present.
|
|
79
|
+
* Other fields are present based on query options.
|
|
78
80
|
*/
|
|
79
81
|
export interface IndexedOutput {
|
|
80
82
|
outpoint: string;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
score: number;
|
|
84
|
+
satoshis?: number;
|
|
85
|
+
blockHeight?: number;
|
|
86
|
+
blockIdx?: number;
|
|
87
|
+
spend?: string;
|
|
86
88
|
events?: string[];
|
|
87
89
|
data?: Record<string, unknown>;
|
|
88
|
-
spend?: string;
|
|
89
|
-
score: number;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Spend information response
|
|
@@ -98,10 +98,6 @@ export interface SpendResponse {
|
|
|
98
98
|
* Options for querying TXOs
|
|
99
99
|
*/
|
|
100
100
|
export interface TxoQueryOptions {
|
|
101
|
-
/** Tags to include in response data */
|
|
102
|
-
tags?: string[];
|
|
103
|
-
/** Include script in response */
|
|
104
|
-
script?: boolean;
|
|
105
101
|
/** Starting score for pagination */
|
|
106
102
|
from?: number;
|
|
107
103
|
/** Maximum results to return */
|
|
@@ -110,16 +106,15 @@ export interface TxoQueryOptions {
|
|
|
110
106
|
rev?: boolean;
|
|
111
107
|
/** Filter for unspent only */
|
|
112
108
|
unspent?: boolean;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
unspent?: boolean;
|
|
109
|
+
/** Include satoshis in response */
|
|
110
|
+
sats?: boolean;
|
|
111
|
+
/** Include spend txid in response */
|
|
112
|
+
spend?: boolean;
|
|
113
|
+
/** Include events array in response */
|
|
114
|
+
events?: boolean;
|
|
115
|
+
/** Include blockHeight and blockIdx in response */
|
|
116
|
+
block?: boolean;
|
|
117
|
+
/** Data tags to include in response */
|
|
123
118
|
tags?: string[];
|
|
124
119
|
}
|
|
125
120
|
/**
|
|
@@ -168,6 +163,38 @@ export interface OrdfsMetadata {
|
|
|
168
163
|
parent?: string;
|
|
169
164
|
map?: Record<string, unknown>;
|
|
170
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Options for OrdFS content requests
|
|
168
|
+
*/
|
|
169
|
+
export interface OrdfsContentOptions {
|
|
170
|
+
/** Sequence number (-1 for latest, 0+ for specific sequence) */
|
|
171
|
+
seq?: number;
|
|
172
|
+
/** Include MAP data in X-Map header */
|
|
173
|
+
map?: boolean;
|
|
174
|
+
/** Include parent outpoint in X-Parent header */
|
|
175
|
+
parent?: boolean;
|
|
176
|
+
/** Return raw directory JSON instead of resolving */
|
|
177
|
+
raw?: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Headers returned from OrdFS content responses
|
|
181
|
+
*/
|
|
182
|
+
export interface OrdfsResponseHeaders {
|
|
183
|
+
contentType: string;
|
|
184
|
+
outpoint?: string;
|
|
185
|
+
origin?: string;
|
|
186
|
+
sequence?: number;
|
|
187
|
+
cacheControl?: string;
|
|
188
|
+
map?: Record<string, unknown>;
|
|
189
|
+
parent?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Full content response from OrdFS including headers
|
|
193
|
+
*/
|
|
194
|
+
export interface OrdfsContentResponse {
|
|
195
|
+
data: Uint8Array;
|
|
196
|
+
headers: OrdfsResponseHeaders;
|
|
197
|
+
}
|
|
171
198
|
/**
|
|
172
199
|
* BSV21 token details (deploy data)
|
|
173
200
|
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SyncQueueInput, SyncQueueItem, SyncQueueStats, SyncQueueStorage, SyncState } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* IndexedDB implementation of SyncQueueStorage for browser environments.
|
|
4
|
+
*/
|
|
5
|
+
export declare class IndexedDbSyncQueue implements SyncQueueStorage {
|
|
6
|
+
private dbName;
|
|
7
|
+
private db;
|
|
8
|
+
private dbPromise;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new IndexedDB sync queue.
|
|
11
|
+
* @param accountId - Unique identifier for the account (e.g., address, pubkey hash)
|
|
12
|
+
*/
|
|
13
|
+
constructor(accountId: string);
|
|
14
|
+
private getDb;
|
|
15
|
+
enqueue(items: SyncQueueInput[]): Promise<void>;
|
|
16
|
+
claim(count?: number): Promise<Map<string, SyncQueueItem[]>>;
|
|
17
|
+
private getPendingByTxid;
|
|
18
|
+
private markProcessing;
|
|
19
|
+
complete(id: string): Promise<void>;
|
|
20
|
+
completeMany(ids: string[]): Promise<void>;
|
|
21
|
+
fail(id: string, error: string): Promise<void>;
|
|
22
|
+
getByTxid(txid: string): Promise<SyncQueueItem[]>;
|
|
23
|
+
getByStatus(status: SyncQueueItem["status"], limit?: number): Promise<SyncQueueItem[]>;
|
|
24
|
+
getStats(): Promise<SyncQueueStats>;
|
|
25
|
+
getState(): Promise<SyncState>;
|
|
26
|
+
setState(state: Partial<SyncState>): Promise<void>;
|
|
27
|
+
resetProcessing(): Promise<number>;
|
|
28
|
+
clear(): Promise<void>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { SyncQueueInput, SyncQueueItem, SyncQueueItemStatus, SyncQueueStats, SyncQueueStorage, SyncState } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Generic interface for SQLite database (works with better-sqlite3 and bun:sqlite)
|
|
4
|
+
*/
|
|
5
|
+
interface SqliteDatabase {
|
|
6
|
+
exec(sql: string): void;
|
|
7
|
+
prepare(sql: string): SqliteStatement;
|
|
8
|
+
close(): void;
|
|
9
|
+
}
|
|
10
|
+
interface SqliteStatement {
|
|
11
|
+
run(...params: unknown[]): {
|
|
12
|
+
changes: number;
|
|
13
|
+
};
|
|
14
|
+
get(...params: unknown[]): unknown;
|
|
15
|
+
all(...params: unknown[]): unknown[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* SQLite implementation of SyncQueueStorage for Node/Bun environments.
|
|
19
|
+
*
|
|
20
|
+
* Works with both `better-sqlite3` (Node) and `bun:sqlite` (Bun).
|
|
21
|
+
*/
|
|
22
|
+
export declare class SqliteSyncQueue implements SyncQueueStorage {
|
|
23
|
+
private db;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new SQLite sync queue.
|
|
26
|
+
* @param db - SQLite database instance (from better-sqlite3 or bun:sqlite)
|
|
27
|
+
*/
|
|
28
|
+
constructor(db: SqliteDatabase);
|
|
29
|
+
/**
|
|
30
|
+
* Create and open a SQLite database for an account.
|
|
31
|
+
* Helper for common use case.
|
|
32
|
+
*
|
|
33
|
+
* @param accountId - Unique identifier for the account (e.g., address, pubkey hash)
|
|
34
|
+
* @param dataDir - Directory for database files
|
|
35
|
+
* @param Database - SQLite Database constructor (e.g., from better-sqlite3 or bun:sqlite)
|
|
36
|
+
*/
|
|
37
|
+
static create(accountId: string, dataDir: string, Database: new (path: string) => any): SqliteSyncQueue;
|
|
38
|
+
private initialize;
|
|
39
|
+
enqueue(items: SyncQueueInput[]): Promise<void>;
|
|
40
|
+
claim(count?: number): Promise<Map<string, SyncQueueItem[]>>;
|
|
41
|
+
complete(id: string): Promise<void>;
|
|
42
|
+
completeMany(ids: string[]): Promise<void>;
|
|
43
|
+
fail(id: string, error: string): Promise<void>;
|
|
44
|
+
getByTxid(txid: string): Promise<SyncQueueItem[]>;
|
|
45
|
+
getByStatus(status: SyncQueueItemStatus, limit?: number): Promise<SyncQueueItem[]>;
|
|
46
|
+
getStats(): Promise<SyncQueueStats>;
|
|
47
|
+
getState(): Promise<SyncState>;
|
|
48
|
+
setState(state: Partial<SyncState>): Promise<void>;
|
|
49
|
+
resetProcessing(): Promise<number>;
|
|
50
|
+
clear(): Promise<void>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
private rowToItem;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync queue types for background transaction processing.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Sync state tracks SSE stream progress.
|
|
6
|
+
*/
|
|
7
|
+
export interface SyncState {
|
|
8
|
+
/** Highest score received from SSE, used to resume stream */
|
|
9
|
+
lastQueuedScore: number;
|
|
10
|
+
/** Timestamp of last sync activity */
|
|
11
|
+
lastSyncedAt?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Status of a queue item.
|
|
15
|
+
*/
|
|
16
|
+
export type SyncQueueItemStatus = "pending" | "processing" | "done" | "failed";
|
|
17
|
+
/**
|
|
18
|
+
* A single item in the sync queue.
|
|
19
|
+
*/
|
|
20
|
+
export interface SyncQueueItem {
|
|
21
|
+
/** Unique per record: `${outpoint}:${score}` */
|
|
22
|
+
id: string;
|
|
23
|
+
/** Outpoint in txid_vout format */
|
|
24
|
+
outpoint: string;
|
|
25
|
+
/** Score from SSE stream (ordering) */
|
|
26
|
+
score: number;
|
|
27
|
+
/** If this is a spend event, the txid that spent it */
|
|
28
|
+
spendTxid?: string;
|
|
29
|
+
/** Current processing status */
|
|
30
|
+
status: SyncQueueItemStatus;
|
|
31
|
+
/** Number of processing attempts */
|
|
32
|
+
attempts: number;
|
|
33
|
+
/** Last error message if failed */
|
|
34
|
+
lastError?: string;
|
|
35
|
+
/** Timestamp when item was queued */
|
|
36
|
+
createdAt: number;
|
|
37
|
+
/** Timestamp of last status update */
|
|
38
|
+
updatedAt: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Input for enqueueing new items (fields auto-populated by enqueue).
|
|
42
|
+
*/
|
|
43
|
+
export interface SyncQueueInput {
|
|
44
|
+
outpoint: string;
|
|
45
|
+
score: number;
|
|
46
|
+
spendTxid?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Queue statistics (transaction-level counts).
|
|
50
|
+
*/
|
|
51
|
+
export interface SyncQueueStats {
|
|
52
|
+
pending: number;
|
|
53
|
+
processing: number;
|
|
54
|
+
done: number;
|
|
55
|
+
failed: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Storage interface for the sync queue.
|
|
59
|
+
* Implementations: IndexedDB (browser), SQLite (Node/Bun).
|
|
60
|
+
*/
|
|
61
|
+
export interface SyncQueueStorage {
|
|
62
|
+
/**
|
|
63
|
+
* Add items to the queue.
|
|
64
|
+
* Items are created with status 'pending'.
|
|
65
|
+
*/
|
|
66
|
+
enqueue(items: SyncQueueInput[]): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Claim items for processing.
|
|
69
|
+
* Finds pending items, gathers all related items by txid, marks them all
|
|
70
|
+
* as 'processing', and returns them grouped by txid.
|
|
71
|
+
* @param count - Maximum number of seed items to start from (default: 1)
|
|
72
|
+
* @returns Map of txid -> items for that txid
|
|
73
|
+
*/
|
|
74
|
+
claim(count?: number): Promise<Map<string, SyncQueueItem[]>>;
|
|
75
|
+
/**
|
|
76
|
+
* Mark an item as complete.
|
|
77
|
+
* @param id - Queue item ID
|
|
78
|
+
*/
|
|
79
|
+
complete(id: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Mark multiple items as complete.
|
|
82
|
+
* @param ids - Queue item IDs
|
|
83
|
+
*/
|
|
84
|
+
completeMany(ids: string[]): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Mark an item as failed.
|
|
87
|
+
* @param id - Queue item ID
|
|
88
|
+
* @param error - Error message
|
|
89
|
+
*/
|
|
90
|
+
fail(id: string, error: string): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Get all queue items for a given txid.
|
|
93
|
+
* Used to gather spend info before ingesting a transaction.
|
|
94
|
+
* @param txid - Transaction ID (first 64 chars of outpoint)
|
|
95
|
+
*/
|
|
96
|
+
getByTxid(txid: string): Promise<SyncQueueItem[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Get queue items by status.
|
|
99
|
+
* @param status - Status to filter by
|
|
100
|
+
* @param limit - Maximum number of items to return (default: 100)
|
|
101
|
+
*/
|
|
102
|
+
getByStatus(status: SyncQueueItemStatus, limit?: number): Promise<SyncQueueItem[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Get queue statistics.
|
|
105
|
+
*/
|
|
106
|
+
getStats(): Promise<SyncQueueStats>;
|
|
107
|
+
/**
|
|
108
|
+
* Get sync state.
|
|
109
|
+
*/
|
|
110
|
+
getState(): Promise<SyncState>;
|
|
111
|
+
/**
|
|
112
|
+
* Update sync state.
|
|
113
|
+
*/
|
|
114
|
+
setState(state: Partial<SyncState>): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Reset any items stuck in "processing" back to "pending".
|
|
117
|
+
* Called at sync start to recover from crashed sessions.
|
|
118
|
+
*/
|
|
119
|
+
resetProcessing(): Promise<number>;
|
|
120
|
+
/**
|
|
121
|
+
* Clear all queue items and reset state.
|
|
122
|
+
* Next sync will start from score 0.
|
|
123
|
+
*/
|
|
124
|
+
clear(): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Close the storage connection.
|
|
127
|
+
*/
|
|
128
|
+
close(): Promise<void>;
|
|
129
|
+
}
|