@arkade-os/swap 0.0.6 → 0.0.8
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/README.md +274 -13
- package/dist/{chunk-WGRU2DBF.js → chunk-6ZUS47GA.js} +15 -1
- package/dist/{chunk-Q4FAYBXS.js → chunk-TU4NGZDP.js} +108 -37
- package/dist/index.cjs +1205 -449
- package/dist/index.d.cts +292 -1139
- package/dist/index.d.ts +292 -1139
- package/dist/index.js +761 -87
- package/dist/nostr.cjs +15 -9
- package/dist/nostr.d.cts +1 -1
- package/dist/nostr.d.ts +1 -1
- package/dist/nostr.js +4 -11
- package/dist/repositories/realm/index.cjs +49 -5
- package/dist/repositories/realm/index.d.cts +28 -6
- package/dist/repositories/realm/index.d.ts +28 -6
- package/dist/repositories/realm/index.js +50 -6
- package/dist/repositories/sqlite/index.cjs +45 -4
- package/dist/repositories/sqlite/index.d.cts +20 -7
- package/dist/repositories/sqlite/index.d.ts +20 -7
- package/dist/repositories/sqlite/index.js +46 -5
- package/dist/repository-BcZ9LXRP.d.ts +1862 -0
- package/dist/repository-Dso34L4D.d.cts +1862 -0
- package/dist/{rfq-3jWha5xA.d.cts → rfq-C-aq5LDJ.d.cts} +82 -9
- package/dist/{rfq-3jWha5xA.d.ts → rfq-C-aq5LDJ.d.ts} +82 -9
- package/package.json +2 -2
- package/dist/repository-BwnZ8N62.d.cts +0 -236
- package/dist/repository-BwnZ8N62.d.ts +0 -236
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
marketsCacheKey
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-6ZUS47GA.js";
|
|
4
4
|
|
|
5
5
|
// src/repositories/sqlite/repository.ts
|
|
6
6
|
import {
|
|
@@ -14,14 +14,16 @@ var SQLiteAssetSwapRepository = class {
|
|
|
14
14
|
this.db = db;
|
|
15
15
|
this.prefix = sanitizeTablePrefix(options?.prefix ?? DEFAULT_PREFIX);
|
|
16
16
|
this.swaps = `${this.prefix}asset_swaps`;
|
|
17
|
+
this.rfqSwaps = `${this.prefix}rfq_swaps`;
|
|
17
18
|
this.scanned = `${this.prefix}asset_swap_scanned_txids`;
|
|
18
19
|
this.markets = `${this.prefix}asset_swap_markets`;
|
|
19
20
|
}
|
|
20
21
|
db;
|
|
21
|
-
version =
|
|
22
|
+
version = 4;
|
|
22
23
|
initPromise = null;
|
|
23
24
|
prefix;
|
|
24
25
|
swaps;
|
|
26
|
+
rfqSwaps;
|
|
25
27
|
scanned;
|
|
26
28
|
markets;
|
|
27
29
|
/** A rejected init is not cached. The DDL runs in a transaction on a shared
|
|
@@ -53,6 +55,15 @@ var SQLiteAssetSwapRepository = class {
|
|
|
53
55
|
await this.db.run(
|
|
54
56
|
`CREATE INDEX IF NOT EXISTS idx_${this.prefix}asset_swaps_created_at ON ${this.swaps} (created_at)`
|
|
55
57
|
);
|
|
58
|
+
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.rfqSwaps} (
|
|
59
|
+
rfq_id TEXT PRIMARY KEY,
|
|
60
|
+
state TEXT NOT NULL,
|
|
61
|
+
updated_at INTEGER NOT NULL,
|
|
62
|
+
data TEXT NOT NULL
|
|
63
|
+
)`);
|
|
64
|
+
await this.db.run(
|
|
65
|
+
`CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
|
|
66
|
+
);
|
|
56
67
|
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.scanned} (txid TEXT PRIMARY KEY)`);
|
|
57
68
|
await this.db.run(
|
|
58
69
|
`CREATE TABLE IF NOT EXISTS ${this.markets} (cache_key TEXT PRIMARY KEY, data TEXT NOT NULL)`
|
|
@@ -83,6 +94,35 @@ var SQLiteAssetSwapRepository = class {
|
|
|
83
94
|
const rows = await this.db.all(`SELECT data FROM ${this.swaps}`);
|
|
84
95
|
return rows.map((r) => JSON.parse(r.data));
|
|
85
96
|
}
|
|
97
|
+
async saveRfqSwap(record) {
|
|
98
|
+
await this.ensureInit();
|
|
99
|
+
await this.withTx(async () => {
|
|
100
|
+
await this.db.run(
|
|
101
|
+
`INSERT OR REPLACE INTO ${this.rfqSwaps} (rfq_id, state, updated_at, data)
|
|
102
|
+
VALUES (?, ?, ?, ?)`,
|
|
103
|
+
[record.rfqId, record.state, record.updatedAt, JSON.stringify(record)]
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async getRfqSwap(rfqId) {
|
|
108
|
+
await this.ensureInit();
|
|
109
|
+
const row = await this.db.get(
|
|
110
|
+
`SELECT data FROM ${this.rfqSwaps} WHERE rfq_id = ?`,
|
|
111
|
+
[rfqId]
|
|
112
|
+
);
|
|
113
|
+
return row ? JSON.parse(row.data) : void 0;
|
|
114
|
+
}
|
|
115
|
+
async getAllRfqSwaps() {
|
|
116
|
+
await this.ensureInit();
|
|
117
|
+
const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
|
|
118
|
+
return rows.map((r) => JSON.parse(r.data));
|
|
119
|
+
}
|
|
120
|
+
async removeRfqSwap(rfqId) {
|
|
121
|
+
await this.ensureInit();
|
|
122
|
+
await this.withTx(async () => {
|
|
123
|
+
await this.db.run(`DELETE FROM ${this.rfqSwaps} WHERE rfq_id = ?`, [rfqId]);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
86
126
|
async getScannedTxids() {
|
|
87
127
|
await this.ensureInit();
|
|
88
128
|
const rows = await this.db.all(`SELECT txid FROM ${this.scanned}`);
|
|
@@ -119,13 +159,14 @@ var SQLiteAssetSwapRepository = class {
|
|
|
119
159
|
);
|
|
120
160
|
});
|
|
121
161
|
}
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
162
|
+
/** Every table in one transaction: clearing swaps but keeping scanned txids
|
|
163
|
+
* would leave the restore scan permanently skipping those funding txs, so a
|
|
164
|
+
* partial clear must not be observable. */
|
|
125
165
|
async clear() {
|
|
126
166
|
await this.ensureInit();
|
|
127
167
|
await this.withTx(async () => {
|
|
128
168
|
await this.db.run(`DELETE FROM ${this.swaps}`);
|
|
169
|
+
await this.db.run(`DELETE FROM ${this.rfqSwaps}`);
|
|
129
170
|
await this.db.run(`DELETE FROM ${this.scanned}`);
|
|
130
171
|
await this.db.run(`DELETE FROM ${this.markets}`);
|
|
131
172
|
});
|