import { sql, type Selectable } from 'kysely'
import type * as Db from '../Db.js'
import type * as Schema from '../Schema.js'
/** Columns of the `routes_transfer_subsidies` table. */
export type Table = Schema.RoutesTransferSubsidy
/** A shared subsidy transaction and its billing owner. */
export type Record = Selectable
/** Serializes subsidy preparation for a source payment and returns its persisted settlement. */
export async function getForUpdateIn(
db: Db.Db,
options: getForUpdateIn.Options,
): Promise {
const key = JSON.stringify([
'routes-transfer-subsidy',
options.sourceChainId,
options.transactionRef,
])
await sql`SELECT pg_advisory_xact_lock(hashtextextended(${key}, 0))`.execute(db.kysely)
return db.kysely
.selectFrom('routes_transfer_subsidies')
.selectAll()
.where('sourceChainId', '=', options.sourceChainId)
.where('transactionRef', '=', options.transactionRef)
.executeTakeFirst()
}
export declare namespace getForUpdateIn {
/** Verified source execution identity. */
type Options = {
/** Source CAIP-2 chain. */
sourceChainId: string
/** Canonical source transaction reference. */
transactionRef: string
}
}