當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Exchange.GetAddrPrivKey方法代碼示例

本文整理匯總了Golang中github.com/skycoin/skycoin-exchange/src/server/engine.Exchange.GetAddrPrivKey方法的典型用法代碼示例。如果您正苦於以下問題:Golang Exchange.GetAddrPrivKey方法的具體用法?Golang Exchange.GetAddrPrivKey怎麽用?Golang Exchange.GetAddrPrivKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/skycoin/skycoin-exchange/src/server/engine.Exchange的用法示例。


在下文中一共展示了Exchange.GetAddrPrivKey方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: makeBtcUtxoWithkeys

func makeBtcUtxoWithkeys(utxos []bitcoin.Utxo, egn engine.Exchange) ([]bitcoin.UtxoWithkey, error) {
	utxoks := make([]bitcoin.UtxoWithkey, len(utxos))
	for i, u := range utxos {
		key, err := egn.GetAddrPrivKey(bitcoin.Type, u.GetAddress())
		if err != nil {
			return []bitcoin.UtxoWithkey{}, err
		}
		utxoks[i] = bitcoin.NewUtxoWithKey(u, key)
	}
	return utxoks, nil
}
開發者ID:skycoin,項目名稱:skycoin-exchange,代碼行數:11,代碼來源:withdrawal.go

示例2: createSkyWithdrawTx

func createSkyWithdrawTx(egn engine.Exchange, amount uint64, toAddr string) (*SkyTxResult, error) {
	uxs, err := egn.ChooseUtxos(skycoin.Type, amount, ChooseUtxoTm)
	if err != nil {
		return nil, err
	}
	utxos := uxs.([]skycoin.Utxo)

	for _, u := range utxos {
		logger.Debug("using skycoin utxos:%s", u.GetHash())
	}

	var success bool
	defer func() {
		if !success {
			go func() { egn.PutUtxos(skycoin.Type, utxos) }()
		}
	}()

	var totalAmounts uint64
	var totalHours uint64
	for _, u := range utxos {
		totalAmounts += u.GetCoins()
		totalHours += u.GetHours()
	}

	outAddrs := []skycoin.TxOut{}
	chgAmt := totalAmounts - amount
	chgHours := totalHours / 4
	chgAddr := ""
	if chgAmt > 0 {
		// generate a change address
		chgAddr = egn.GetNewAddress(skycoin.Type)
		outAddrs = append(outAddrs,
			skycoin.MakeUtxoOutput(toAddr, amount, chgHours/2),
			skycoin.MakeUtxoOutput(chgAddr, chgAmt, chgHours/2))
	} else {
		outAddrs = append(outAddrs, skycoin.MakeUtxoOutput(toAddr, amount, chgHours/2))
	}

	keys := make([]cipher.SecKey, len(utxos))
	for i, u := range utxos {
		k, err := egn.GetAddrPrivKey(skycoin.Type, u.GetAddress())
		if err != nil {
			panic(err)
		}
		keys[i] = cipher.MustSecKeyFromHex(k)
	}

	logger.Debug("creating skycoin transaction...")
	tx := skycoin.NewTransaction(utxos, keys, outAddrs)
	if err := tx.Verify(); err != nil {
		return nil, err
	}

	success = true
	rlt := SkyTxResult{
		Tx:         tx,
		UsingUtxos: utxos[:],
		ChangeAddr: chgAddr,
	}
	return &rlt, nil
}
開發者ID:skycoin,項目名稱:skycoin-exchange,代碼行數:62,代碼來源:withdrawal.go

示例3: getAddrPrivKey

func getAddrPrivKey(ee engine.Exchange, cp string) coin.GetPrivKey {
	return func(addr string) (string, error) {
		return ee.GetAddrPrivKey(cp, addr)
	}
}
開發者ID:skycoin,項目名稱:skycoin-exchange,代碼行數:5,代碼來源:withdrawal.go


注:本文中的github.com/skycoin/skycoin-exchange/src/server/engine.Exchange.GetAddrPrivKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。