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


Golang ReadTx.Rollback方法代碼示例

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


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

示例1: MakeSecp256k1MultiSigScript

// MakeSecp256k1MultiSigScript creates a multi-signature script that can be
// redeemed with nRequired signatures of the passed keys and addresses.  If the
// address is a P2PKH address, the associated pubkey is looked up by the wallet
// if possible, otherwise an error is returned for a missing pubkey.
//
// This function only works with secp256k1 pubkeys and P2PKH addresses derived
// from them.
func (w *Wallet) MakeSecp256k1MultiSigScript(secp256k1Addrs []dcrutil.Address, nRequired int) ([]byte, error) {
	secp256k1PubKeys := make([]*dcrutil.AddressSecpPubKey, len(secp256k1Addrs))

	var dbtx walletdb.ReadTx
	var addrmgrNs walletdb.ReadBucket
	defer func() {
		if dbtx != nil {
			dbtx.Rollback()
		}
	}()

	// The address list will made up either of addreseses (pubkey hash), for
	// which we need to look up the keys in wallet, straight pubkeys, or a
	// mixture of the two.
	for i, addr := range secp256k1Addrs {
		switch addr := addr.(type) {
		default:
			return nil, errors.New("cannot make multisig script for " +
				"a non-secp256k1 public key or P2PKH address")

		case *dcrutil.AddressSecpPubKey:
			secp256k1PubKeys[i] = addr

		case *dcrutil.AddressPubKeyHash:
			if addr.DSA(w.chainParams) != chainec.ECTypeSecp256k1 {
				return nil, errors.New("cannot make multisig " +
					"script for a non-secp256k1 P2PKH address")
			}

			if dbtx == nil {
				var err error
				dbtx, err = w.db.BeginReadTx()
				if err != nil {
					return nil, err
				}
				addrmgrNs = dbtx.ReadBucket(waddrmgrNamespaceKey)
			}
			addrInfo, err := w.Manager.Address(addrmgrNs, addr)
			if err != nil {
				return nil, err
			}
			serializedPubKey := addrInfo.(waddrmgr.ManagedPubKeyAddress).
				PubKey().Serialize()

			pubKeyAddr, err := dcrutil.NewAddressSecpPubKey(
				serializedPubKey, w.chainParams)
			if err != nil {
				return nil, err
			}
			secp256k1PubKeys[i] = pubKeyAddr
		}
	}

	return txscript.MultiSigScript(secp256k1PubKeys, nRequired)
}
開發者ID:jcvernaleo,項目名稱:btcwallet,代碼行數:62,代碼來源:multisig.go


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