本文整理汇总了Golang中github.com/skycoin/skycoin-exchange/src/server/engine.Exchange.GetCoin方法的典型用法代码示例。如果您正苦于以下问题:Golang Exchange.GetCoin方法的具体用法?Golang Exchange.GetCoin怎么用?Golang Exchange.GetCoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skycoin/skycoin-exchange/src/server/engine.Exchange
的用法示例。
在下文中一共展示了Exchange.GetCoin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetRawTx
// GetRawTx return rawtx of specifc tx.
func GetRawTx(egn engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
var rlt *pp.EmptyRes
for {
req := pp.GetRawTxReq{}
if err := c.BindJSON(&req); err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
coin, err := egn.GetCoin(req.GetCoinType())
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
rawtx, err := coin.GetRawTx(req.GetTxid())
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
res := pp.GetRawTxRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
CoinType: req.CoinType,
Rawtx: pp.PtrString(rawtx),
}
return c.SendJSON(&res)
}
return c.Error(rlt)
}
}
示例2: GetUtxos
// GetUtxos get unspent output of specific address.
func GetUtxos(egn engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
var req pp.GetUtxoReq
var rlt *pp.EmptyRes
for {
if err := c.BindJSON(&req); err != nil {
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
logger.Error(err.Error())
break
}
coin, err := egn.GetCoin(req.GetCoinType())
if err != nil {
rlt = pp.MakeErrRes(err)
logger.Error(err.Error())
break
}
res, err := coin.GetUtxos(req.GetAddresses())
if err != nil {
rlt = pp.MakeErrRes(err)
logger.Error(err.Error())
break
}
return c.SendJSON(&res)
}
return c.Error(rlt)
}
}
示例3: GetAddrBalance
// GetAddrBalance get balance of specific address.
func GetAddrBalance(ee engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
var rlt *pp.EmptyRes
for {
req := pp.GetAddrBalanceReq{}
if err := c.BindJSON(&req); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
coin, err := ee.GetCoin(req.GetCoinType())
if err != nil {
rlt = pp.MakeErrRes(err)
logger.Error(err.Error())
break
}
addrs := strings.Split(req.GetAddrs(), ",")
b, err := coin.GetBalance(addrs)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
res := pp.GetAddrBalanceRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
Balance: &b,
}
return c.SendJSON(&res)
}
return c.Error(rlt)
}
}
示例4: GetTx
// GetTx get transaction by id.
func GetTx(egn engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
var rlt *pp.EmptyRes
for {
req := pp.GetTxReq{}
if err := c.BindJSON(&req); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
coin, err := egn.GetCoin(req.GetCoinType())
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
// brief validate transaction id
if !coin.ValidateTxid(req.GetTxid()) {
rlt = pp.MakeErrRes(errors.New("invalid transaction id"))
break
}
tx, err := coin.GetTx(req.GetTxid())
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
res := pp.GetTxRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
CoinType: req.CoinType,
Tx: tx,
}
return c.SendJSON(&res)
}
return c.Error(rlt)
}
}
示例5: InjectTx
// InjectTx inject transaction.
func InjectTx(egn engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
var rlt *pp.EmptyRes
for {
req := pp.InjectTxnReq{}
if err := c.BindJSON(&req); err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrResWithCode(pp.ErrCode_WrongRequest)
break
}
// get coin gateway
coin, err := egn.GetCoin(req.GetCoinType())
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
// inject tx.
txid, err := coin.InjectTx(req.GetTx())
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
res := pp.InjectTxnRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
Txid: pp.PtrString(txid),
}
return c.SendJSON(&res)
}
return c.Error(rlt)
}
}
示例6: Withdraw
// Withdraw api for handlering withdraw process.
func Withdraw(ee engine.Exchange) sknet.HandlerFunc {
return func(c *sknet.Context) error {
rlt := &pp.EmptyRes{}
for {
reqParam, err := getWithdrawReqParams(c, ee)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
cp := reqParam.Values["cointype"].(string)
a := reqParam.Values["account"].(account.Accounter)
amt := reqParam.Values["amt"].(uint64)
outAddr := reqParam.Values["outAddr"].(string)
// get handler for creating txIns and txOuts base on the coin type.
createTxInOut, err := getTxInOutHandler(cp)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
// create txIns and txOuts.
inOutSet, err := createTxInOut(ee, a, amt, outAddr)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
var success bool
defer func() {
if !success {
// if not success, invoke the teardown, for putting back utxos, and reset balance.
inOutSet.Teardown()
}
}()
// get coin gateway.
coin, err := ee.GetCoin(cp)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
// create raw tx
rawtx, err := coin.CreateRawTx(inOutSet.TxIns, inOutSet.TxOuts)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
// sign the tx
rawtx, err = coin.SignRawTx(rawtx, getAddrPrivKey(ee, cp))
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
// inject the transaction.
txid, err := coin.InjectTx(rawtx)
if err != nil {
logger.Error(err.Error())
rlt = pp.MakeErrRes(err)
break
}
success = true
resp := pp.WithdrawalRes{
Result: pp.MakeResultWithCode(pp.ErrCode_Success),
NewTxid: &txid,
}
return c.SendJSON(&resp)
}
return c.Error(rlt)
}
}