本文整理匯總了Golang中github.com/btcsuite/btcutil.Address.String方法的典型用法代碼示例。如果您正苦於以下問題:Golang Address.String方法的具體用法?Golang Address.String怎麽用?Golang Address.String使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/btcsuite/btcutil.Address
的用法示例。
在下文中一共展示了Address.String方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UnsubscribeAddress
func (l *LibbitcoinClient) UnsubscribeAddress(address btc.Address) {
l.lock.Lock()
_, ok := l.subscriptions[address.String()]
if ok {
delete(l.subscriptions, address.String())
}
l.lock.Unlock()
}
示例2: RenewSubscription
func (l *LibbitcoinClient) RenewSubscription(address btc.Address, callback func(interface{})) {
req := []byte{}
req = append(req, byte(0))
req = append(req, byte(160))
req = append(req, address.ScriptAddress()...)
go l.SendCommand("address.renew", req, nil)
l.lock.Lock()
l.subscriptions[address.String()] = subscription{
expiration: time.Now().Add(24 * time.Hour),
callback: callback,
}
l.lock.Unlock()
}
示例3: Parse
func (l *LibbitcoinClient) Parse(command string, data []byte, callback func(interface{}, error)) {
switch command {
case "address.fetch_history2":
numRows := (len(data) - 4) / 49
buff := bytes.NewBuffer(data)
err := ParseError(buff.Next(4))
rows := []FetchHistory2Resp{}
for i := 0; i < numRows; i++ {
r := FetchHistory2Resp{}
spendByte := int(buff.Next(1)[0])
var spendBool bool
if spendByte == 0 {
spendBool = false
} else {
spendBool = true
}
r.IsSpend = spendBool
lehash := buff.Next(32)
sh, _ := wire.NewShaHash(lehash)
r.TxHash = sh.String()
indexBytes := buff.Next(4)
r.Index = binary.LittleEndian.Uint32(indexBytes)
heightBytes := buff.Next(4)
r.Height = binary.LittleEndian.Uint32(heightBytes)
valueBytes := buff.Next(8)
r.Value = binary.LittleEndian.Uint64(valueBytes)
rows = append(rows, r)
}
callback(rows, err)
case "blockchain.fetch_last_height":
height := binary.LittleEndian.Uint32(data[4:])
callback(height, ParseError(data[:4]))
case "blockchain.fetch_transaction":
txn, _ := btc.NewTxFromBytes(data[4:])
callback(txn, ParseError(data[:4]))
case "transaction_pool.fetch_transaction":
txn, _ := btc.NewTxFromBytes(data[4:])
callback(txn, ParseError(data[:4]))
case "address.update":
buff := bytes.NewBuffer(data)
addressVersion := buff.Next(1)[0]
addressHash160 := buff.Next(20)
height := buff.Next(4)
block := buff.Next(32)
tx := buff.Bytes()
var addr btc.Address
if addressVersion == byte(111) || addressVersion == byte(0) {
a, _ := btc.NewAddressPubKeyHash(addressHash160, l.Params)
addr = a
} else if addressVersion == byte(5) || addressVersion == byte(196) {
a, _ := btc.NewAddressScriptHashFromHash(addressHash160, l.Params)
addr = a
}
bl, _ := wire.NewShaHash(block)
txn, _ := btc.NewTxFromBytes(tx)
resp := SubscribeResp{
Address: addr.String(),
Height: binary.LittleEndian.Uint32(height),
Block: bl.String(),
Tx: *txn,
}
l.lock.Lock()
l.subscriptions[addr.String()].callback(resp)
l.lock.Unlock()
case "protocol.broadcast_transaction":
callback(nil, ParseError(data[:4]))
case "transaction_pool.validate":
b := data[4:5]
success, _ := strconv.ParseBool(string(b))
callback(success, ParseError(data[:4]))
}
}