Documentation ¶
Index ¶
Constants ¶
View Source
const ( // CreateFeeKeysTable creates the fee_keys table, which is a small table that // is used as a persistent child key counter for master extended public key. CreateFeeKeysTable = `CREATE TABLE IF NOT EXISTS %s ( key_hash BYTEA PRIMARY KEY, -- UNIQUE INDEX child INT8 DEFAULT 0 );` // CreateAccountsTable creates the account table. CreateAccountsTable = `CREATE TABLE IF NOT EXISTS %s ( account_id BYTEA PRIMARY KEY, -- UNIQUE INDEX pubkey BYTEA );` CreateBondsTableV0 = `` /* 241-byte string literal not displayed */ CreateBondsTable = CreateBondsTableV0 CreateBondsAcctIndexV0 = `CREATE INDEX IF NOT EXISTS %s ON %s (account_id);` CreateBondsAcctIndex = CreateBondsAcctIndexV0 CreateBondsLockTimeIndexV0 = `CREATE INDEX IF NOT EXISTS %s ON %s (lock_time);` CreateBondsLockTimeIndex = CreateBondsLockTimeIndexV0 CreateBondsCoinIDIndexV0 = `CREATE INDEX IF NOT EXISTS %s ON %s (bond_coin_id, asset_id);` CreateBondsCoinIDIndex = CreateBondsCoinIDIndexV0 AddBond = `` /* 128-byte string literal not displayed */ DeleteBond = `DELETE FROM %s WHERE bond_coin_id = $1 AND asset_id = $2;` SelectActiveBondsForUser = `` /* 141-byte string literal not displayed */ // InsertKeyIfMissing creates an entry for the specified key hash, if it // doesn't already exist. InsertKeyIfMissing = `INSERT INTO %s (key_hash) VALUES ($1) ON CONFLICT (key_hash) DO NOTHING RETURNING child;` CurrentKeyIndex = `SELECT child FROM %s WHERE key_hash = $1;` SetKeyIndex = `UPDATE %s SET child = $1 WHERE key_hash = $2;` UpsertKeyIndex = `INSERT INTO %s (child, key_hash) VALUES ($1, $2) ON CONFLICT (key_hash) DO UPDATE SET child = $1;` // CloseAccount sets the broken_rule column for the account, which signifies // that the account is closed. CloseAccount = `UPDATE %s SET broken_rule = $1 WHERE account_id = $2;` // SelectAccount gathers account details for the specified account ID. SelectAccount = `SELECT pubkey FROM %s WHERE account_id = $1;` // SelectAccountInfo retrieves all fields for an account. SelectAccountInfo = `SELECT account_id, pubkey FROM %s WHERE account_id = $1;` CreateAccountForBond = `INSERT INTO %s (account_id, pubkey) VALUES ($1, $2);` CreatePrepaidBondsTable = `CREATE TABLE IF NOT EXISTS %s ( coin_id BYTEA PRIMARY KEY, version INT2 DEFAULT 0, strength int4, lock_time INT8 );` SelectPrepaidBond = `SELECT strength, lock_time FROM %s WHERE coin_id = $1;` DeletePrepaidBond = `DELETE FROM %s WHERE coin_id = $1;` InsertPrepaidBond = `INSERT INTO %s (coin_id, strength, lock_time) VALUES ($1, $2, $3);` )
View Source
const ( // CreateEpochsTable creates a table specified via the %s printf specifier // for epoch data. CreateEpochsTable = `` /* 491-byte string literal not displayed */ // InsertEpoch inserts the epoch's match proof data into the epoch table. InsertEpoch = `INSERT INTO %s (epoch_idx, epoch_dur, match_time, csum, seed, revealed, missed) VALUES ($1, $2, $3, $4, $5, $6, $7);` SelectLastEpochRate = `SELECT end_rate FROM %s ORDER BY epoch_end DESC LIMIT 1;` // CreateEpochReportTable creates an epoch_reports table that holds // epoch-end reports that can be used to construct market history data sets. CreateEpochReportTable = `` /* 1033-byte string literal not displayed */ // InsertEpochReport inserts a row into the epoch_reports table. InsertEpochReport = `` /* 265-byte string literal not displayed */ InsertPartialEpochReport = `` /* 297-byte string literal not displayed */ // SelectEpochCandles selects all rows from the epoch_reports table sorted // by ascending time. SelectEpochCandles = `` /* 157-byte string literal not displayed */ // CreateEpochReportTable creates an candles table that holds binned // candle data. CreateCandlesTable = `` /* 177-byte string literal not displayed */ InsertCandle = `` /* 280-byte string literal not displayed */ SelectCandles = `` /* 129-byte string literal not displayed */ SelectLastEndStamp = `SELECT (end_stamp) FROM %s ORDER BY end_stamp DESC LIMIT 1;` )
View Source
const ( // CreateMarketsTable creates the DEX's "markets" table, which indicates // which markets are currently recognized by the DEX, and their configured // lot sizes. This tables should be created in the public schema. This // information is stored in a table to facilitate the addition and removal // of markets, plus market lot size changes, without having to assume that // whatever is specified in a config file is accurately reflected by the DB // tables. CreateMarketsTable = `CREATE TABLE IF NOT EXISTS %s ( name TEXT PRIMARY KEY, base INT8, quote INT8, lot_size INT8 )` // SelectAllMarkets retrieves the active market information. SelectAllMarkets = `SELECT name, base, quote, lot_size FROM %s;` // InsertMarket inserts a new market in to the markets tables InsertMarket = `INSERT INTO %s (name, base, quote, lot_size) VALUES ($1, $2, $3, $4);` // UpdateLotSize updates the market's lot size. UpdateLotSize = `UPDATE %s SET lot_size = $2 WHERE name = $1;` )
View Source
const ( // CreateMatchesTable creates the matches table for storing data related to // a match and the related swap. This only includes trade matches, not // cancel order matches that just remove one order from the book (and change // the target order status in the orders table). // // The takerSell column indicates the asset of the address and coinID // columns for both maker and taker. Sell refers to sell of the base asset, // and the opposite is implied for the counterparty (makerSell = !takerSell) // // takerSell | takerAddress | aContractCoinID | aRedeemCoinID || (makerSell) | makerAddress | bContractCoinID | bRedeemCoinID // --------------------------------------------------------------------------------------------------------------------------------- // true (B->Q) | quote | base | quote || false (Q->B) | base | quote | base // false (Q->B) | base | quote | base || true (B->Q) | quote | base | quote CreateMatchesTable = `` /* 1995-byte string literal not displayed */ RetrieveMatchStatsByEpoch = `SELECT quantity, rate, takerSell FROM %s WHERE takerSell IS NOT NULL AND epochIdx = $1 AND epochDur = $2;` RetrieveSwapData = `` /* 301-byte string literal not displayed */ InsertMatch = `` /* 272-byte string literal not displayed */ UpsertMatch = InsertMatch + ` ON CONFLICT (matchid) DO UPDATE SET quantity = $11, status = $15;` InsertCancelMatch = `` /* 365-byte string literal not displayed */ UpsertCancelMatch = InsertCancelMatch + ` ON CONFLICT (matchid) DO NOTHING;` RetrieveMatchByID = `` /* 213-byte string literal not displayed */ RetrieveUserMatches = `` /* 240-byte string literal not displayed */ RetrieveActiveUserMatches = `` /* 247-byte string literal not displayed */ RetrieveMarketMatches = `` /* 356-byte string literal not displayed */ RetrieveActiveMarketMatches = `` /* 351-byte string literal not displayed */ // RetrieveActiveMarketMatchesExtended combines RetrieveSwapData with // RetrieveActiveMarketMatches. RetrieveActiveMarketMatchesExtended = `` /* 546-byte string literal not displayed */ // CompletedOrAtFaultMatchesLastN retrieves inactive matches for a user that // are either successfully completed by the user (MatchComplete or // MakerRedeemed with user as maker), or failed because of this user's // inaction. Note that the literal status values used in this query MUST BE // UPDATED if the order.OrderStatus enum is changed. CompletedOrAtFaultMatchesLastN = `` /* 1151-byte string literal not displayed */ UserMatchFails = `` /* 742-byte string literal not displayed */ ForgiveMatchFail = `UPDATE %s SET forgiven = TRUE WHERE matchid = $1 AND NOT active;` SetMakerMatchAckSig = `UPDATE %s SET sigMatchAckMaker = $2 WHERE matchid = $1;` SetTakerMatchAckSig = `UPDATE %s SET sigMatchAckTaker = $2 WHERE matchid = $1;` SetInitiatorSwapData = `UPDATE %s SET status = $2, aContractCoinID = $3, aContract = $4, aContractTime = $5 WHERE matchid = $1;` SetParticipantSwapData = `UPDATE %s SET status = $2, bContractCoinID = $3, bContract = $4, bContractTime = $5 WHERE matchid = $1;` SetParticipantContractAuditSig = `UPDATE %s SET bSigAckOfAContract = $2 WHERE matchid = $1;` SetInitiatorContractAuditSig = `UPDATE %s SET aSigAckOfBContract = $2 WHERE matchid = $1;` SetInitiatorRedeemData = `UPDATE %s SET status = $2, aRedeemCoinID = $3, aRedeemSecret = $4, aRedeemTime = $5 WHERE matchid = $1;` SetParticipantRedeemData = `UPDATE %s SET status = $2, bRedeemCoinID = $3, bRedeemTime = $4, active = FALSE WHERE matchid = $1;` SetParticipantRedeemAckSig = `UPDATE %s SET bSigAckOfARedeem = $2 WHERE matchid = $1;` SetSwapDone = `UPDATE %s SET active = FALSE -- leave forgiven NULL WHERE matchid = $1;` SetSwapDoneForgiven = `UPDATE %s SET active = FALSE, forgiven = TRUE WHERE matchid = $1;` SelectMatchStatuses = `` /* 292-byte string literal not displayed */ )
View Source
const ( // CreateMetaTable creates a table to hold DEX metadata. This query has a %s // specifier for "meta" / metaTableName so it can work with createTable. CreateMetaTable = `CREATE TABLE IF NOT EXISTS %s ( schema_version INT4 DEFAULT 0 );` // CreateMetaRow creates the single row of the meta table. CreateMetaRow = "INSERT INTO meta DEFAULT VALUES;" SelectDBVersion = `SELECT schema_version FROM meta;` SetDBVersion = `UPDATE meta SET schema_version = $1;` )
View Source
const ( // CreateOrdersTable creates a table specified via the %s printf specifier // for market and limit orders. CreateOrdersTable = `` /* 520-byte string literal not displayed */ // InsertOrder inserts a market or limit order into the specified table. InsertOrder = `` /* 255-byte string literal not displayed */ // SelectOrder retrieves all columns with the given order ID. This may be // used for any table with an "oid" column (orders_active, cancels_archived, // etc.). SelectOrder = `` /* 150-byte string literal not displayed */ SelectOrdersByStatus = `` /* 145-byte string literal not displayed */ PreimageResultsLastN = `` /* 292-byte string literal not displayed */ // SelectUserOrders retrieves all columns of all orders for the given // account ID. SelectUserOrders = `` /* 157-byte string literal not displayed */ // SelectUserOrderStatuses retrieves the order IDs and statuses of all orders // for the given account ID. Only applies to market and limit orders. SelectUserOrderStatuses = `SELECT oid, status FROM %s WHERE account_id = $1;` // SelectUserOrderStatusesByID retrieves the order IDs and statuses of the // orders with the provided order IDs for the given account ID. Only applies // to market and limit orders. SelectUserOrderStatusesByID = `SELECT oid, status FROM %s WHERE account_id = $1 AND oid = ANY($2);` // SelectCanceledUserOrders gets the ID of orders that were either canceled // by the user or revoked/canceled by the server, but these statuses can be // set by the caller. Note that revoked orders can be market or immediate // limit orders that failed to swap. SelectCanceledUserOrders = `` /* 306-byte string literal not displayed */ // SelectOrderByCommit retrieves the order ID for any order with the given // commitment value. This applies to the cancel order tables as well. SelectOrderByCommit = `SELECT oid FROM %s WHERE commit = $1;` // SelectOrderPreimage retrieves the preimage for the order ID; SelectOrderPreimage = `SELECT preimage FROM %s WHERE oid = $1;` // SelectOrderCoinIDs retrieves the order id, sell flag, and coins for all // orders in a certain table. SelectOrderCoinIDs = `SELECT oid, sell, coins FROM %s;` SetOrderPreimage = `UPDATE %s SET preimage = $1 WHERE oid = $2;` SetOrderCompleteTime = `UPDATE %s SET complete_time = $1 WHERE oid = $2;` RetrieveCompletedOrdersForAccount = `` /* 143-byte string literal not displayed */ // UpdateOrderStatus sets the status of an order with the given order ID. UpdateOrderStatus = `UPDATE %s SET status = $1 WHERE oid = $2;` // UpdateOrderFilledAmt sets the filled amount of an order with the given // order ID. UpdateOrderFilledAmt = `UPDATE %s SET filled = $1 WHERE oid = $2;` // UpdateOrderStatusAndFilledAmt sets the order status and filled amount of // an order with the given order ID. UpdateOrderStatusAndFilledAmt = `UPDATE %s SET status = $1, filled = $2 WHERE oid = $3;` // OrderStatus retrieves the order type, status, and filled amount for an // order with the given order ID. This only applies to market and limit // orders. For cancel orders, which lack a type and filled column, use // CancelOrderStatus. OrderStatus = `SELECT type, status, filled FROM %s WHERE oid = $1;` // MoveOrder moves an order row from one table to another (e.g. // orders_active to orders_archived), while updating the order's status and // filled amounts. // For example, // WITH moved AS ( -- temporary table // DELETE FROM dcrdex.dcr_btc.orders_active -- origin table (%s) // WHERE oid = '\xDEADBEEF' -- the order to move ($1) // RETURNING // oid, // type, // sell, // account_id, // address, // client_time, // server_time, // commit, // coins, // quantity, // rate, // force, // 2, -- new status (%d) // 123456789, -- new filled (%d) // epoch_idx, epoch_dur, preimage, complete_time // ) // INSERT INTO dcrdex.dcr_btc.orders_archived -- destination table (%s) // SELECT * FROM moved; MoveOrder = `` /* 267-byte string literal not displayed */ PurgeBook = `` /* 435-byte string literal not displayed */ // CreateCancelOrdersTable creates a table specified via the %s printf // specifier for cancel orders. CreateCancelOrdersTable = `` /* 624-byte string literal not displayed */ SelectCancelOrder = `SELECT oid, account_id, client_time, server_time, commit, target_order, status FROM %s WHERE oid = $1;` SelectCancelOrdersByStatus = `SELECT account_id, client_time, server_time, commit, target_order FROM %s WHERE status = $1;` CancelPreimageResultsLastN = `` /* 392-byte string literal not displayed */ // SelectRevokeCancels retrieves server-initiated cancels (revokes). SelectRevokeCancels = `` /* 164-byte string literal not displayed */ // RetrieveCancelsForUserByStatus gets matched cancel orders by user and // status, where status should be orderStatusExecuted. This query may be // followed by a SELECT of match_time from the epochs table for the epoch // IDs (idx:dur) returned by this query. In general, this query will be used // on a market's archived cancels table, which includes matched cancels. RetrieveCancelsForUserByStatus = `` /* 135-byte string literal not displayed */ // RetrieveCancelTimesForUserByStatus is similar to // RetrieveCancelsForUserByStatus, but it joins on an epochs table to get // the match_time directly instead of the epoch_idx and epoch_dur. The // cancels table, with full market schema, is %[1]s, while the epochs table // is %[2]s. RetrieveCancelTimesForUserByStatus = `` /* 273-byte string literal not displayed */ // InsertCancelOrder inserts a cancel order row into the specified table. InsertCancelOrder = `` /* 176-byte string literal not displayed */ // CancelOrderStatus retrieves an order's status CancelOrderStatus = `SELECT status FROM %s WHERE oid = $1;` // MoveCancelOrder, like MoveOrder, moves an order row from one table to // another. However, for a cancel order, only status column is updated. MoveCancelOrder = `` /* 330-byte string literal not displayed */ )
View Source
const ( // IndexExists checks if an index with a given name in certain namespace // (schema) exists. IndexExists = `SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relname = $1 AND n.nspname = $2;` // IndexIsUnique checks if an index with a given name in certain namespace // (schema) exists, and is a UNIQUE index. IndexIsUnique = `` /* 175-byte string literal not displayed */ // RetrieveSysSettingsConfFile retrieves system settings that are set by a // configuration file. RetrieveSysSettingsConfFile = `` /* 126-byte string literal not displayed */ // RetrieveSysSettingsServer retrieves system settings related to the // postgres server configuration. RetrieveSysSettingsServer = `` /* 354-byte string literal not displayed */ // RetrieveSysSettingsPerformance retrieves postgres performance-related // settings. RetrieveSysSettingsPerformance = `` /* 921-byte string literal not displayed */ // RetrieveSyncCommitSetting retrieves just the synchronous_commit setting. RetrieveSyncCommitSetting = `SELECT setting FROM pg_settings WHERE name='synchronous_commit';` // RetrievePGVersion retrieves the version string from the database process. RetrievePGVersion = `SELECT version();` // CreateSchema creates a database schema. CreateSchema = `CREATE SCHEMA IF NOT EXISTS %s;` )
The following queries retrieve various system settings and other system information from the database server.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.