@cashu/coco-expo-sqlite 1.0.0-rc.3 → 1.0.0-rc.5

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 ADDED
@@ -0,0 +1,35 @@
1
+ # @cashu/coco-expo-sqlite
2
+
3
+ > ⚠️ Release candidate: Coco is stabilizing for v1, but breaking changes may
4
+ > still land before the final 1.0 release. Pin versions in production.
5
+
6
+ Expo SQLite storage adapter for Coco in React Native and Expo applications.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @cashu/coco-core @cashu/coco-expo-sqlite
12
+ npx expo install expo-sqlite
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { initializeCoco } from '@cashu/coco-core';
19
+ import { ExpoSqliteRepositories } from '@cashu/coco-expo-sqlite';
20
+ import { openDatabaseAsync } from 'expo-sqlite';
21
+
22
+ const database = await openDatabaseAsync('coco.db');
23
+ const repositories = new ExpoSqliteRepositories({ database });
24
+ await repositories.init();
25
+
26
+ const manager = await initializeCoco({
27
+ repo: repositories,
28
+ seedGetter,
29
+ });
30
+ ```
31
+
32
+ ## Notes
33
+
34
+ - Pass an already opened `expo-sqlite` database instance via the `database` option.
35
+ - The adapter ensures schema creation and migrations when you call `init()`.
package/dist/index.cjs CHANGED
@@ -630,6 +630,12 @@ const MIGRATIONS = [
630
630
  id: "022_melt_operation_unit",
631
631
  sql: `
632
632
  ALTER TABLE coco_cashu_melt_operations ADD COLUMN unit TEXT;
633
+ `
634
+ },
635
+ {
636
+ id: "023_receive_operation_unit",
637
+ sql: `
638
+ ALTER TABLE coco_cashu_receive_operations ADD COLUMN unit TEXT NOT NULL DEFAULT 'sat';
633
639
  `
634
640
  }
635
641
  ];
@@ -1264,6 +1270,14 @@ var ExpoHistoryRepository = class {
1264
1270
  const entry = this.rowToEntry(row);
1265
1271
  return entry.type === "send" ? entry : null;
1266
1272
  }
1273
+ async getReceiveHistoryEntry(mintUrl, operationId) {
1274
+ const row = await this.db.get(`SELECT id, mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId
1275
+ FROM coco_cashu_history WHERE mintUrl = ? AND operationId = ? AND type = 'receive'
1276
+ ORDER BY createdAt DESC, id DESC LIMIT 1`, [mintUrl, operationId]);
1277
+ if (!row) return null;
1278
+ const entry = this.rowToEntry(row);
1279
+ return entry.type === "receive" ? entry : null;
1280
+ }
1267
1281
  async getPaginatedHistoryEntries(limit, offset) {
1268
1282
  return (await this.db.all(`SELECT id, mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId
1269
1283
  FROM coco_cashu_history
@@ -1310,6 +1324,7 @@ var ExpoHistoryRepository = class {
1310
1324
  case "receive":
1311
1325
  tokenJson = history.token ? JSON.stringify(history.token) : null;
1312
1326
  operationId = history.operationId ?? null;
1327
+ state = history.state;
1313
1328
  break;
1314
1329
  }
1315
1330
  const id = (await this.db.run(`INSERT INTO coco_cashu_history (mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId)
@@ -1409,7 +1424,26 @@ var ExpoHistoryRepository = class {
1409
1424
  ORDER BY createdAt DESC, id DESC LIMIT 1`, [history.mintUrl, history.operationId]);
1410
1425
  if (!row) throw new Error("Updated history entry not found");
1411
1426
  return this.rowToEntry(row);
1412
- } else throw new Error("updateHistoryEntry does not support receive entries");
1427
+ } else if (history.type === "receive") {
1428
+ if (!history.operationId) throw new Error("operationId required for receive entry");
1429
+ state = history.state;
1430
+ tokenJson = history.token ? JSON.stringify(history.token) : null;
1431
+ await this.db.run(`UPDATE coco_cashu_history SET unit = ?, amount = ?, state = ?, tokenJson = ?, metadata = ?
1432
+ WHERE mintUrl = ? AND operationId = ? AND type = 'receive'`, [
1433
+ history.unit,
1434
+ history.amount,
1435
+ state,
1436
+ tokenJson,
1437
+ history.metadata ? JSON.stringify(history.metadata) : null,
1438
+ history.mintUrl,
1439
+ history.operationId
1440
+ ]);
1441
+ const row = await this.db.get(`SELECT id, mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId
1442
+ FROM coco_cashu_history WHERE mintUrl = ? AND operationId = ? AND type = 'receive'
1443
+ ORDER BY createdAt DESC, id DESC LIMIT 1`, [history.mintUrl, history.operationId]);
1444
+ if (!row) throw new Error("Updated history entry not found");
1445
+ return this.rowToEntry(row);
1446
+ } else throw new Error(`Unsupported history entry type: ${String(history.type)}`);
1413
1447
  }
1414
1448
  async updateSendHistoryState(mintUrl, operationId, state) {
1415
1449
  await this.db.run(`UPDATE coco_cashu_history SET state = ?
@@ -1419,6 +1453,14 @@ var ExpoHistoryRepository = class {
1419
1453
  operationId
1420
1454
  ]);
1421
1455
  }
1456
+ async updateReceiveHistoryState(mintUrl, operationId, state) {
1457
+ await this.db.run(`UPDATE coco_cashu_history SET state = ?
1458
+ WHERE mintUrl = ? AND operationId = ? AND type = 'receive'`, [
1459
+ state,
1460
+ mintUrl,
1461
+ operationId
1462
+ ]);
1463
+ }
1422
1464
  async deleteHistoryEntry(mintUrl, quoteId) {
1423
1465
  await this.db.run("DELETE FROM coco_cashu_history WHERE mintUrl = ? AND quoteId = ?", [mintUrl, quoteId]);
1424
1466
  }
@@ -1467,6 +1509,7 @@ var ExpoHistoryRepository = class {
1467
1509
  type: "receive",
1468
1510
  amount: row.amount,
1469
1511
  operationId: row.operationId ?? void 0,
1512
+ state: row.state ?? "finalized",
1470
1513
  token
1471
1514
  };
1472
1515
  }
@@ -2037,10 +2080,14 @@ var ExpoMintOperationRepository = class {
2037
2080
 
2038
2081
  //#endregion
2039
2082
  //#region src/repositories/ReceiveOperationRepository.ts
2083
+ function getOperationUnit(op) {
2084
+ return op.unit ?? "sat";
2085
+ }
2040
2086
  function rowToOperation(row) {
2041
2087
  const base = {
2042
2088
  id: row.id,
2043
2089
  mintUrl: row.mintUrl,
2090
+ unit: row.unit ?? "sat",
2044
2091
  amount: row.amount,
2045
2092
  inputProofs: row.inputProofsJson ? JSON.parse(row.inputProofsJson) : [],
2046
2093
  createdAt: row.createdAt * 1e3,
@@ -2085,6 +2132,7 @@ function operationToParams(op) {
2085
2132
  if (op.state === "init") return [
2086
2133
  op.id,
2087
2134
  op.mintUrl,
2135
+ getOperationUnit(op),
2088
2136
  op.amount,
2089
2137
  op.state,
2090
2138
  createdAtSeconds,
@@ -2097,6 +2145,7 @@ function operationToParams(op) {
2097
2145
  return [
2098
2146
  op.id,
2099
2147
  op.mintUrl,
2148
+ getOperationUnit(op),
2100
2149
  op.amount,
2101
2150
  op.state,
2102
2151
  createdAtSeconds,
@@ -2116,27 +2165,29 @@ var ExpoReceiveOperationRepository = class {
2116
2165
  if (await this.db.get("SELECT id FROM coco_cashu_receive_operations WHERE id = ? LIMIT 1", [operation.id])) throw new Error(`ReceiveOperation with id ${operation.id} already exists`);
2117
2166
  const params = operationToParams(operation);
2118
2167
  await this.db.run(`INSERT INTO coco_cashu_receive_operations
2119
- (id, mintUrl, amount, state, createdAt, updatedAt, error, fee, inputProofsJson, outputDataJson)
2120
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, params);
2168
+ (id, mintUrl, unit, amount, state, createdAt, updatedAt, error, fee, inputProofsJson, outputDataJson)
2169
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, params);
2121
2170
  }
2122
2171
  async update(operation) {
2123
2172
  if (!await this.db.get("SELECT id FROM coco_cashu_receive_operations WHERE id = ? LIMIT 1", [operation.id])) throw new Error(`ReceiveOperation with id ${operation.id} not found`);
2124
2173
  const updatedAtSeconds = getUnixTimeSeconds();
2125
2174
  if (operation.state === "init") await this.db.run(`UPDATE coco_cashu_receive_operations
2126
- SET state = ?, updatedAt = ?, error = ?, inputProofsJson = ?
2175
+ SET state = ?, updatedAt = ?, error = ?, unit = ?, inputProofsJson = ?
2127
2176
  WHERE id = ?`, [
2128
2177
  operation.state,
2129
2178
  updatedAtSeconds,
2130
2179
  operation.error ?? null,
2180
+ getOperationUnit(operation),
2131
2181
  JSON.stringify(operation.inputProofs),
2132
2182
  operation.id
2133
2183
  ]);
2134
2184
  else await this.db.run(`UPDATE coco_cashu_receive_operations
2135
- SET state = ?, updatedAt = ?, error = ?, fee = ?, inputProofsJson = ?, outputDataJson = ?
2185
+ SET state = ?, updatedAt = ?, error = ?, unit = ?, fee = ?, inputProofsJson = ?, outputDataJson = ?
2136
2186
  WHERE id = ?`, [
2137
2187
  operation.state,
2138
2188
  updatedAtSeconds,
2139
2189
  operation.error ?? null,
2190
+ getOperationUnit(operation),
2140
2191
  operation.fee,
2141
2192
  JSON.stringify(operation.inputProofs),
2142
2193
  operation.outputData ? JSON.stringify(operation.outputData) : null,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthSession, AuthSessionRepository, CoreProof, Counter, CounterRepository, HistoryEntry, KeyRingRepository, Keypair, Keyset, KeysetRepository, MeltHistoryEntry, MeltOperationRepository, MeltQuote, MeltQuoteRepository, Mint, MintHistoryEntry, MintOperationRepository, MintQuote, MintQuoteRepository, MintRepository, ProofRepository, ProofState, ReceiveHistoryEntry, ReceiveOperation, ReceiveOperationRepository, ReceiveOperationState, Repositories, RepositoryTransactionScope, SendHistoryEntry, SendOperation, SendOperationRepository, SendOperationState } from "@cashu/coco-core";
1
+ import { AuthSession, AuthSessionRepository, CoreProof, Counter, CounterRepository, HistoryEntry, KeyRingRepository, Keypair, Keyset, KeysetRepository, MeltHistoryEntry, MeltOperationRepository, MeltQuote, MeltQuoteRepository, Mint, MintHistoryEntry, MintOperationRepository, MintQuote, MintQuoteRepository, MintRepository, ProofRepository, ProofState, ReceiveHistoryEntry, ReceiveHistoryState, ReceiveOperation, ReceiveOperationRepository, ReceiveOperationState, Repositories, RepositoryTransactionScope, SendHistoryEntry, SendOperation, SendOperationRepository, SendOperationState } from "@cashu/coco-core";
2
2
  import { SQLiteDatabase } from "expo-sqlite";
3
3
 
4
4
  //#region src/db.d.ts
@@ -179,13 +179,14 @@ type MintQuoteState = MintHistoryEntry['state'];
179
179
  type MeltQuoteState = MeltHistoryEntry['state'];
180
180
  type SendHistoryState = SendHistoryEntry['state'];
181
181
  type NewHistoryEntry = Omit<MintHistoryEntry, 'id'> | Omit<MeltHistoryEntry, 'id'> | Omit<SendHistoryEntry, 'id'> | Omit<ReceiveHistoryEntry, 'id'>;
182
- type UpdatableHistoryEntry = Omit<MintHistoryEntry, 'id' | 'createdAt'> | Omit<MeltHistoryEntry, 'id' | 'createdAt'> | Omit<SendHistoryEntry, 'id' | 'createdAt'>;
182
+ type UpdatableHistoryEntry = Omit<MintHistoryEntry, 'id' | 'createdAt'> | Omit<MeltHistoryEntry, 'id' | 'createdAt'> | Omit<SendHistoryEntry, 'id' | 'createdAt'> | Omit<ReceiveHistoryEntry, 'id' | 'createdAt'>;
183
183
  declare class ExpoHistoryRepository {
184
184
  private readonly db;
185
185
  constructor(db: ExpoSqliteDb);
186
186
  getMintHistoryEntry(mintUrl: string, quoteId: string): Promise<MintHistoryEntry | null>;
187
187
  getMeltHistoryEntry(mintUrl: string, quoteId: string): Promise<MeltHistoryEntry | null>;
188
188
  getSendHistoryEntry(mintUrl: string, operationId: string): Promise<SendHistoryEntry | null>;
189
+ getReceiveHistoryEntry(mintUrl: string, operationId: string): Promise<ReceiveHistoryEntry | null>;
189
190
  getPaginatedHistoryEntries(limit: number, offset: number): Promise<HistoryEntry[]>;
190
191
  getHistoryEntryById(id: string): Promise<HistoryEntry | null>;
191
192
  addHistoryEntry(history: NewHistoryEntry): Promise<HistoryEntry>;
@@ -193,6 +194,7 @@ declare class ExpoHistoryRepository {
193
194
  updateHistoryMeltEntry(mintUrl: string, quoteId: string, state: MeltQuoteState): Promise<HistoryEntry>;
194
195
  updateHistoryEntry(history: UpdatableHistoryEntry): Promise<HistoryEntry>;
195
196
  updateSendHistoryState(mintUrl: string, operationId: string, state: SendHistoryState): Promise<void>;
197
+ updateReceiveHistoryState(mintUrl: string, operationId: string, state: ReceiveHistoryState): Promise<void>;
196
198
  deleteHistoryEntry(mintUrl: string, quoteId: string): Promise<void>;
197
199
  private getById;
198
200
  private rowToEntry;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthSession, AuthSessionRepository, CoreProof, Counter, CounterRepository, HistoryEntry, KeyRingRepository, Keypair, Keyset, KeysetRepository, MeltHistoryEntry, MeltOperationRepository, MeltQuote, MeltQuoteRepository, Mint, MintHistoryEntry, MintOperationRepository, MintQuote, MintQuoteRepository, MintRepository, ProofRepository, ProofState, ReceiveHistoryEntry, ReceiveOperation, ReceiveOperationRepository, ReceiveOperationState, Repositories, RepositoryTransactionScope, SendHistoryEntry, SendOperation, SendOperationRepository, SendOperationState } from "@cashu/coco-core";
1
+ import { AuthSession, AuthSessionRepository, CoreProof, Counter, CounterRepository, HistoryEntry, KeyRingRepository, Keypair, Keyset, KeysetRepository, MeltHistoryEntry, MeltOperationRepository, MeltQuote, MeltQuoteRepository, Mint, MintHistoryEntry, MintOperationRepository, MintQuote, MintQuoteRepository, MintRepository, ProofRepository, ProofState, ReceiveHistoryEntry, ReceiveHistoryState, ReceiveOperation, ReceiveOperationRepository, ReceiveOperationState, Repositories, RepositoryTransactionScope, SendHistoryEntry, SendOperation, SendOperationRepository, SendOperationState } from "@cashu/coco-core";
2
2
  import { SQLiteDatabase } from "expo-sqlite";
3
3
 
4
4
  //#region src/db.d.ts
@@ -179,13 +179,14 @@ type MintQuoteState = MintHistoryEntry['state'];
179
179
  type MeltQuoteState = MeltHistoryEntry['state'];
180
180
  type SendHistoryState = SendHistoryEntry['state'];
181
181
  type NewHistoryEntry = Omit<MintHistoryEntry, 'id'> | Omit<MeltHistoryEntry, 'id'> | Omit<SendHistoryEntry, 'id'> | Omit<ReceiveHistoryEntry, 'id'>;
182
- type UpdatableHistoryEntry = Omit<MintHistoryEntry, 'id' | 'createdAt'> | Omit<MeltHistoryEntry, 'id' | 'createdAt'> | Omit<SendHistoryEntry, 'id' | 'createdAt'>;
182
+ type UpdatableHistoryEntry = Omit<MintHistoryEntry, 'id' | 'createdAt'> | Omit<MeltHistoryEntry, 'id' | 'createdAt'> | Omit<SendHistoryEntry, 'id' | 'createdAt'> | Omit<ReceiveHistoryEntry, 'id' | 'createdAt'>;
183
183
  declare class ExpoHistoryRepository {
184
184
  private readonly db;
185
185
  constructor(db: ExpoSqliteDb);
186
186
  getMintHistoryEntry(mintUrl: string, quoteId: string): Promise<MintHistoryEntry | null>;
187
187
  getMeltHistoryEntry(mintUrl: string, quoteId: string): Promise<MeltHistoryEntry | null>;
188
188
  getSendHistoryEntry(mintUrl: string, operationId: string): Promise<SendHistoryEntry | null>;
189
+ getReceiveHistoryEntry(mintUrl: string, operationId: string): Promise<ReceiveHistoryEntry | null>;
189
190
  getPaginatedHistoryEntries(limit: number, offset: number): Promise<HistoryEntry[]>;
190
191
  getHistoryEntryById(id: string): Promise<HistoryEntry | null>;
191
192
  addHistoryEntry(history: NewHistoryEntry): Promise<HistoryEntry>;
@@ -193,6 +194,7 @@ declare class ExpoHistoryRepository {
193
194
  updateHistoryMeltEntry(mintUrl: string, quoteId: string, state: MeltQuoteState): Promise<HistoryEntry>;
194
195
  updateHistoryEntry(history: UpdatableHistoryEntry): Promise<HistoryEntry>;
195
196
  updateSendHistoryState(mintUrl: string, operationId: string, state: SendHistoryState): Promise<void>;
197
+ updateReceiveHistoryState(mintUrl: string, operationId: string, state: ReceiveHistoryState): Promise<void>;
196
198
  deleteHistoryEntry(mintUrl: string, quoteId: string): Promise<void>;
197
199
  private getById;
198
200
  private rowToEntry;
package/dist/index.js CHANGED
@@ -630,6 +630,12 @@ const MIGRATIONS = [
630
630
  id: "022_melt_operation_unit",
631
631
  sql: `
632
632
  ALTER TABLE coco_cashu_melt_operations ADD COLUMN unit TEXT;
633
+ `
634
+ },
635
+ {
636
+ id: "023_receive_operation_unit",
637
+ sql: `
638
+ ALTER TABLE coco_cashu_receive_operations ADD COLUMN unit TEXT NOT NULL DEFAULT 'sat';
633
639
  `
634
640
  }
635
641
  ];
@@ -1264,6 +1270,14 @@ var ExpoHistoryRepository = class {
1264
1270
  const entry = this.rowToEntry(row);
1265
1271
  return entry.type === "send" ? entry : null;
1266
1272
  }
1273
+ async getReceiveHistoryEntry(mintUrl, operationId) {
1274
+ const row = await this.db.get(`SELECT id, mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId
1275
+ FROM coco_cashu_history WHERE mintUrl = ? AND operationId = ? AND type = 'receive'
1276
+ ORDER BY createdAt DESC, id DESC LIMIT 1`, [mintUrl, operationId]);
1277
+ if (!row) return null;
1278
+ const entry = this.rowToEntry(row);
1279
+ return entry.type === "receive" ? entry : null;
1280
+ }
1267
1281
  async getPaginatedHistoryEntries(limit, offset) {
1268
1282
  return (await this.db.all(`SELECT id, mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId
1269
1283
  FROM coco_cashu_history
@@ -1310,6 +1324,7 @@ var ExpoHistoryRepository = class {
1310
1324
  case "receive":
1311
1325
  tokenJson = history.token ? JSON.stringify(history.token) : null;
1312
1326
  operationId = history.operationId ?? null;
1327
+ state = history.state;
1313
1328
  break;
1314
1329
  }
1315
1330
  const id = (await this.db.run(`INSERT INTO coco_cashu_history (mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId)
@@ -1409,7 +1424,26 @@ var ExpoHistoryRepository = class {
1409
1424
  ORDER BY createdAt DESC, id DESC LIMIT 1`, [history.mintUrl, history.operationId]);
1410
1425
  if (!row) throw new Error("Updated history entry not found");
1411
1426
  return this.rowToEntry(row);
1412
- } else throw new Error("updateHistoryEntry does not support receive entries");
1427
+ } else if (history.type === "receive") {
1428
+ if (!history.operationId) throw new Error("operationId required for receive entry");
1429
+ state = history.state;
1430
+ tokenJson = history.token ? JSON.stringify(history.token) : null;
1431
+ await this.db.run(`UPDATE coco_cashu_history SET unit = ?, amount = ?, state = ?, tokenJson = ?, metadata = ?
1432
+ WHERE mintUrl = ? AND operationId = ? AND type = 'receive'`, [
1433
+ history.unit,
1434
+ history.amount,
1435
+ state,
1436
+ tokenJson,
1437
+ history.metadata ? JSON.stringify(history.metadata) : null,
1438
+ history.mintUrl,
1439
+ history.operationId
1440
+ ]);
1441
+ const row = await this.db.get(`SELECT id, mintUrl, type, unit, amount, createdAt, quoteId, state, paymentRequest, tokenJson, metadata, operationId
1442
+ FROM coco_cashu_history WHERE mintUrl = ? AND operationId = ? AND type = 'receive'
1443
+ ORDER BY createdAt DESC, id DESC LIMIT 1`, [history.mintUrl, history.operationId]);
1444
+ if (!row) throw new Error("Updated history entry not found");
1445
+ return this.rowToEntry(row);
1446
+ } else throw new Error(`Unsupported history entry type: ${String(history.type)}`);
1413
1447
  }
1414
1448
  async updateSendHistoryState(mintUrl, operationId, state) {
1415
1449
  await this.db.run(`UPDATE coco_cashu_history SET state = ?
@@ -1419,6 +1453,14 @@ var ExpoHistoryRepository = class {
1419
1453
  operationId
1420
1454
  ]);
1421
1455
  }
1456
+ async updateReceiveHistoryState(mintUrl, operationId, state) {
1457
+ await this.db.run(`UPDATE coco_cashu_history SET state = ?
1458
+ WHERE mintUrl = ? AND operationId = ? AND type = 'receive'`, [
1459
+ state,
1460
+ mintUrl,
1461
+ operationId
1462
+ ]);
1463
+ }
1422
1464
  async deleteHistoryEntry(mintUrl, quoteId) {
1423
1465
  await this.db.run("DELETE FROM coco_cashu_history WHERE mintUrl = ? AND quoteId = ?", [mintUrl, quoteId]);
1424
1466
  }
@@ -1467,6 +1509,7 @@ var ExpoHistoryRepository = class {
1467
1509
  type: "receive",
1468
1510
  amount: row.amount,
1469
1511
  operationId: row.operationId ?? void 0,
1512
+ state: row.state ?? "finalized",
1470
1513
  token
1471
1514
  };
1472
1515
  }
@@ -2037,10 +2080,14 @@ var ExpoMintOperationRepository = class {
2037
2080
 
2038
2081
  //#endregion
2039
2082
  //#region src/repositories/ReceiveOperationRepository.ts
2083
+ function getOperationUnit(op) {
2084
+ return op.unit ?? "sat";
2085
+ }
2040
2086
  function rowToOperation(row) {
2041
2087
  const base = {
2042
2088
  id: row.id,
2043
2089
  mintUrl: row.mintUrl,
2090
+ unit: row.unit ?? "sat",
2044
2091
  amount: row.amount,
2045
2092
  inputProofs: row.inputProofsJson ? JSON.parse(row.inputProofsJson) : [],
2046
2093
  createdAt: row.createdAt * 1e3,
@@ -2085,6 +2132,7 @@ function operationToParams(op) {
2085
2132
  if (op.state === "init") return [
2086
2133
  op.id,
2087
2134
  op.mintUrl,
2135
+ getOperationUnit(op),
2088
2136
  op.amount,
2089
2137
  op.state,
2090
2138
  createdAtSeconds,
@@ -2097,6 +2145,7 @@ function operationToParams(op) {
2097
2145
  return [
2098
2146
  op.id,
2099
2147
  op.mintUrl,
2148
+ getOperationUnit(op),
2100
2149
  op.amount,
2101
2150
  op.state,
2102
2151
  createdAtSeconds,
@@ -2116,27 +2165,29 @@ var ExpoReceiveOperationRepository = class {
2116
2165
  if (await this.db.get("SELECT id FROM coco_cashu_receive_operations WHERE id = ? LIMIT 1", [operation.id])) throw new Error(`ReceiveOperation with id ${operation.id} already exists`);
2117
2166
  const params = operationToParams(operation);
2118
2167
  await this.db.run(`INSERT INTO coco_cashu_receive_operations
2119
- (id, mintUrl, amount, state, createdAt, updatedAt, error, fee, inputProofsJson, outputDataJson)
2120
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, params);
2168
+ (id, mintUrl, unit, amount, state, createdAt, updatedAt, error, fee, inputProofsJson, outputDataJson)
2169
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, params);
2121
2170
  }
2122
2171
  async update(operation) {
2123
2172
  if (!await this.db.get("SELECT id FROM coco_cashu_receive_operations WHERE id = ? LIMIT 1", [operation.id])) throw new Error(`ReceiveOperation with id ${operation.id} not found`);
2124
2173
  const updatedAtSeconds = getUnixTimeSeconds();
2125
2174
  if (operation.state === "init") await this.db.run(`UPDATE coco_cashu_receive_operations
2126
- SET state = ?, updatedAt = ?, error = ?, inputProofsJson = ?
2175
+ SET state = ?, updatedAt = ?, error = ?, unit = ?, inputProofsJson = ?
2127
2176
  WHERE id = ?`, [
2128
2177
  operation.state,
2129
2178
  updatedAtSeconds,
2130
2179
  operation.error ?? null,
2180
+ getOperationUnit(operation),
2131
2181
  JSON.stringify(operation.inputProofs),
2132
2182
  operation.id
2133
2183
  ]);
2134
2184
  else await this.db.run(`UPDATE coco_cashu_receive_operations
2135
- SET state = ?, updatedAt = ?, error = ?, fee = ?, inputProofsJson = ?, outputDataJson = ?
2185
+ SET state = ?, updatedAt = ?, error = ?, unit = ?, fee = ?, inputProofsJson = ?, outputDataJson = ?
2136
2186
  WHERE id = ?`, [
2137
2187
  operation.state,
2138
2188
  updatedAtSeconds,
2139
2189
  operation.error ?? null,
2190
+ getOperationUnit(operation),
2140
2191
  operation.fee,
2141
2192
  JSON.stringify(operation.inputProofs),
2142
2193
  operation.outputData ? JSON.stringify(operation.outputData) : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashu/coco-expo-sqlite",
3
- "version": "1.0.0-rc.3",
3
+ "version": "1.0.0-rc.5",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  "README.md"
14
14
  ],
15
15
  "devDependencies": {
16
- "@cashu/coco-adapter-tests": "1.0.0-rc.3"
16
+ "@cashu/coco-adapter-tests": "1.0.0-rc.5"
17
17
  },
18
18
  "exports": {
19
19
  ".": {
@@ -31,6 +31,6 @@
31
31
  "peerDependencies": {
32
32
  "typescript": "^5",
33
33
  "expo-sqlite": "*",
34
- "@cashu/coco-core": "1.0.0-rc.3"
34
+ "@cashu/coco-core": "1.0.0-rc.5"
35
35
  }
36
36
  }