Remove usage of deprecated address encode/decode API.
This commit is contained in:
parent
082ad7caf2
commit
405eca4a44
2 changed files with 30 additions and 25 deletions
28
rpcserver.go
28
rpcserver.go
|
@ -528,31 +528,29 @@ func createVoutList(mtx *btcwire.MsgTx, net btcwire.BitcoinNet) ([]btcjson.Vout,
|
||||||
voutList[i].ScriptPubKey.Asm = disbuf
|
voutList[i].ScriptPubKey.Asm = disbuf
|
||||||
voutList[i].ScriptPubKey.Hex = hex.EncodeToString(v.PkScript)
|
voutList[i].ScriptPubKey.Hex = hex.EncodeToString(v.PkScript)
|
||||||
|
|
||||||
scriptType, reqSigs, addrHashes := btcscript.CalcPkScriptAddrHashes(v.PkScript)
|
scriptType, reqSigs, hashes := btcscript.CalcPkScriptAddrHashes(v.PkScript)
|
||||||
voutList[i].ScriptPubKey.Type = scriptType.String()
|
voutList[i].ScriptPubKey.Type = scriptType.String()
|
||||||
voutList[i].ScriptPubKey.ReqSigs = reqSigs
|
voutList[i].ScriptPubKey.ReqSigs = reqSigs
|
||||||
|
|
||||||
if addrHashes == nil {
|
if hashes == nil {
|
||||||
voutList[i].ScriptPubKey.Addresses = nil
|
voutList[i].ScriptPubKey.Addresses = nil
|
||||||
} else {
|
} else {
|
||||||
voutList[i].ScriptPubKey.Addresses = make([]string, len(addrHashes))
|
voutList[i].ScriptPubKey.Addresses = make([]string, len(hashes))
|
||||||
for j := 0; j < len(addrHashes); j++ {
|
for j := 0; j < len(hashes); j++ {
|
||||||
var addr string
|
var addr btcutil.Address
|
||||||
if scriptType == btcscript.ScriptHashTy {
|
if scriptType == btcscript.ScriptHashTy {
|
||||||
addr, err = btcutil.EncodeScriptHash(addrHashes[j], net)
|
addr, err = btcutil.NewAddressScriptHash(hashes[j], net)
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
addr, err = btcutil.EncodeAddress(addrHashes[j], net)
|
addr, err = btcutil.NewAddressPubKeyHash(hashes[j], net)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
// hash will always be 20 bytes, so the only
|
||||||
|
// possible error is from an invalid network.
|
||||||
|
return nil, errors.New("Cannot create address with invalid network.")
|
||||||
|
}
|
||||||
|
voutList[i].ScriptPubKey.Addresses[j] = addr.EncodeAddress()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
voutList[i].ScriptPubKey.Addresses[j] = addr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return voutList, nil
|
return voutList, nil
|
||||||
|
|
|
@ -340,12 +340,19 @@ func handleNotifyNewTXs(s *rpcServer, cmd btcjson.Cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, addr := range notifyCmd.Addresses {
|
for _, addr := range notifyCmd.Addresses {
|
||||||
hash, _, err := btcutil.DecodeAddress(addr)
|
addr, err := btcutil.DecodeAddr(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot decode address: %v", err)
|
return fmt.Errorf("cannot decode address: %v", err)
|
||||||
}
|
}
|
||||||
s.ws.AddTxRequest(walletNotification, rc, string(hash),
|
|
||||||
cmd.Id())
|
// TODO(jrick) Notifing for non-P2PKH addresses is currently
|
||||||
|
// unsuported.
|
||||||
|
if _, ok := addr.(*btcutil.AddressPubKeyHash); !ok {
|
||||||
|
return fmt.Errorf("address is not P2PKH: %v", addr.EncodeAddress())
|
||||||
|
}
|
||||||
|
|
||||||
|
s.ws.AddTxRequest(walletNotification, rc,
|
||||||
|
string(addr.ScriptAddress()), cmd.Id())
|
||||||
}
|
}
|
||||||
|
|
||||||
mreply, _ := json.Marshal(reply)
|
mreply, _ := json.Marshal(reply)
|
||||||
|
@ -423,13 +430,13 @@ func handleRescan(s *rpcServer, cmd btcjson.Cmd,
|
||||||
if st != btcscript.ScriptAddr || err != nil {
|
if st != btcscript.ScriptAddr || err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
txaddr, err := btcutil.EncodeAddress(txaddrhash, s.server.btcnet)
|
txaddr, err := btcutil.NewAddressPubKeyHash(txaddrhash, s.server.btcnet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rpcsLog.Errorf("Error encoding address: %v", err)
|
rpcsLog.Errorf("Error creating address: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := rescanCmd.Addresses[txaddr]; ok {
|
if _, ok := rescanCmd.Addresses[txaddr.EncodeAddress()]; ok {
|
||||||
// TODO(jrick): This lookup is expensive and can be avoided
|
// TODO(jrick): This lookup is expensive and can be avoided
|
||||||
// if the wallet is sent the previous outpoints for all inputs
|
// if the wallet is sent the previous outpoints for all inputs
|
||||||
// of the tx, so any can removed from the utxo set (since
|
// of the tx, so any can removed from the utxo set (since
|
||||||
|
@ -460,7 +467,7 @@ func handleRescan(s *rpcServer, cmd btcjson.Cmd,
|
||||||
PkScript string `json:"pkscript"`
|
PkScript string `json:"pkscript"`
|
||||||
Spent bool `json:"spent"`
|
Spent bool `json:"spent"`
|
||||||
}{
|
}{
|
||||||
Receiver: txaddr,
|
Receiver: txaddr.EncodeAddress(),
|
||||||
Height: blk.Height(),
|
Height: blk.Height(),
|
||||||
BlockHash: blkshalist[i].String(),
|
BlockHash: blkshalist[i].String(),
|
||||||
BlockIndex: tx.Index(),
|
BlockIndex: tx.Index(),
|
||||||
|
@ -784,9 +791,9 @@ func (s *rpcServer) NotifyForTxOuts(tx *btcutil.Tx, block *btcutil.Block) {
|
||||||
for e := idlist.Front(); e != nil; e = e.Next() {
|
for e := idlist.Front(); e != nil; e = e.Next() {
|
||||||
ctx := e.Value.(*notificationCtx)
|
ctx := e.Value.(*notificationCtx)
|
||||||
|
|
||||||
txaddr, err := btcutil.EncodeAddress(txaddrhash, s.server.btcnet)
|
txaddr, err := btcutil.NewAddressPubKeyHash(txaddrhash, s.server.btcnet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rpcsLog.Error("Error encoding address; dropping Tx notification.")
|
rpcsLog.Debugf("Error creating address; dropping Tx notification.")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -802,7 +809,7 @@ func (s *rpcServer) NotifyForTxOuts(tx *btcutil.Tx, block *btcutil.Block) {
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
PkScript string `json:"pkscript"`
|
PkScript string `json:"pkscript"`
|
||||||
}{
|
}{
|
||||||
Receiver: txaddr,
|
Receiver: txaddr.EncodeAddress(),
|
||||||
TxID: tx.Sha().String(),
|
TxID: tx.Sha().String(),
|
||||||
TxOutIndex: uint32(i),
|
TxOutIndex: uint32(i),
|
||||||
Amount: txout.Value,
|
Amount: txout.Value,
|
||||||
|
|
Loading…
Reference in a new issue