示例#1
0
func SaveMPK(mpk *MPK) *MPK {
	err := db.QueryRow(
		`INSERT INTO mpk (`+MPKModel.FieldsInsert+`)
         VALUES (`+MPKModel.Placeholders+`)
         RETURNING id`,
		mpk,
	).Scan(&mpk.Id)
	if err != nil {
		panic(err)
	}
	return mpk
}
示例#2
0
func GetMaxAddressIndex(coin string, mpkId int64, chainPath string) int32 {
	var countNull sql.NullInt64
	err := db.QueryRow(
		`SELECT max(chain_idx)
         FROM address
         WHERE coin=? AND mpk_id=? AND chain_path=?`,
		coin, mpkId, chainPath,
	).Scan(&countNull)
	if err != nil {
		panic(err)
	}
	return int32(countNull.Int64)
}
示例#3
0
func SaveWithdrawalTx(wth *WithdrawalTx) *WithdrawalTx {
	if wth.Time == 0 {
		wth.Time = time.Now().Unix()
	}
	err := db.QueryRow(
		`INSERT INTO withdrawal_tx (`+WithdrawalTxModel.FieldsInsert+`)
         VALUES (`+WithdrawalTxModel.Placeholders+`)
         RETURNING id`,
		wth,
	).Scan(&wth.Id)
	if err != nil {
		panic(err)
	}
	return wth
}
示例#4
0
func LoadOrder(id int64) *Order {
	var order Order
	err := db.QueryRow(
		`SELECT `+OrderModel.FieldsSimple+`
         FROM exchange_order
         WHERE id=?`, id,
	).Scan(&order)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &order
	default:
		panic(err)
	}
}
示例#5
0
func LoadMPKByPubKey(pubKey string) *MPK {
	var mpk MPK
	err := db.QueryRow(
		`SELECT `+MPKModel.FieldsSimple+`
         FROM mpk WHERE pubkey=?`,
		pubKey,
	).Scan(&mpk)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &mpk
	default:
		panic(err)
	}
}
示例#6
0
func Get(key string) string {
	var value string
	err := db.QueryRow(
		`SELECT value
         FROM kvstore WHERE key_=?`,
		key,
	).Scan(&value)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return ""
	case nil:
		return value
	default:
		panic(err)
	}
}
示例#7
0
func LoadBlockAtHeight(coin string, height uint32) *Block {
	var block Block
	err := db.QueryRow(
		`SELECT `+BlockModel.FieldsSimple+`
         FROM block WHERE coin=? AND height=? AND (status=0 OR status=1 OR status=10)`,
		coin, height,
	).Scan(&block)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &block
	default:
		panic(err)
	}
}
示例#8
0
func LoadBlock(hash string) *Block {
	var block Block
	err := db.QueryRow(
		`SELECT `+BlockModel.FieldsSimple+`
         FROM block WHERE hash=?`,
		hash,
	).Scan(&block)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &block
	default:
		panic(err)
	}
}
示例#9
0
func LoadMPK(mpkId int64) *MPK {
	var mpk MPK
	err := db.QueryRow(
		`SELECT `+MPKModel.FieldsSimple+`
         FROM mpk WHERE id=?`,
		mpkId,
	).Scan(&mpk)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &mpk
	default:
		panic(err)
	}
}
示例#10
0
func LoadPaymentByTxId(txId string, vout uint32) *Payment {
	var payment Payment
	err := db.QueryRow(
		`SELECT `+PaymentModel.FieldsSimple+` FROM payment
         WHERE tx_id=? AND vout=?`,
		txId, vout,
	).Scan(&payment)
	switch err {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &payment
	default:
		panic(err)
	}
}
示例#11
0
func LoadAddress(address string) *Address {
	var addr Address
	err := db.QueryRow(
		`SELECT `+AddressModel.FieldsSimple+`
         FROM address
         WHERE address=?`,
		address,
	).Scan(&addr)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &addr
	default:
		panic(err)
	}
}
示例#12
0
// Gets the last executed order id, or 0 if none.
func LastCompletedOrderId(basisCoin string, coin string) int64 {
	var lastCompletedOrderId int64
	err := db.QueryRow(
		`SELECT id FROM exchange_order
         WHERE basis_coin=? AND coin=? AND status=3
         ORDER BY id DESC limit 1`,
		basisCoin, coin,
	).Scan(&lastCompletedOrderId)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return 0
	case nil:
		return lastCompletedOrderId
	default:
		panic(err)
	}
}
示例#13
0
func LoadLastAddressByWallet(userId int64, wallet string, coin string) *Address {
	var addr Address
	err := db.QueryRow(
		`SELECT `+AddressModel.FieldsSimple+`
         FROM address
         WHERE user_id=? AND wallet=? AND coin=?
         ORDER BY chain_idx DESC LIMIT 1`,
		userId, wallet, coin,
	).Scan(&addr)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &addr
	default:
		panic(err)
	}
}
示例#14
0
func LoadUserByEmail(email string) *User {
	var user User
	err := db.QueryRow(
		`SELECT `+UserModel.FieldsSimple+`
         FROM auth_user WHERE email=?`,
		email,
	).Scan(
		&user,
	)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &user
	default:
		panic(err)
	}
}
示例#15
0
func LoadUser(userId int64) *User {
	var user User
	err := db.QueryRow(
		`SELECT `+UserModel.FieldsSimple+`
         FROM auth_user WHERE id=?`,
		userId,
	).Scan(
		&user,
	)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &user
	default:
		panic(err)
	}
}
示例#16
0
func LoadAPIKey(key string) *APIKey {
	var apiKey APIKey
	err := db.QueryRow(
		`SELECT `+APIKeyModel.FieldsSimple+`
         FROM auth_api_key WHERE key=?`,
		key,
	).Scan(
		&apiKey,
	)
	switch db.GetErrorType(err) {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &apiKey
	default:
		panic(err)
	}
}
示例#17
0
func LoadLargestSpendablePaymentLessThan(mpkId int64, coin string, amount uint64, reqHeight uint32, exclude []*Payment) *Payment {
	excludeIds := Map(exclude, "Id")
	if len(excludeIds) == 0 {
		excludeIds = []interface{}{-1}
	} // hack
	var payment Payment
	err := db.QueryRow(
		`SELECT `+PaymentModel.FieldsSimple+`
         FROM payment WHERE
         mpk_id=? AND coin=? AND spent=0 AND orphaned=0 AND amount<=? AND blockheight>0 AND blockheight<=?
         AND id NOT IN (`+Placeholders(len(excludeIds))+`)`,
		append([]interface{}{mpkId, coin, amount, reqHeight}, excludeIds...)...).Scan(&payment)
	switch err {
	case sql.ErrNoRows:
		return nil
	case nil:
		return &payment
	default:
		panic(err)
	}
}