func (l *LibbitcoinClient) FetchHistory2(address btc.Address, fromHeight uint32, callback func(interface{}, error)) { hash160 := address.ScriptAddress() var netID byte height := make([]byte, 4) binary.LittleEndian.PutUint32(height, fromHeight) address.ScriptAddress() switch reflect.TypeOf(address).String() { case "*btcutil.AddressPubKeyHash": if l.Params.Name == chaincfg.MainNetParams.Name { netID = byte(0) } else { netID = byte(111) } case "*btcutil.AddressScriptHash": if l.Params.Name == chaincfg.MainNetParams.Name { netID = byte(5) } else { netID = byte(196) } } req := []byte{} req = append(req, netID) req = append(req, hash160...) req = append(req, height...) go l.SendCommand("address.fetch_history2", req, callback) }
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() }
// PayToAddrScript creates a new script to pay a transaction output to a the // specified address. func PayToAddrScript(addr btcutil.Address) ([]byte, error) { switch addr := addr.(type) { case *btcutil.AddressPubKeyHash: if addr == nil { return nil, ErrUnsupportedAddress } return payToPubKeyHashScript(addr.ScriptAddress()) case *btcutil.AddressScriptHash: if addr == nil { return nil, ErrUnsupportedAddress } return payToScriptHashScript(addr.ScriptAddress()) case *btcutil.AddressPubKey: if addr == nil { return nil, ErrUnsupportedAddress } return payToPubKeyScript(addr.ScriptAddress()) } return nil, ErrUnsupportedAddress }