示例#1
0
	WALLET_RESERVED_WITHDRAWAL = "reserved_w"
	WALLET_SWEEP               = "sweep"
	WALLET_SWEEP_DRY           = "sweep_dry"
	WALLET_CHANGE              = "change"
)

// BALANCE

type Balance struct {
	UserId int64  `json:"userId"      db:"user_id"`
	Wallet string `json:"wallet"      db:"wallet"`
	Coin   string `json:"coin"        db:"coin"`
	Amount int64  `json:"amount"      db:"amount"`
}

var BalanceModel = db.GetModelInfo(new(Balance))

func SaveBalance(c db.MConn, balance *Balance) *Balance {
	_, err := c.Exec(
		`INSERT INTO account_balance (`+BalanceModel.FieldsInsert+`)
         VALUES (`+BalanceModel.Placeholders+`)`,
		balance,
	)
	if err != nil {
		panic(err)
	}
	return balance
}

// Adds or subtracts an amount to a user's wallet.
// nonnegative: panics with INSUFFICIENT_FUNDS_ERROR if resulting balance is negative.
示例#2
0
	. "ftnox.com/common"
	"ftnox.com/db"
	"strings"
	"time"
)

//////////// MPK
//////////// MPK

type MPK struct {
	Id     int64  `json:"id"       db:"id,autoinc"`
	PubKey string `json:"pubkey"   db:"pubkey"`
	Chain  string `json:"chain"    db:"chain"`
}

var MPKModel = db.GetModelInfo(new(MPK))

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
}

func SaveMPKIfNotExists(mpk *MPK) *MPK {
示例#3
0
	SaveBetaSignup(signup)

	ReturnJSON(API_OK, nil)
}

// MODELS

type BetaSignup struct {
	Id     int64  `json:"id"          db:"id,autoinc"`
	Body   string `json:"body"        db:"body"`
	Header string `json:"header"      db:"header"`
	Time   int64  `json:"time"        db:"time"`
}

var BetaSignupModel = db.GetModelInfo(new(BetaSignup))

func SaveBetaSignup(signup *BetaSignup) *BetaSignup {
	if signup.Time == 0 {
		signup.Time = time.Now().Unix()
	}
	_, err := db.Exec(
		`INSERT INTO beta_signup (`+BetaSignupModel.FieldsInsert+`)
         VALUES (`+BetaSignupModel.Placeholders+`)`,
		signup,
	)
	if err != nil {
		panic(err)
	}
	return signup
}
示例#4
0
	Amount         uint64  `json:"amount"          db:"amount"`
	Filled         uint64  `json:"filled"          db:"filled"`
	BasisCoin      string  `json:"basisCoin"       db:"basis_coin"`
	BasisAmount    uint64  `json:"basisAmount"     db:"basis_amount"`
	BasisFilled    uint64  `json:"basisFilled"     db:"basis_filled"`
	BasisFee       uint64  `json:"basisFee"        db:"basis_fee"`
	BasisFeeFilled uint64  `json:"basisFeeFilled"  db:"basis_fee_filled"`
	BasisFeeRatio  float64 `json:"basisFeeRatio"   db:"basis_fee_ratio"`
	Price          float64 `json:"price"           db:"price"`
	Status         uint32  `json:"status"          db:"status"`
	Cancel         bool    `json:"-"`
	Time           int64   `json:"time"            db:"time"`
	Updated        int64   `json:"updated"         db:"updated"`
}

var OrderModel = db.GetModelInfo(new(Order))

const (
	ORDER_TYPE_BID = "B"
	ORDER_TYPE_ASK = "A"

	ORDER_STATUS_PENDING = 0
	// ORDER_STATUS_INCOMPLETE = 1 (NOT USED, RESERVED)
	ORDER_STATUS_COMPLETE = 2
	ORDER_STATUS_CANCELED = 3
)

func (order *Order) Validate() {

	if 0 < order.Amount && order.Amount < order.Filled {
		panic(NewError("[order: %v] order.Amount < order.Filled", order.Id))
示例#5
0
type User struct {
	Id        int64  `json:"id"           db:"id,autoinc"`
	Email     string `json:"email"        db:"email"`
	EmailCode string `json:"-"            db:"email_code"`
	EmailConf int32  `json:"-"            db:"email_conf"`
	Password  string `json:"-"`
	Scrypt    []byte `json:"-"            db:"scrypt"`
	Salt      []byte `json:"-"            db:"salt"`
	TOTPKey   []byte `json:"-"            db:"totp_key"`
	TOTPConf  int32  `json:"totpConf"     db:"totp_conf"`
	ChainIdx  int32  `json:"-"            db:"chain_idx"`
	Roles     string `json:"roles"        db:"roles"`
}

var UserModel = db.GetModelInfo(new(User))

func (user *User) HasRole(role string) bool {
	roles := strings.Split(user.Roles, ",")
	for _, rl := range roles {
		if role == rl {
			return true
		}
	}
	return false
}

func (user *User) Authenticate(password string) bool {
	// Scrypt the password.
	scryptPassword, err := scrypt.Key([]byte(password), user.Salt, 16384, 8, 1, 32)
	if err != nil {
示例#6
0
// so we know why the input was spent.
type WithdrawalTx struct {
	Id         int64  `json:"id"           db:"id,autoinc"`
	Type       string `json:"type"         db:"type"`
	Coin       string `json:"coin"         db:"coin"`
	FromMPKId  int64  `json:"fromMPKId"    db:"from_mpk_id,null"`
	ToMPKId    int64  `json:"toMPKId"      db:"to_mpk_id,null"`
	Amount     uint64 `json:"amount"       db:"amount"`
	MinerFee   uint64 `json:"minerFee"     db:"miner_fee"`
	ChgAddress string `json:"chgAddress"   db:"chg_address"`
	RawTx      string `json:"rawTx"        db:"raw_tx"`
	TxId       string `json:"txId"         db:"tx_id"`
	Time       int64  `json:"time"         db:"time"`
}

var WithdrawalTxModel = db.GetModelInfo(new(WithdrawalTx))

const (
	WITHDRAWAL_TX_TYPE_WITHDRAWAL = "W" // user withdrawal
	WITHDRAWAL_TX_TYPE_SWEEP      = "S" // e.g. from hot to cold wallet, etc.
)

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,
示例#7
0
package email

import (
	"ftnox.com/db"
)

// NOT USED YET
type OutgoingEmail struct {
	MessageID string `db:"message_id"`
	From      string `db:"from_"`
	To        string `db:"to_"`
	Subject   string `db:"subject"`
	BodyPlain string `db:"body_plain"`

	TimeSent uint64 `db:"time_sent"`
	Error    string `db:"error"`
}

var OutgoingEmailModel = db.GetModelInfo(new(OutgoingEmail))

func SaveOutgoingEmail(email *OutgoingEmail) *OutgoingEmail {
	// TODO
	return nil
}