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 a 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 = `` /* 199-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;`

	// IncrementKey increments the child counter and returns the new value.
	IncrementKey = `UPDATE %s
		SET child = child + 1
		WHERE key_hash = $1
		RETURNING child;`

	// 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. The
	// details returned from this query are sufficient to determine 1) whether the
	// registration fee has been paid, or 2) whether the account has been closed.
	SelectAccount = `SELECT pubkey, fee_coin, broken_rule
		FROM %s
		WHERE account_id = $1;`

	// SelectAllAccounts retrieves all accounts.
	SelectAllAccounts = `SELECT * FROM %s;`

	// SelectAccountInfo retrieves all fields for an account.
	SelectAccountInfo = `SELECT * FROM %s
		WHERE account_id = $1;`

	// CreateAccount creates an entry for a new account.
	CreateAccount = `INSERT INTO %s (account_id, pubkey, fee_address)
		VALUES ($1, $2, $3);`

	// SelectRegAddress fetches the registration fee address for the account.
	SelectRegAddress = `SELECT fee_address FROM %s WHERE account_id = $1;`

	// SetRegOutput sets the registration fee payment transaction details for the
	// account.
	SetRegOutput = `UPDATE %s SET
		fee_coin = $1
		WHERE account_id = $2;`
)
View Source
const (
	// CreateEpochsTable creates a table specified via the %s printf specifier
	// for epoch data.
	CreateEpochsTable = `` /* 491-byte string literal not displayed */

	InsertEpoch = `INSERT INTO %s (epoch_idx, epoch_dur, match_time, csum, seed, revealed, missed)
		VALUES ($1, $2, $3, $4, $5, $6, $7);`
)
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 INT2,
		quote INT2,
		lot_size INT8
	)`

	// SelectAllMarkets retrieves the active market information.
	SelectAllMarkets = `SELECT * 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);`
)
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 */

	AddMatchesForgivenColumn = `ALTER TABLE %s
		ADD COLUMN IF NOT EXISTS forgiven BOOL;`

	RetrieveSwapData = `` /* 301-byte string literal not displayed */

	InsertMatch = ``

	// do not terminate with ;
	/* 272-byte string literal not displayed */

	UpsertMatch = InsertMatch + ` ON CONFLICT (matchid) DO
	UPDATE SET quantity = $11, status = $15;`

	InsertCancelMatch = ``

	// status should be MatchComplete although there is no swap
	/* 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 */

	// 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 */

	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
		WHERE matchid = $1;`

	SelectMatchStatuses = `` /* 217-byte string literal not displayed */

)
View Source
const (
	// CreateMetaTable creates a table to hold DEX metadata.
	CreateMetaTable = `CREATE TABLE IF NOT EXISTS %s (
		state_hash BYTEA -- hash of the swapper state file
	);`

	// CreateMetaRow creates the single row of the meta table.
	CreateMetaRow = "INSERT INTO meta DEFAULT VALUES;"

	// RetrieveStateHash retrieves the last stored swap state file hash.
	RetrieveStateHash = "SELECT state_hash FROM meta;"

	// SetStateHash sets the hash of the swap state file.
	SetStateHash = "UPDATE meta SET state_hash = $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 = ``

	// no ;
	/* 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 = ``

	// The matchTime is when the order was booked, not canceled!!!
	/* 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 = `` /* 534-byte string literal not displayed */

	SelectCancelOrder = `SELECT oid, account_id, client_time, server_time,
		commit, target_order, status
	FROM %s WHERE oid = $1;`

	CancelPreimageResultsLastN = ``

	// no ;
	/* 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 = ``

	// NOTE: find revoked orders via SelectRevokeCancels
	/* 262-byte string literal not displayed */

	// InsertCancelOrder inserts a cancel order row into the specified table.
	InsertCancelOrder = `` /* 157-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 = `` /* 202-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.