multi: update to new upstream btcsuite/btcd API's
This commit is contained in:
parent
2a277a8994
commit
a0abd3632c
10 changed files with 49 additions and 44 deletions
4
CHANGES
4
CHANGES
|
@ -30,7 +30,7 @@ Changes in 0.7.0 (Mon Nov 23 2015)
|
|||
- Miscellaneous:
|
||||
- Updated websocket notification handlers to latest API required by
|
||||
btcd (#294)
|
||||
- Enabled the logging subsystem of the btcrpcclient package (#328)
|
||||
- Enabled the logging subsystem of the rpcclient package (#328)
|
||||
|
||||
- Contributors (alphabetical order):
|
||||
- Alex Yocom-Piatt
|
||||
|
@ -259,7 +259,7 @@ Changes in 0.5.0 (Tue Mar 03 2015)
|
|||
notification channels in the rpcServer struct, which are in turn
|
||||
marshalled and broadcast to each websocket client
|
||||
- Separate the RPC client code into the chain package:
|
||||
- Uses btcrpcclient for a btcd websocket RPC client
|
||||
- Uses rpcclient for a btcd websocket RPC client
|
||||
- Converts all notification callbacks to typed messages sent over channels
|
||||
- Uses an unbounded queue for waiting notifications
|
||||
- Import a new voting pool package (votingpool):
|
||||
|
|
|
@ -30,7 +30,7 @@ type Interface interface {
|
|||
|
||||
// Notification types. These are defined here and processed from from reading
|
||||
// a notificationChan to avoid handling these notifications directly in
|
||||
// btcrpcclient callbacks, which isn't very Go-like and doesn't allow
|
||||
// rpcclient callbacks, which isn't very Go-like and doesn't allow
|
||||
// blocking client calls.
|
||||
type (
|
||||
// ClientConnected is a notification for when a client connection is
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
|
||||
"github.com/lightninglabs/neutrino"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
"github.com/roasbeef/btcd/rpcclient"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcrpcclient"
|
||||
"github.com/roasbeef/btcutil"
|
||||
"github.com/roasbeef/btcwallet/waddrmgr"
|
||||
"github.com/roasbeef/btcwallet/wtxmgr"
|
||||
|
@ -98,7 +98,7 @@ func (s *NeutrinoClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error)
|
|||
// GetBlockHeight gets the height of a block by its hash. It serves as a
|
||||
// replacement for the use of GetBlockVerboseTxAsync for the wallet package
|
||||
// since we can't actually return a FutureGetBlockVerboseResult because the
|
||||
// underlying type is private to btcrpcclient.
|
||||
// underlying type is private to rpcclient.
|
||||
func (s *NeutrinoClient) GetBlockHeight(hash *chainhash.Hash) (int32, error) {
|
||||
_, height, err := s.CS.BlockHeaders.FetchHeader(hash)
|
||||
if err != nil {
|
||||
|
@ -196,7 +196,7 @@ func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Addre
|
|||
}
|
||||
|
||||
s.rescan = s.CS.NewRescan(
|
||||
neutrino.NotificationHandlers(btcrpcclient.NotificationHandlers{
|
||||
neutrino.NotificationHandlers(rpcclient.NotificationHandlers{
|
||||
OnBlockConnected: s.onBlockConnected,
|
||||
OnFilteredBlockConnected: s.onFilteredBlockConnected,
|
||||
OnBlockDisconnected: s.onBlockDisconnected,
|
||||
|
@ -243,7 +243,7 @@ func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error {
|
|||
|
||||
// Rescan with just the specified addresses.
|
||||
s.rescan = s.CS.NewRescan(
|
||||
neutrino.NotificationHandlers(btcrpcclient.NotificationHandlers{
|
||||
neutrino.NotificationHandlers(rpcclient.NotificationHandlers{
|
||||
OnBlockConnected: s.onBlockConnected,
|
||||
OnFilteredBlockConnected: s.onFilteredBlockConnected,
|
||||
OnBlockDisconnected: s.onBlockDisconnected,
|
||||
|
|
19
chain/rpc.go
19
chain/rpc.go
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||
|
@ -20,8 +21,8 @@ import (
|
|||
// RPCClient represents a persistent client connection to a bitcoin RPC server
|
||||
// for information regarding the current best block chain.
|
||||
type RPCClient struct {
|
||||
*btcrpcclient.Client
|
||||
connConfig *btcrpcclient.ConnConfig // Work around unexported field
|
||||
*rpcclient.Client
|
||||
connConfig *rpcclient.ConnConfig // Work around unexported field
|
||||
chainParams *chaincfg.Params
|
||||
reconnectAttempts int
|
||||
|
||||
|
@ -49,7 +50,7 @@ func NewRPCClient(chainParams *chaincfg.Params, connect, user, pass string, cert
|
|||
}
|
||||
|
||||
client := &RPCClient{
|
||||
connConfig: &btcrpcclient.ConnConfig{
|
||||
connConfig: &rpcclient.ConnConfig{
|
||||
Host: connect,
|
||||
Endpoint: "ws",
|
||||
User: user,
|
||||
|
@ -66,7 +67,7 @@ func NewRPCClient(chainParams *chaincfg.Params, connect, user, pass string, cert
|
|||
currentBlock: make(chan *waddrmgr.BlockStamp),
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
ntfnCallbacks := &btcrpcclient.NotificationHandlers{
|
||||
ntfnCallbacks := &rpcclient.NotificationHandlers{
|
||||
OnClientConnected: client.onClientConnect,
|
||||
OnBlockConnected: client.onBlockConnected,
|
||||
OnBlockDisconnected: client.onBlockDisconnected,
|
||||
|
@ -75,7 +76,7 @@ func NewRPCClient(chainParams *chaincfg.Params, connect, user, pass string, cert
|
|||
OnRescanFinished: client.onRescanFinished,
|
||||
OnRescanProgress: client.onRescanProgress,
|
||||
}
|
||||
rpcClient, err := btcrpcclient.New(client.connConfig, ntfnCallbacks)
|
||||
rpcClient, err := rpcclient.New(client.connConfig, ntfnCallbacks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -159,7 +160,7 @@ func (c *RPCClient) BlockStamp() (*waddrmgr.BlockStamp, error) {
|
|||
|
||||
// parseBlock parses a btcws definition of the block a tx is mined it to the
|
||||
// Block structure of the wtxmgr package, and the block index. This is done
|
||||
// here since btcrpcclient doesn't parse this nicely for us.
|
||||
// here since rpcclient doesn't parse this nicely for us.
|
||||
func parseBlock(block *btcjson.BlockDetails) (*wtxmgr.BlockMeta, error) {
|
||||
if block == nil {
|
||||
return nil, nil
|
||||
|
@ -372,9 +373,9 @@ out:
|
|||
c.wg.Done()
|
||||
}
|
||||
|
||||
// POSTClient creates the equivalent HTTP POST btcrpcclient.Client.
|
||||
func (c *RPCClient) POSTClient() (*btcrpcclient.Client, error) {
|
||||
// POSTClient creates the equivalent HTTP POST rpcclient.Client.
|
||||
func (c *RPCClient) POSTClient() (*rpcclient.Client, error) {
|
||||
configCopy := *c.connConfig
|
||||
configCopy.HTTPPostMode = true
|
||||
return btcrpcclient.New(&configCopy, nil)
|
||||
return rpcclient.New(&configCopy, nil)
|
||||
}
|
||||
|
|
|
@ -12,17 +12,17 @@ import (
|
|||
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/netparams"
|
||||
"github.com/btcsuite/btcwallet/wallet/txauthor"
|
||||
"github.com/btcsuite/btcwallet/wallet/txrules"
|
||||
"github.com/btcsuite/golangcrypto/ssh/terminal"
|
||||
"github.com/jessevdk/go-flags"
|
||||
"github.com/roasbeef/btcd/btcjson"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
"github.com/roasbeef/btcd/rpcclient"
|
||||
"github.com/roasbeef/btcd/txscript"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
"github.com/roasbeef/btcwallet/internal/cfgutil"
|
||||
"github.com/roasbeef/btcwallet/netparams"
|
||||
"github.com/roasbeef/btcwallet/wallet/txauthor"
|
||||
"github.com/roasbeef/btcwallet/wallet/txrules"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -186,7 +186,7 @@ func makeInputSource(outputs []btcjson.ListUnspentResult) txauthor.InputSource {
|
|||
// makeDestinationScriptSource creates a ChangeSource which is used to receive
|
||||
// all correlated previous input value. A non-change address is created by this
|
||||
// function.
|
||||
func makeDestinationScriptSource(rpcClient *btcrpcclient.Client, accountName string) txauthor.ChangeSource {
|
||||
func makeDestinationScriptSource(rpcClient *rpcclient.Client, accountName string) txauthor.ChangeSource {
|
||||
return func() ([]byte, error) {
|
||||
destinationAddress, err := rpcClient.GetNewAddress(accountName)
|
||||
if err != nil {
|
||||
|
@ -214,7 +214,7 @@ func sweep() error {
|
|||
if err != nil {
|
||||
return errContext(err, "failed to read RPC certificate")
|
||||
}
|
||||
rpcClient, err := btcrpcclient.New(&btcrpcclient.ConnConfig{
|
||||
rpcClient, err := rpcclient.New(&rpcclient.ConnConfig{
|
||||
Host: opts.RPCConnect,
|
||||
User: opts.RPCUsername,
|
||||
Pass: rpcPassword,
|
||||
|
|
12
log.go
12
log.go
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/btcsuite/btcwallet/wallet"
|
||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||
"github.com/jrick/logrotate/rotator"
|
||||
"github.com/lightninglabs/neutrino"
|
||||
)
|
||||
|
||||
// logWriter implements an io.Writer that outputs to both standard output and
|
||||
|
@ -61,7 +62,7 @@ func init() {
|
|||
wallet.UseLogger(walletLog)
|
||||
wtxmgr.UseLogger(txmgrLog)
|
||||
chain.UseLogger(chainLog)
|
||||
btcrpcclient.UseLogger(chainLog)
|
||||
rpcclient.UseLogger(chainLog)
|
||||
rpcserver.UseLogger(grpcLog)
|
||||
legacyrpc.UseLogger(legacyRPCLog)
|
||||
neutrino.UseLogger(btcnLog)
|
||||
|
@ -134,17 +135,16 @@ func useLogger(subsystemID string, logger btclog.Logger) {
|
|||
btcnLog = logger
|
||||
neutrino.UseLogger(logger)
|
||||
}
|
||||
|
||||
r, err := rotator.New(logFile, 10*1024, false, 3)
|
||||
=======
|
||||
}
|
||||
pr, pw := io.Pipe()
|
||||
r, err := rotator.New(pr, logFile, 10*1024, false, 3)
|
||||
>>>>>>> 249dae0... log: update to new logging API
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to create file rotator: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
go r.Run(pr)
|
||||
|
||||
logRotator = r
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ import (
|
|||
"github.com/roasbeef/btcd/btcjson"
|
||||
"github.com/roasbeef/btcd/chaincfg"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
"github.com/roasbeef/btcd/rpcclient"
|
||||
"github.com/roasbeef/btcd/txscript"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcrpcclient"
|
||||
"github.com/roasbeef/btcutil"
|
||||
"github.com/roasbeef/btcwallet/chain"
|
||||
"github.com/roasbeef/btcwallet/waddrmgr"
|
||||
|
@ -970,7 +970,7 @@ func help(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (int
|
|||
//
|
||||
// This is hacky and is probably better handled by exposing help usage
|
||||
// texts in a non-internal btcd package.
|
||||
postClient := func() *btcrpcclient.Client {
|
||||
postClient := func() *rpcclient.Client {
|
||||
if chainClient == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -1649,7 +1649,7 @@ func signRawTransaction(icmd interface{}, w *wallet.Wallet, chainClient *chain.R
|
|||
// querying btcd with getrawtransaction. We queue up a bunch of async
|
||||
// requests and will wait for replies after we have checked the rest of
|
||||
// the arguments.
|
||||
requested := make(map[wire.OutPoint]btcrpcclient.FutureGetTxOutResult)
|
||||
requested := make(map[wire.OutPoint]rpcclient.FutureGetTxOutResult)
|
||||
for _, txIn := range tx.TxIn {
|
||||
// Did we get this outpoint from the arguments?
|
||||
if _, ok := inputs[txIn.PreviousOutPoint]; ok {
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"google.golang.org/grpc/codes"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
|
@ -816,7 +817,7 @@ func (s *loaderServer) StartConsensusRpc(ctx context.Context, req *pb.StartConse
|
|||
|
||||
err = rpcClient.Start()
|
||||
if err != nil {
|
||||
if err == btcrpcclient.ErrInvalidAuth {
|
||||
if err == rpcclient.ErrInvalidAuth {
|
||||
return nil, grpc.Errorf(codes.InvalidArgument,
|
||||
"Invalid RPC credentials: %v", err)
|
||||
}
|
||||
|
|
|
@ -263,7 +263,7 @@ func spendWitnessKeyHash(txIn *wire.TxIn, pkScript []byte,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
witnessScript, err := txscript.WitnessScript(tx, hashCache, idx,
|
||||
witnessScript, err := txscript.WitnessSignature(tx, hashCache, idx,
|
||||
inputValue, witnessProgram, txscript.SigHashAll, privKey, true)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -326,7 +326,7 @@ func spendNestedWitnessPubKeyHash(txIn *wire.TxIn, pkScript []byte,
|
|||
|
||||
// With the sigScript in place, we'll next generate the proper witness
|
||||
// that'll allow us to spend the p2wkh output.
|
||||
witnessScript, err := txscript.WitnessScript(tx, hashCache, idx,
|
||||
witnessScript, err := txscript.WitnessSignature(tx, hashCache, idx,
|
||||
inputValue, witnessProgram, txscript.SigHashAll, privKey, compressed)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
|
||||
|
@ -287,7 +288,7 @@ func (w *Wallet) ChainSynced() bool {
|
|||
// SetChainSynced marks whether the wallet is connected to and currently in sync
|
||||
// with the latest block notified by the chain server.
|
||||
//
|
||||
// NOTE: Due to an API limitation with btcrpcclient, this may return true after
|
||||
// NOTE: Due to an API limitation with rpcclient, this may return true after
|
||||
// the client disconnected (and is attempting a reconnect). This will be unknown
|
||||
// until the reconnect notification is received, at which point the wallet can be
|
||||
// marked out of sync again until after the next rescan completes.
|
||||
|
@ -493,9 +494,9 @@ func (w *Wallet) syncWithChain() error {
|
|||
// Request notifications for connected and disconnected blocks.
|
||||
//
|
||||
// TODO(jrick): Either request this notification only once, or when
|
||||
// btcrpcclient is modified to allow some notification request to not
|
||||
// rpcclient is modified to allow some notification request to not
|
||||
// automatically resent on reconnect, include the notifyblocks request
|
||||
// as well. I am leaning towards allowing off all btcrpcclient
|
||||
// as well. I am leaning towards allowing off all rpcclient
|
||||
// notification re-registrations, in which case the code here should be
|
||||
// left as is.
|
||||
err = chainClient.NotifyBlocks()
|
||||
|
@ -1421,7 +1422,7 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
|
|||
// TODO: Fetching block heights by their hashes is inherently racy
|
||||
// because not all block headers are saved but when they are for SPV the
|
||||
// db can be queried directly without this.
|
||||
var startResp, endResp btcrpcclient.FutureGetBlockVerboseResult
|
||||
var startResp, endResp rpcclient.FutureGetBlockVerboseResult
|
||||
if startBlock != nil {
|
||||
if startBlock.hash == nil {
|
||||
start = startBlock.height
|
||||
|
@ -1807,7 +1808,9 @@ func (w *Wallet) ListUnspent(minconf, maxconf int32, addresses map[string]struct
|
|||
spendable = true
|
||||
case txscript.PubKeyTy:
|
||||
spendable = true
|
||||
case txscript.ScriptHashTy:
|
||||
case txscript.WitnessV0ScriptHashTy:
|
||||
spendable = true
|
||||
case txscript.WitnessV0PubKeyHashTy:
|
||||
spendable = true
|
||||
case txscript.MultiSigTy:
|
||||
for _, a := range addrs {
|
||||
|
|
Loading…
Add table
Reference in a new issue