func LoadPayments(limit uint) []*Payment { rows, err := db.QueryAll(Payment{}, `SELECT `+PaymentModel.FieldsSimple+` FROM payment ORDER BY id DESC LIMIT ?`, limit, ) if err != nil { panic(err) } return rows.([]*Payment) }
// Loads payments associated with a given block(hash), // regardless of orphaned/spent status. func LoadPaymentsByBlockhash(blockhash string) []*Payment { rows, err := db.QueryAll(Payment{}, `SELECT `+PaymentModel.FieldsSimple+` FROM payment WHERE blockhash=?`, blockhash, ) if err != nil { panic(err) } return rows.([]*Payment) }
func LoadLastBlocks(coin string, n uint32) []*Block { rows, err := db.QueryAll(Block{}, `SELECT `+BlockModel.FieldsSimple+` FROM block WHERE coin=? AND (status=0 OR status=1 OR status=10) ORDER BY height DESC LIMIT ?`, coin, n, ) if err != nil { panic(err) } return rows.([]*Block) }
func LoadAPIKeysByUser(userId int64) []*APIKey { rows, err := db.QueryAll(APIKey{}, `SELECT `+APIKeyModel.FieldsSimple+` FROM auth_api_key WHERE user_id=?`, userId, ) if err != nil { panic(err) } return rows.([]*APIKey) }
func LoadAddressesByMPK(mpkId int64) []*Address { rows, err := db.QueryAll(Address{}, `SELECT `+AddressModel.FieldsSimple+` FROM address WHERE mpk_id=? ORDER BY (chain_path, chain_idx) ASC`, mpkId, ) if err != nil { panic(err) } return rows.([]*Address) }
func LoadSpendablePaymentsByAmount(mpkId int64, coin string, min, max uint64, reqHeight uint32, limit uint) []*Payment { rows, err := db.QueryAll(Payment{}, `SELECT `+PaymentModel.FieldsSimple+` FROM payment WHERE mpkId=? AND coin=? AND spent=0 AND orphaned=0 AND ?<=amount AND amount<=? AND blockheight>0 AND blockheight<=? ORDER BY amount ASC LIMIT ?`, mpkId, coin, min, max, reqHeight, limit, ) if err != nil { panic(err) } return rows.([]*Payment) }
func LoadAddressesByWallet(userId int64, wallet string) []*Address { rows, err := db.QueryAll(Address{}, `SELECT `+AddressModel.FieldsSimple+` FROM address WHERE user_id=? AND wallet=?`, userId, wallet, ) if err != nil { panic(err) } return rows.([]*Address) }
func LoadWithdrawals(limit uint) []*Withdrawal { rows, err := db.QueryAll(Withdrawal{}, `SELECT `+WithdrawalModel.FieldsSimple+` FROM account_withdrawal ORDER BY id DESC LIMIT ?`, limit, ) if err != nil { panic(err) } return rows.([]*Withdrawal) }
func LoadBalancesByWallet(userId int64, wallet string) []*Balance { rows, err := db.QueryAll(Balance{}, `SELECT `+BalanceModel.FieldsSimple+` FROM account_balance WHERE user_id=? AND wallet=?`, userId, wallet, ) if err != nil { panic(err) } return rows.([]*Balance) }
func LoadWithdrawalsByUser(userId int64, coin string, limit uint) []*Withdrawal { rows, err := db.QueryAll(Withdrawal{}, `SELECT `+WithdrawalModel.FieldsSimple+` FROM account_withdrawal WHERE user_id=? AND coin=? ORDER BY id DESC LIMIT ?`, userId, coin, limit, ) if err != nil { panic(err) } return rows.([]*Withdrawal) }
// This is for loading pending orders upon app init, // for orders that were saved but didn't go through the processor. // NOTE: don't try to add a limit // paginate here, unless you understand why this notice is here. func LoadPendingOrdersSince(basisCoin string, coin string, startOrderId int64) []*Order { rows, err := db.QueryAll(Order{}, `SELECT `+OrderModel.FieldsSimple+` FROM exchange_order WHERE basis_coin=? AND coin=? AND status=0 AND id>=? ORDER BY id ASC`, basisCoin, coin, startOrderId, ) if err != nil { panic(err) } return rows.([]*Order) }
func LoadPendingOrdersByUser(userId int64, basisCoin string, coin string) (orders []*Order) { rows, err := db.QueryAll(Order{}, `SELECT `+OrderModel.FieldsSimple+` FROM exchange_order WHERE status=0 AND user_id=? AND basis_coin=? AND coin=? ORDER BY price ASC`, userId, basisCoin, coin, ) if err != nil { panic(err) } return rows.([]*Order) }
func LoadDepositsByWalletAndCoin(userId int64, wallet string, coin string, limit uint) []*Deposit { rows, err := db.QueryAll(Deposit{}, `SELECT `+DepositModel.FieldsSimple+` FROM account_deposit WHERE user_id=? AND wallet=? AND coin=? ORDER BY time DESC LIMIT ?`, userId, wallet, coin, limit, ) if err != nil { panic(err) } return rows.([]*Deposit) }
func LoadPriceLogs(market string, interval int64, startTime int64, endTime int64) []*PriceLog { rows, err := db.QueryAll(PriceLog{}, `SELECT `+PriceLogModel.FieldsSimple+` FROM exchange_price_log WHERE market=? AND interval=? AND ?<=time AND time<? ORDER BY time ASC`, market, interval, startTime, endTime, ) if err != nil { panic(err) } return rows.([]*PriceLog) }
func LoadTradesByUser(userId int64, limit uint) []*Trade { rows, err := db.QueryAll(Trade{}, `SELECT `+TradeModel.FieldsSimple+` FROM exchange_trade WHERE (bid_user_id=? OR ask_user_id=?) ORDER BY time DESC LIMIT ?`, userId, userId, limit, ) if err != nil { panic(err) } return rows.([]*Trade) }
func LoadLastPriceLogs(market string, interval int64, limit int) []*PriceLog { rows, err := db.QueryAll(PriceLog{}, `SELECT `+PriceLogModel.FieldsSimple+` FROM exchange_price_log WHERE market=? AND interval=? ORDER BY time DESC LIMIT ?`, market, interval, limit, ) if err != nil { panic(err) } plogs := rows.([]*PriceLog) for i := 0; i < len(plogs)/2; i++ { plogs[i] = plogs[len(plogs)-1-i] } // time ASC order return plogs }
// See comment for LoadLimitBids. // To load the best asks, set minPrice to 0. func LoadLimitAsks(basisCoin string, coin string, limit int, minPrice float64, minId int64, maxId int64) (asks []*Order, hasMore bool) { rows, err := db.QueryAll(Order{}, `SELECT `+OrderModel.FieldsSimple+` FROM exchange_order WHERE basis_coin=? AND coin=? AND type='A' AND status=0 AND (price, id) > (?, ?) AND id<=? ORDER BY price ASC, id ASC LIMIT ?`, basisCoin, coin, minPrice, minId, maxId, limit+1, ) if err != nil { panic(err) } asks = rows.([]*Order) if len(asks) == limit+1 { return asks[:len(asks)-1], true } else { return asks, false } }
func LoadKnownAddresses(addrStrs []string) []*Address { if len(addrStrs) == 0 { return nil } var addrStrs_i []interface{} for _, addrStr := range addrStrs { addrStrs_i = append(addrStrs_i, addrStr) } // TODO: consider limitations on placeholder count. 65536? addrsPH := "?" + strings.Repeat(",?", len(addrStrs)-1) rows, err := db.QueryAll(Address{}, `SELECT `+AddressModel.FieldsSimple+` FROM address WHERE address in (`+addrsPH+`)`, addrStrs_i..., ) if err != nil { panic(err) } return rows.([]*Address) }