本文整理汇总了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]))
}
}