First deposit integration slice
This commit is contained in:
@@ -25,6 +25,7 @@ const observationSchema = z.object({
|
||||
height: z.number().int().positive().safe(), confirmations: z.number().int().positive().safe(),
|
||||
timestamp: z.number().int().nonnegative().safe(), unlockTime: z.string().regex(/^(0|[1-9]\d{0,19})$/),
|
||||
accountIndex: z.number().int().nonnegative().safe(), addressIndex: z.number().int().nonnegative().safe(),
|
||||
outputPublicKey: z.string().regex(/^[a-f0-9]{64}$/), globalOutputIndex: z.number().int().nonnegative().safe(),
|
||||
locked: z.boolean(), doubleSpendSeen: z.boolean(),
|
||||
}).strict();
|
||||
const MAX_SCAN_RANGE = 100_000;
|
||||
@@ -53,7 +54,8 @@ function digest(value: unknown): string {
|
||||
function rowDigest(observation: MoneroIncomingObservation): string {
|
||||
return digest([observation.observationId, observation.transactionId, observation.amountAtomicXmr,
|
||||
observation.height, observation.timestamp, observation.unlockTime,
|
||||
observation.accountIndex, observation.addressIndex, observation.locked, observation.doubleSpendSeen]);
|
||||
observation.accountIndex, observation.addressIndex, observation.outputPublicKey, observation.globalOutputIndex,
|
||||
observation.locked, observation.doubleSpendSeen]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +76,7 @@ export async function persistMoneroObservationScan(pool: Pool, input: PersistObs
|
||||
const ids = new Set<string>();
|
||||
for (const observation of observations) {
|
||||
await validateXmrAddress(observation.address);
|
||||
if (observation.observationId !== `${observation.transactionId}:${observation.accountIndex}:${observation.addressIndex}` ||
|
||||
if (observation.observationId !== `${observation.transactionId}:${observation.outputPublicKey}` ||
|
||||
BigInt(observation.amountAtomicXmr) > XMR_RPC_UINT64_MAX || observation.height < page.fromHeight ||
|
||||
observation.height > page.throughHeight || observation.confirmations !== page.walletHeight - observation.height + 1 ||
|
||||
(observation.locked && observation.confirmations <= 0)) throw new Error('Monero observation is inconsistent with its scan page');
|
||||
@@ -119,20 +121,22 @@ export async function persistMoneroObservationScan(pool: Pool, input: PersistObs
|
||||
const eventType = !current.rowCount ? 'seen' : !current.rows[0].currently_present ? 'reappeared'
|
||||
: current.rows[0].payload_digest !== payloadDigest ? 'changed' : null;
|
||||
await client.query(`INSERT INTO wk_custody.monero_transfer_observations(
|
||||
wallet_fingerprint,observation_id,txid,monero_address,account_index,address_index,amount_atomic_xmr,block_height,
|
||||
wallet_fingerprint,observation_id,txid,monero_address,account_index,address_index,output_public_key,global_output_index,
|
||||
amount_atomic_xmr,block_height,
|
||||
wallet_height,confirmations,timestamp,unlock_time,locked,double_spend_seen,payload_digest,
|
||||
currently_present,last_seen_scan_id,first_observed_at,last_observed_at)
|
||||
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,true,$16,$17,$17)
|
||||
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,true,$18,$19,$19)
|
||||
ON CONFLICT(wallet_fingerprint,observation_id) DO UPDATE SET
|
||||
monero_address=excluded.monero_address,
|
||||
output_public_key=excluded.output_public_key,global_output_index=excluded.global_output_index,
|
||||
amount_atomic_xmr=excluded.amount_atomic_xmr,block_height=excluded.block_height,wallet_height=excluded.wallet_height,
|
||||
confirmations=excluded.confirmations,timestamp=excluded.timestamp,unlock_time=excluded.unlock_time,
|
||||
locked=excluded.locked,double_spend_seen=excluded.double_spend_seen,payload_digest=excluded.payload_digest,
|
||||
currently_present=true,last_seen_scan_id=excluded.last_seen_scan_id,last_observed_at=excluded.last_observed_at`,
|
||||
[parsed.walletFingerprint, observation.observationId, observation.transactionId, observation.address,
|
||||
observation.accountIndex, observation.addressIndex, observation.amountAtomicXmr, observation.height, page.walletHeight,
|
||||
observation.confirmations, observation.timestamp, observation.unlockTime, observation.locked,
|
||||
observation.doubleSpendSeen, payloadDigest, parsed.scanId,
|
||||
observation.accountIndex, observation.addressIndex, observation.outputPublicKey, observation.globalOutputIndex,
|
||||
observation.amountAtomicXmr, observation.height, page.walletHeight, observation.confirmations,
|
||||
observation.timestamp, observation.unlockTime, observation.locked, observation.doubleSpendSeen, payloadDigest, parsed.scanId,
|
||||
current.rowCount ? Number(current.rows[0].first_observed_at) : parsed.scannedAt]);
|
||||
if (eventType) {
|
||||
await client.query(`INSERT INTO wk_custody.monero_observation_events
|
||||
|
||||
Reference in New Issue
Block a user