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


Golang Address.EncodeAddress方法代碼示例

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


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

示例1: CalculateAddressBalance

// CalculateAddressBalance sums the amounts of all unspent transaction
// outputs to a single address's pubkey hash and returns the balance
// as a float64.
//
// If confirmations is 0, all UTXOs, even those not present in a
// block (height -1), will be used to get the balance.  Otherwise,
// a UTXO must be in a block.  If confirmations is 1 or greater,
// the balance will be calculated based on how many how many blocks
// include a UTXO.
func (a *Account) CalculateAddressBalance(addr btcutil.Address, confirms int) float64 {
	bs, err := GetCurBlock()
	if bs.Height == int32(btcutil.BlockHeightUnknown) || err != nil {
		return 0.
	}

	var bal btcutil.Amount
	unspent, err := a.TxStore.UnspentOutputs()
	if err != nil {
		return 0.
	}
	for _, credit := range unspent {
		if credit.Confirmed(confirms, bs.Height) {
			// We only care about the case where len(addrs) == 1, and err
			// will never be non-nil in that case
			_, addrs, _, _ := credit.Addresses(activeNet.Params)
			if len(addrs) != 1 {
				continue
			}
			if addrs[0].EncodeAddress() == addr.EncodeAddress() {
				bal += credit.Amount()
			}
		}
	}
	return bal.ToUnit(btcutil.AmountBTC)
}
開發者ID:kingpro,項目名稱:btcwallet,代碼行數:35,代碼來源:account.go

示例2: MarkAddressForAccount

// MarkAddressForAccount labels the given account as containing the provided
// address.
func (am *AccountManager) MarkAddressForAccount(address btcutil.Address,
	account *Account) {
	// TODO(oga) really this entire dance should be carried out implicitly
	// instead of requiring explicit messaging from the account to the
	// manager.
	am.cmdChan <- &markAddressForAccountCmd{
		address: address.EncodeAddress(),
		account: account,
	}
}
開發者ID:GeertJohan,項目名稱:btcwallet,代碼行數:12,代碼來源:acctmgr.go

示例3: AccountByAddress

// AccountByAddress returns the account specified by address, or
// ErrNotFound as an error if the account is not found.
func (am *AccountManager) AccountByAddress(addr btcutil.Address) (*Account,
	error) {
	respChan := make(chan *Account)
	am.cmdChan <- &accessAccountByAddressRequest{
		address: addr.EncodeAddress(),
		resp:    respChan,
	}
	resp := <-respChan
	if resp == nil {
		return nil, ErrNotFound
	}
	return resp, nil
}
開發者ID:GeertJohan,項目名稱:btcwallet,代碼行數:15,代碼來源:acctmgr.go

示例4: AccountByAddress

// AccountByAddress returns the account specified by address, or
// ErrNotFound as an error if the account is not found.
func (am *AccountManager) AccountByAddress(addr btcutil.Address) (*Account, error) {
	respChan := make(chan *Account)
	req := accessAccountByAddressRequest{
		address: addr.EncodeAddress(),
		resp:    respChan,
	}
	select {
	case am.cmdChan <- &req:
		resp := <-respChan
		if resp == nil {
			return nil, ErrNotFound
		}
		return resp, nil
	case <-am.quit:
		return nil, ErrNoAccounts
	}
}
開發者ID:kingpro,項目名稱:btcwallet,代碼行數:19,代碼來源:acctmgr.go

示例5: TestAddresses


//.........這裏部分代碼省略.........
					0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
					0xb1, 0x6e, 0x65, 0x37, 0xa5, 0x76, 0x78, 0x2e, 0xba, 0x66,
					0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
					0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
					0x1e, 0x09, 0x08, 0xef, 0x7b}
				return btcutil.NewAddressPubKey(serializedPubKey, btcwire.TestNet3)
			},
			net: btcwire.TestNet3,
		},
	}

	for _, test := range tests {
		var decoded btcutil.Address
		var err error
		if test.canDecode {
			// Decode addr and compare error against valid.
			decoded, err = btcutil.DecodeAddr(test.addr)
			if (err == nil) != test.valid {
				t.Errorf("%v: decoding test failed", test.name)
				return
			}
		} else {
			// The address can't be decoded directly, so instead
			// call the creation function.
			decoded, err = test.f()
			if (err == nil) != test.valid {
				t.Errorf("%v: creation test failed", test.name)
				return
			}
		}

		// If decoding succeeded, encode again and compare against the original.
		if err == nil {
			encoded := decoded.EncodeAddress()

			// Compare encoded addr against the original encoding.
			if test.addr != encoded {
				t.Errorf("%v: decoding and encoding produced different addressess: %v != %v",
					test.name, test.addr, encoded)
				return
			}

			// Perform type-specific calculations.
			var saddr []byte
			var net btcwire.BitcoinNet
			switch d := decoded.(type) {
			case *btcutil.AddressPubKeyHash:
				saddr = btcutil.TstAddressSAddr(encoded)

				// Net is not part of the Address interface and
				// must be calculated here.
				net = d.Net()

			case *btcutil.AddressScriptHash:
				saddr = btcutil.TstAddressSAddr(encoded)

				// Net is not part of the Address interface and
				// must be calculated here.
				net = d.Net()

			case *btcutil.AddressPubKey:
				// Ignore the error here since the script
				// address is checked below.
				saddr, _ = hex.DecodeString(d.String())

				// Net is not part of the Address interface and
開發者ID:rivercheng,項目名稱:btcutil,代碼行數:67,代碼來源:address_test.go


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