@render-foundation/utils 0.0.257 → 0.0.259
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/lib/cjs/client/pg/base.js.map +1 -1
- package/lib/cjs/client/pg/v2Client.js +133 -81
- package/lib/cjs/client/pg/v2Client.js.map +1 -1
- package/lib/esm/src/client/pg/base.js.map +1 -1
- package/lib/esm/src/client/pg/v2Client.js +127 -63
- package/lib/esm/src/client/pg/v2Client.js.map +1 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/src/client/pg/base.d.ts +5 -1
- package/lib/types/src/client/pg/base.d.ts.map +1 -1
- package/lib/types/src/client/pg/v2Client.d.ts +2 -1
- package/lib/types/src/client/pg/v2Client.d.ts.map +1 -1
- package/lib/types/src/dbTypesV2.d.ts +1 -0
- package/lib/types/src/dbTypesV2.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/client/pg/base.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,2BAA6C;AAE7C,yCACC;AAAC,MAAM,CAAC,SAAiB,CAAC,MAAM,GAAG;IAClC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;AACxB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/client/pg/base.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,2BAA6C;AAE7C,yCACC;AAAC,MAAM,CAAC,SAAiB,CAAC,MAAM,GAAG;IAClC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;AACxB,CAAC,CAAA;AAmED,MAAa,QAAQ;IAMnB;QALS,oCAAoB;QAE7B,oCAA8C;QAC9C,mCAAgC;QAahC,YAAO,GAAG,CAAC,KAAyB,EAAQ,EAAE;YAC5C,IAAI,uBAAA,IAAI,yBAAS,EAAE;gBACj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IAAY,CAAC,KAAK,GAAG,UACrB,WAAgB,EAChB,MAAY,EACZ,QAAc;;QAEd,iEAAiE;QACjE,IAAI,IAAY,CAAA;QAChB,IAAI,MAAM,GAA2B,EAAE,CAAA;QACvC,IAAI,EAAO,CAAA;QAEX,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;YACnC,IAAI,GAAG,WAAW,CAAA;YAClB,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;gBAChC,EAAE,GAAG,MAAM,CAAA;aACZ;iBAAM;gBACL,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;gBACrB,EAAE,GAAG,QAAQ,CAAA;aACd;SACF;aAAM;YACL,IAAI,GAAG,WAAW,CAAC,IAAI,CAAA;YACvB,MAAM,GAAG,MAAA,WAAW,CAAC,MAAM,mCAAI,EAAE,CAAA;YACjC,EAAE,GAAG,MAAM,CAAA,CAAC,2BAA2B;SACxC;QAED,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;QAEhE,IAAI,EAAE,EAAE;YACN,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YACxC,oDAAoD;YACpD,OAAM;SACP;QACD,OAAO,CAAC,CAAA;IACV,CAAC,CAGA;IAAC,IAAY,CAAC,UAAU,GAAG,SAAS,CAAA;AACvC,CAAC;AA1CD,wDA0CC"}
|
|
@@ -1558,7 +1558,7 @@ const pgClient = (config) => {
|
|
|
1558
1558
|
});
|
|
1559
1559
|
},
|
|
1560
1560
|
fetchBurns(db, f, log = logger_1.consoleLogger) {
|
|
1561
|
-
var _a, _b;
|
|
1561
|
+
var _a, _b, _c;
|
|
1562
1562
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1563
1563
|
let q = db.trx
|
|
1564
1564
|
.selectFrom('burn')
|
|
@@ -1606,6 +1606,7 @@ const pgClient = (config) => {
|
|
|
1606
1606
|
eurToUsdc: r.eur_to_usdc,
|
|
1607
1607
|
markedBurnedAt: r.marked_burned_at,
|
|
1608
1608
|
tags: r.tags ? r.tags.split(',') : [],
|
|
1609
|
+
fromEscrowUsdc: BigInt((_c = r.from_escrow_usdc) !== null && _c !== void 0 ? _c : 0),
|
|
1609
1610
|
});
|
|
1610
1611
|
burnIdToIdx[r.id] = burns.length - 1;
|
|
1611
1612
|
}
|
|
@@ -1631,75 +1632,138 @@ const pgClient = (config) => {
|
|
|
1631
1632
|
fetchBurnsPage(db, f, log = logger_1.consoleLogger) {
|
|
1632
1633
|
var _a;
|
|
1633
1634
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1634
|
-
const
|
|
1635
|
-
|
|
1636
|
-
.
|
|
1637
|
-
.
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
if (f.
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1635
|
+
const params = [];
|
|
1636
|
+
const p = (v) => {
|
|
1637
|
+
params.push(v);
|
|
1638
|
+
return `$${params.length}`;
|
|
1639
|
+
};
|
|
1640
|
+
// Decode cursor — supports new {t,id,ea} format and legacy bare-id format.
|
|
1641
|
+
let cursorEa;
|
|
1642
|
+
let cursorType;
|
|
1643
|
+
let cursorId;
|
|
1644
|
+
if (f.cursor) {
|
|
1645
|
+
const raw = atob(f.cursor);
|
|
1646
|
+
try {
|
|
1647
|
+
const c = JSON.parse(raw);
|
|
1648
|
+
cursorEa = new Date(c.ea);
|
|
1649
|
+
cursorType = c.t;
|
|
1650
|
+
cursorId = c.id;
|
|
1651
|
+
}
|
|
1652
|
+
catch (_b) {
|
|
1653
|
+
// Legacy cursor: bare burn.id — treat as buy-burn cursor.
|
|
1654
|
+
cursorId = Number(raw);
|
|
1655
|
+
cursorType = 'buy';
|
|
1656
|
+
}
|
|
1652
1657
|
}
|
|
1658
|
+
// Shared WHERE fragments pushed into each union leg for index use.
|
|
1659
|
+
const dateFilters = [];
|
|
1660
|
+
if (f.executedAfter)
|
|
1661
|
+
dateFilters.push(`st.executed_at >= ${p(f.executedAfter)}`);
|
|
1662
|
+
if (f.executedBefore)
|
|
1663
|
+
dateFilters.push(`st.executed_at <= ${p(f.executedBefore)}`);
|
|
1664
|
+
const sigFilter = f.sig ? `st.sig = ${p(f.sig)}` : '';
|
|
1665
|
+
// Buy-burn leg
|
|
1666
|
+
const buyWhere = [...dateFilters];
|
|
1667
|
+
if (!f.inclManual)
|
|
1668
|
+
buyWhere.push('b.usdc_spent > 0');
|
|
1669
|
+
if (sigFilter)
|
|
1670
|
+
buyWhere.push(sigFilter);
|
|
1653
1671
|
if (f.jobId !== undefined) {
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1672
|
+
buyWhere.push(`b.id IN (SELECT burn_id FROM job WHERE id = ${p(f.jobId)})`);
|
|
1673
|
+
}
|
|
1674
|
+
const buyWhereClause = buyWhere.length ? `WHERE ${buyWhere.join(' AND ')}` : '';
|
|
1675
|
+
const buySql = `
|
|
1676
|
+
SELECT 'buy'::text AS type, b.id::bigint AS sortid, b.id AS id,
|
|
1677
|
+
st.executed_at, b.priced_at, b.burned::text AS burned,
|
|
1678
|
+
b.usdc_spent::text AS usdc_spent, b.quote_amt::text AS quote_amt,
|
|
1679
|
+
b.tags, st.sig, b.render_to_usdc, b.eur_to_usdc,
|
|
1680
|
+
coalesce(b.from_escrow_usdc, 0)::text AS from_escrow_usdc,
|
|
1681
|
+
b.down_correction_id, b.escrow_correction_id,
|
|
1682
|
+
b.marked_burned_at
|
|
1683
|
+
FROM burn b
|
|
1684
|
+
INNER JOIN sol_tx st ON st.id = b.sol_tx_id
|
|
1685
|
+
${buyWhereClause}`;
|
|
1686
|
+
// Grant-burn leg
|
|
1687
|
+
const grantWhere = [...dateFilters];
|
|
1688
|
+
if (sigFilter)
|
|
1689
|
+
grantWhere.push(sigFilter);
|
|
1690
|
+
if (f.jobId !== undefined) {
|
|
1691
|
+
grantWhere.push(`gb.id IN (SELECT grant_burn_id FROM job WHERE id = ${p(f.jobId)})`);
|
|
1692
|
+
}
|
|
1693
|
+
const grantWhereClause = grantWhere.length ? `WHERE ${grantWhere.join(' AND ')}` : '';
|
|
1694
|
+
const grantSql = `
|
|
1695
|
+
SELECT 'grant'::text AS type, gb.id::bigint AS sortid, gb.id AS id,
|
|
1696
|
+
st.executed_at, null::timestamp AS priced_at, gb.burned::text AS burned,
|
|
1697
|
+
'0' AS usdc_spent, '0' AS quote_amt,
|
|
1698
|
+
gb.tags, st.sig, null::float8 AS render_to_usdc, null::float8 AS eur_to_usdc,
|
|
1699
|
+
'0' AS from_escrow_usdc,
|
|
1700
|
+
null::bigint AS down_correction_id, null::bigint AS escrow_correction_id,
|
|
1701
|
+
gb.marked_burned_at
|
|
1702
|
+
FROM grant_burn gb
|
|
1703
|
+
INNER JOIN sol_tx st ON st.id = gb.sol_tx_id
|
|
1704
|
+
${grantWhereClause}`;
|
|
1705
|
+
// Cursor filter on the outer query — row comparison for deterministic paging.
|
|
1706
|
+
let cursorFilter = '';
|
|
1707
|
+
if (cursorEa && cursorType && cursorId !== undefined) {
|
|
1708
|
+
cursorFilter = `WHERE (u.executed_at, u.type, u.sortid) > (${p(cursorEa)}, ${p(cursorType)}, ${p(cursorId)})`;
|
|
1709
|
+
}
|
|
1710
|
+
else if (cursorId !== undefined) {
|
|
1711
|
+
// Legacy cursor fallback: only buy burns, ordered by id.
|
|
1712
|
+
cursorFilter = `WHERE u.type = 'buy' AND u.sortid > ${p(cursorId)}`;
|
|
1664
1713
|
}
|
|
1665
1714
|
const limit = (_a = f.limit) !== null && _a !== void 0 ? _a : 1000;
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1715
|
+
const sql = `
|
|
1716
|
+
SELECT u.* FROM (
|
|
1717
|
+
${buySql}
|
|
1718
|
+
UNION ALL
|
|
1719
|
+
${grantSql}
|
|
1720
|
+
) u
|
|
1721
|
+
${cursorFilter}
|
|
1722
|
+
ORDER BY u.executed_at ASC, u.type, u.sortid
|
|
1723
|
+
LIMIT ${p(limit)}`;
|
|
1724
|
+
const { rows } = yield (0, base_1.timedQuery)(pgPool, sql, params, 'fetchBurnsPage', log);
|
|
1669
1725
|
const burns = rows.map((r) => {
|
|
1670
|
-
var _a, _b;
|
|
1726
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1671
1727
|
return ({
|
|
1672
1728
|
jobs: [],
|
|
1673
1729
|
id: Number(r.id),
|
|
1674
|
-
|
|
1730
|
+
type: r.type,
|
|
1731
|
+
renderToUsdc: (_a = r.render_to_usdc) !== null && _a !== void 0 ? _a : undefined,
|
|
1675
1732
|
solTx: r.sig,
|
|
1676
1733
|
executedAt: r.executed_at,
|
|
1677
|
-
pricedAt: r.priced_at,
|
|
1678
|
-
usdcSpent: BigInt((
|
|
1679
|
-
quoteAmt: BigInt((
|
|
1734
|
+
pricedAt: (_b = r.priced_at) !== null && _b !== void 0 ? _b : undefined,
|
|
1735
|
+
usdcSpent: BigInt((_c = r.usdc_spent) !== null && _c !== void 0 ? _c : 0),
|
|
1736
|
+
quoteAmt: BigInt((_d = r.quote_amt) !== null && _d !== void 0 ? _d : 0),
|
|
1680
1737
|
burned: BigInt(r.burned),
|
|
1681
|
-
eurToUsdc: r.eur_to_usdc,
|
|
1738
|
+
eurToUsdc: (_e = r.eur_to_usdc) !== null && _e !== void 0 ? _e : undefined,
|
|
1682
1739
|
markedBurnedAt: r.marked_burned_at,
|
|
1683
1740
|
tags: r.tags ? r.tags.split(',') : [],
|
|
1741
|
+
fromEscrowUsdc: BigInt((_f = r.from_escrow_usdc) !== null && _f !== void 0 ? _f : 0),
|
|
1742
|
+
downCorrectionId: r.down_correction_id ? Number(r.down_correction_id) : undefined,
|
|
1743
|
+
escrowCorrectionId: r.escrow_correction_id ? Number(r.escrow_correction_id) : undefined,
|
|
1684
1744
|
});
|
|
1685
1745
|
});
|
|
1686
1746
|
return {
|
|
1687
1747
|
burns,
|
|
1688
|
-
// Only hand back a cursor on a full page; a short page means we're done.
|
|
1689
1748
|
cursor: burns.length === limit
|
|
1690
|
-
? btoa(
|
|
1749
|
+
? btoa(JSON.stringify({
|
|
1750
|
+
ea: rows[burns.length - 1].executed_at,
|
|
1751
|
+
t: rows[burns.length - 1].type,
|
|
1752
|
+
id: rows[burns.length - 1].sortid,
|
|
1753
|
+
}))
|
|
1691
1754
|
: undefined,
|
|
1692
1755
|
};
|
|
1693
1756
|
});
|
|
1694
1757
|
},
|
|
1695
|
-
fetchBurnJobs(db, burnId, log = logger_1.consoleLogger) {
|
|
1758
|
+
fetchBurnJobs(db, burnId, burnType = 'buy', log = logger_1.consoleLogger) {
|
|
1696
1759
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1760
|
+
const fk = burnType === 'grant' ? 'grant_burn_id' : 'burn_id';
|
|
1697
1761
|
const rows = yield db.trx
|
|
1698
1762
|
.selectFrom('job')
|
|
1699
1763
|
.selectAll('job')
|
|
1700
|
-
.where(
|
|
1764
|
+
.where(fk, '=', String(burnId))
|
|
1701
1765
|
.execute();
|
|
1702
|
-
log.debug(`fetchBurnJobs
|
|
1766
|
+
log.debug(`fetchBurnJobs ${burnType} ${burnId} -> ${rows.length} jobs`);
|
|
1703
1767
|
return rows.map((r) => ({
|
|
1704
1768
|
id: Number(r.id),
|
|
1705
1769
|
completedAt: r.completed_at,
|
|
@@ -1722,8 +1786,8 @@ const pgClient = (config) => {
|
|
|
1722
1786
|
.innerJoin('sol_tx', 'sol_tx.id', 'burn.sol_tx_id')
|
|
1723
1787
|
.select(({ fn }) => [
|
|
1724
1788
|
dayExpr.as('day'),
|
|
1725
|
-
|
|
1726
|
-
|
|
1789
|
+
(0, kysely_1.sql) `SUM(CASE WHEN burn.burned > 0 THEN burn.burned WHEN COALESCE(burn.from_escrow_usdc, 0) > 0 AND burn.render_to_usdc > 0 THEN (burn.from_escrow_usdc::numeric / burn.render_to_usdc * 100)::bigint ELSE 0 END)`.as('render_burned'),
|
|
1790
|
+
(0, kysely_1.sql) `SUM(CASE WHEN burn.usdc_spent > 0 THEN burn.usdc_spent ELSE COALESCE(burn.from_escrow_usdc, 0) END)`.as('usdc_spent'),
|
|
1727
1791
|
fn.count('burn.id').as('burn_count'),
|
|
1728
1792
|
])
|
|
1729
1793
|
.groupBy((0, kysely_1.sql) `date_trunc('day', sol_tx.executed_at)`)
|
|
@@ -2027,16 +2091,14 @@ const pgClient = (config) => {
|
|
|
2027
2091
|
// Check if dispersed_obligation table exists BEFORE the transaction so a missing table never
|
|
2028
2092
|
// poisons the txn (PG aborts the entire transaction on any error, even a caught one).
|
|
2029
2093
|
let hasObligationTable = false;
|
|
2094
|
+
let hasJsonbColumn = false;
|
|
2030
2095
|
if ((_a = p.obligations) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
catch (_b) {
|
|
2036
|
-
hasObligationTable = false;
|
|
2037
|
-
}
|
|
2096
|
+
const { rows: tblRows } = yield (0, base_1.timedQuery)(pgPool, `SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'dispersed_obligation' LIMIT 1`, [], 'checkObligationTable', log);
|
|
2097
|
+
hasObligationTable = tblRows.length > 0;
|
|
2098
|
+
const { rows: colRows } = yield (0, base_1.timedQuery)(pgPool, `SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'dispersed_settlement' AND column_name = 'obligation_details' LIMIT 1`, [], 'checkObligationDetailsCol', log);
|
|
2099
|
+
hasJsonbColumn = colRows.length > 0;
|
|
2038
2100
|
if (!hasObligationTable) {
|
|
2039
|
-
log.warn(`dispersed obligations: table not found (migration 44 pending); skipping for tx ${p.txSignature}`);
|
|
2101
|
+
log.warn(`dispersed obligations: table not found (migration 44 pending); skipping fan-out for tx ${p.txSignature}`);
|
|
2040
2102
|
}
|
|
2041
2103
|
}
|
|
2042
2104
|
// The outbox row is the durable, crash-safe anchor persisted BEFORE broadcast. When it carries a
|
|
@@ -2047,24 +2109,12 @@ const pgClient = (config) => {
|
|
|
2047
2109
|
// took the room), the whole txn rolls back and we return {inserted:false} — the caller must NOT
|
|
2048
2110
|
// broadcast (no row, no counter change, no burn).
|
|
2049
2111
|
const result = yield db.transaction().execute((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
2050
|
-
var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
2112
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
2051
2113
|
const res = yield trx
|
|
2052
2114
|
.insertInto(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
2053
|
-
.values({
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
obligation_uuids: p.obligationUuids,
|
|
2057
|
-
settled_amount: p.settledAmount,
|
|
2058
|
-
burned_amount: p.burnedAmount,
|
|
2059
|
-
executed_at: p.executedAt,
|
|
2060
|
-
eur_render: (_c = p.eurRender) !== null && _c !== void 0 ? _c : null,
|
|
2061
|
-
last_valid_block_height: (_d = p.lastValidBlockHeight) !== null && _d !== void 0 ? _d : null,
|
|
2062
|
-
usdc_spent: (_e = p.usdcSpent) !== null && _e !== void 0 ? _e : null,
|
|
2063
|
-
correction_id: (_f = p.correctionId) !== null && _f !== void 0 ? _f : null,
|
|
2064
|
-
correction_render: (_g = p.correctionRender) !== null && _g !== void 0 ? _g : null,
|
|
2065
|
-
usage_from: (_h = p.usageFrom) !== null && _h !== void 0 ? _h : null,
|
|
2066
|
-
usage_to: (_j = p.usageTo) !== null && _j !== void 0 ? _j : null,
|
|
2067
|
-
})
|
|
2115
|
+
.values(Object.assign({ tx_signature: p.txSignature, claim_uuid: p.claimUuid, obligation_uuids: p.obligationUuids, settled_amount: p.settledAmount, burned_amount: p.burnedAmount, executed_at: p.executedAt, eur_render: (_b = p.eurRender) !== null && _b !== void 0 ? _b : null, last_valid_block_height: (_c = p.lastValidBlockHeight) !== null && _c !== void 0 ? _c : null, usdc_spent: (_d = p.usdcSpent) !== null && _d !== void 0 ? _d : null, correction_id: (_e = p.correctionId) !== null && _e !== void 0 ? _e : null, correction_render: (_f = p.correctionRender) !== null && _f !== void 0 ? _f : null, usage_from: (_g = p.usageFrom) !== null && _g !== void 0 ? _g : null, usage_to: (_h = p.usageTo) !== null && _h !== void 0 ? _h : null }, (hasJsonbColumn && ((_j = p.obligations) === null || _j === void 0 ? void 0 : _j.length)
|
|
2116
|
+
? { obligation_details: JSON.stringify(p.obligations.map((o) => ({ uuid: o.uuid, amount_eur: o.amountEur, opened_at: o.openedAt.toISOString(), authorization_uuid: o.authorizationUuid }))) }
|
|
2117
|
+
: {})))
|
|
2068
2118
|
.onConflict((oc) => oc.column('tx_signature').doNothing())
|
|
2069
2119
|
.executeTakeFirst();
|
|
2070
2120
|
const inserted = ((_k = res.numInsertedOrUpdatedRows) !== null && _k !== void 0 ? _k : BigInt(0)) > BigInt(0);
|
|
@@ -2089,21 +2139,22 @@ const pgClient = (config) => {
|
|
|
2089
2139
|
}
|
|
2090
2140
|
}
|
|
2091
2141
|
if (inserted && hasObligationTable && ((_m = p.obligations) === null || _m === void 0 ? void 0 : _m.length)) {
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2142
|
+
yield trx
|
|
2143
|
+
.insertInto('dispersed_obligation')
|
|
2144
|
+
.values(p.obligations.map((o) => {
|
|
2145
|
+
var _a;
|
|
2146
|
+
return ({
|
|
2096
2147
|
settlement_tx_sig: p.txSignature,
|
|
2097
2148
|
uuid: o.uuid,
|
|
2098
2149
|
amount_eur: o.amountEur,
|
|
2099
2150
|
opened_at: o.openedAt,
|
|
2100
|
-
authorization_uuid: (
|
|
2101
|
-
})
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2151
|
+
authorization_uuid: (_a = o.authorizationUuid) !== null && _a !== void 0 ? _a : null,
|
|
2152
|
+
});
|
|
2153
|
+
}))
|
|
2154
|
+
.onConflict((oc) => oc.column('uuid').doNothing())
|
|
2155
|
+
.execute();
|
|
2105
2156
|
}
|
|
2106
|
-
log.debug(`dispersed outbox tx ${p.txSignature}: ${res.numInsertedOrUpdatedRows} row(s), ${hasObligationTable ? ((
|
|
2157
|
+
log.debug(`dispersed outbox tx ${p.txSignature}: ${res.numInsertedOrUpdatedRows} row(s), ${hasObligationTable ? ((_p = (_o = p.obligations) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : 0) : 0} obligations`);
|
|
2107
2158
|
return { inserted };
|
|
2108
2159
|
})).catch((e) => {
|
|
2109
2160
|
if (e instanceof DispersedCorrectionRejected)
|
|
@@ -2152,7 +2203,7 @@ const pgClient = (config) => {
|
|
|
2152
2203
|
.execute();
|
|
2153
2204
|
log.debug(`dispersed outbox: ${rows.length} unsettled`);
|
|
2154
2205
|
return rows.map((r) => {
|
|
2155
|
-
var _a, _b;
|
|
2206
|
+
var _a, _b, _c, _d;
|
|
2156
2207
|
return ({
|
|
2157
2208
|
txSignature: r.tx_signature,
|
|
2158
2209
|
claimUuid: r.claim_uuid,
|
|
@@ -2162,10 +2213,11 @@ const pgClient = (config) => {
|
|
|
2162
2213
|
executedAt: r.executed_at,
|
|
2163
2214
|
eurRender: (_a = r.eur_render) !== null && _a !== void 0 ? _a : undefined,
|
|
2164
2215
|
usdcSpent: (_b = r.usdc_spent) !== null && _b !== void 0 ? _b : undefined,
|
|
2165
|
-
// int8 comes back as a string from pg; block heights are well within JS safe-integer range.
|
|
2166
2216
|
lastValidBlockHeight: r.last_valid_block_height != null
|
|
2167
2217
|
? Number(r.last_valid_block_height)
|
|
2168
2218
|
: undefined,
|
|
2219
|
+
usageFrom: (_c = r.usage_from) !== null && _c !== void 0 ? _c : undefined,
|
|
2220
|
+
usageTo: (_d = r.usage_to) !== null && _d !== void 0 ? _d : undefined,
|
|
2169
2221
|
});
|
|
2170
2222
|
});
|
|
2171
2223
|
});
|