本文整理汇总了Golang中github.com/skycoin/skycoin-exchange/src/server/engine.Exchange.GetAccount方法的典型用法代码示例。如果您正苦于以下问题:Golang Exchange.GetAccount方法的具体用法?Golang Exchange.GetAccount怎么用?Golang Exchange.GetAccount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skycoin/skycoin-exchange/src/server/engine.Exchange
的用法示例。
在下文中一共展示了Exchange.GetAccount方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetAccountBalance
// GetBalance return balance of specific account.
func GetAccountBalance(ee engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
rlt := &pp.EmptyRes{}
for {
req := pp.GetAccountBalanceReq{}
if err := c.BindJSON(&req); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
// validate pubkey
pubkey := req.GetPubkey()
if err := validatePubkey(pubkey); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongPubkey)
break
}
a, err := ee.GetAccount(pubkey)
if err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_NotExits)
break
}
bal := a.GetBalance(req.GetCoinType())
bres := pp.GetAccountBalanceRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
Balance: &pp.Balance{Amount: pp.PtrUint64(bal)},
}
return c.SendJSON(&bres)
}
return c.Error(rlt)
}
}
示例2: GetNewAddress
// GetNewAddress account create new address for depositing.
func GetNewAddress(ee engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
rlt := &pp.EmptyRes{}
for {
req := pp.GetDepositAddrReq{}
if err := c.BindJSON(&req); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
// validate pubkey
pubkey := req.GetPubkey()
if err := validatePubkey(pubkey); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongPubkey)
break
}
at, err := ee.GetAccount(pubkey)
if err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_NotExits)
break
}
ct := req.GetCoinType()
// get the new address for depositing
addr := ee.GetNewAddress(ct)
// add the new address to engin for watching it's utxos.
at.AddDepositAddress(ct, addr)
ee.WatchAddress(ct, addr)
ds := pp.GetDepositAddrRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
CoinType: req.CoinType,
Address: &addr,
}
return c.SendJSON(&ds)
}
return c.Error(rlt)
}
}
示例3: UpdateCredit
// UpdateCredit update credit.
func UpdateCredit(ee engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
var rlt *pp.EmptyRes
for {
req := pp.UpdateCreditReq{}
if err := c.BindJSON(&req); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
// validate the dst pubkey.
dstPubkey := req.GetDst()
if err := validatePubkey(dstPubkey); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongPubkey)
break
}
// get account.
a, err := ee.GetAccount(dstPubkey)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongPubkey)
break
}
// get coin type.
if err := a.SetBalance(req.GetCoinType(), req.GetAmount()); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
ee.SaveAccount()
res := pp.UpdateCreditRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
}
return c.SendJSON(&res)
}
return c.Error(rlt)
}
}
示例4: getWithdrawReqParams
func getWithdrawReqParams(c *sknet.Context, ee engine.Exchange) (*ReqParams, error) {
rp := NewReqParams()
req := pp.WithdrawalReq{}
if err := c.BindJSON(&req); err != nil {
return nil, err
}
// validate pubkey
pubkey := req.GetPubkey()
if err := validatePubkey(pubkey); err != nil {
return nil, err
}
a, err := ee.GetAccount(pubkey)
if err != nil {
return nil, err
}
rp.Values["account"] = a
rp.Values["cointype"] = req.GetCoinType()
rp.Values["amt"] = req.GetCoins()
rp.Values["outAddr"] = req.GetOutputAddress()
return rp, nil
}
示例5: CreateOrder
// CreateOrder create specifc order.
func CreateOrder(egn engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
rlt := &pp.EmptyRes{}
req := &pp.OrderReq{}
for {
if err := c.BindJSON(req); err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
logger.Error(err.Error())
break
}
// validate pubkey
pubkey := req.GetPubkey()
if err := validatePubkey(pubkey); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongPubkey)
break
}
// get order type
op, err := order.TypeFromStr(req.GetType())
if err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
logger.Error(err.Error())
break
}
// find the account
acnt, err := egn.GetAccount(pubkey)
if err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongPubkey)
logger.Error(err.Error())
break
}
cp, bal, err := needBalance(op, req)
if err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
logger.Error(err.Error())
break
}
if acnt.GetBalance(cp) < bal {
err := fmt.Errorf("%s balance is not sufficient", cp)
rlt = pp.MakeErrRes(err)
logger.Debug(err.Error())
break
}
var success bool
if op == order.Bid {
defer func() {
if success {
egn.SaveAccount()
} else {
acnt.IncreaseBalance(cp, bal)
}
}()
// decrease the balance, in case of double use the coins.
logger.Info("account:%s decrease %s:%d", acnt.GetID(), cp, bal)
if err := acnt.DecreaseBalance(cp, bal); err != nil {
rlt = pp.MakeErrRes(err)
logger.Error(err.Error())
break
}
}
odr := order.New(pubkey, op, req.GetPrice(), req.GetAmount())
oid, err := egn.AddOrder(req.GetCoinPair(), *odr)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
success = true
logger.Info(fmt.Sprintf("new %s order:%d", op, oid))
res := pp.OrderRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
OrderId: &oid,
}
return c.SendJSON(&res)
}
return c.Error(rlt)
}
}