multi: add bitcoind back-end (only for API use for now)

This commit is contained in:
Alex 2017-11-09 17:13:40 -07:00 committed by Olaoluwa Osuntokun
parent b963eb3ba4
commit 73dbcf3943
8 changed files with 1188 additions and 1 deletions

1149
chain/bitcoind.go Normal file

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,16 @@ import (
"github.com/roasbeef/btcwallet/wtxmgr" "github.com/roasbeef/btcwallet/wtxmgr"
) )
// BackEnds returns a list of the available back ends.
// TODO: Refactor each into a driver and use dynamic registration.
func BackEnds() []string {
return []string{
"bitcoind",
"btcd",
"neutrino",
}
}
// Interface allows more than one backing blockchain source, such as a // Interface allows more than one backing blockchain source, such as a
// btcd RPC chain server, or an SPV library, as long as we write a driver for // btcd RPC chain server, or an SPV library, as long as we write a driver for
// it. // it.
@ -27,6 +37,7 @@ type Interface interface {
NotifyReceived([]btcutil.Address) error NotifyReceived([]btcutil.Address) error
NotifyBlocks() error NotifyBlocks() error
Notifications() <-chan interface{} Notifications() <-chan interface{}
BackEnd() string
} }
// Notification types. These are defined here and processed from from reading // Notification types. These are defined here and processed from from reading

View file

@ -46,6 +46,11 @@ func NewNeutrinoClient(chainService *neutrino.ChainService) *NeutrinoClient {
return &NeutrinoClient{CS: chainService} return &NeutrinoClient{CS: chainService}
} }
// BackEnd returns the name of the driver.
func (s *NeutrinoClient) BackEnd() string {
return "neutrino"
}
// Start replicates the RPC client's Start method. // Start replicates the RPC client's Start method.
func (s *NeutrinoClient) Start() error { func (s *NeutrinoClient) Start() error {
s.CS.Start() s.CS.Start()

View file

@ -84,6 +84,11 @@ func NewRPCClient(chainParams *chaincfg.Params, connect, user, pass string, cert
return client, nil return client, nil
} }
// BackEnd returns the name of the driver.
func (c *RPCClient) BackEnd() string {
return "btcd"
}
// Start attempts to establish a client connection with the remote server. // Start attempts to establish a client connection with the remote server.
// If successful, handler goroutines are started to process notifications // If successful, handler goroutines are started to process notifications
// sent by the server. After a limited number of connection attempts, this // sent by the server. After a limited number of connection attempts, this

7
glide.lock generated
View file

@ -9,6 +9,7 @@
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
<<<<<<< HEAD
hash: 2fe59efc96b0a2839297653da88cde89208f8f8cf4ced2bb1e828def57e3611b hash: 2fe59efc96b0a2839297653da88cde89208f8f8cf4ced2bb1e828def57e3611b
updated: 2017-07-19T11:33:58.0769452-04:00 updated: 2017-07-19T11:33:58.0769452-04:00
======= =======
@ -54,6 +55,10 @@ updated: 2017-11-03T12:30:39.76652975-07:00
hash: 8217b51c2a5fc4df53200de6315f4c1f4a084a516f38c77b815e0a02ac71e332 hash: 8217b51c2a5fc4df53200de6315f4c1f4a084a516f38c77b815e0a02ac71e332
updated: 2017-11-18T15:17:20.95646706-08:00 updated: 2017-11-18T15:17:20.95646706-08:00
>>>>>>> dc5f652... build: update to latest btcd and neutrino >>>>>>> dc5f652... build: update to latest btcd and neutrino
=======
hash: 83bb1c0a0f5c6396d2387746544592662898af52596d5cdca898b6fbfaa60841
updated: 2017-11-29T14:42:36.82153259-06:00
>>>>>>> 7a32017... multi: add bitcoind back-end (only for API use for now)
imports: imports:
- name: github.com/aead/siphash - name: github.com/aead/siphash
version: e404fcfc888570cadd1610538e2dbc89f66af814 version: e404fcfc888570cadd1610538e2dbc89f66af814
@ -174,6 +179,8 @@ imports:
subpackages: subpackages:
- filterdb - filterdb
- headerfs - headerfs
- name: github.com/pebbe/zmq4
version: 90d69e412a09549f2e90bac70fbb449081f1e5c1
- name: github.com/roasbeef/btcd - name: github.com/roasbeef/btcd
version: 5d9e4e1fa749fa2f1675802a4c9f10ef0ada04d1 version: 5d9e4e1fa749fa2f1675802a4c9f10ef0ada04d1
subpackages: subpackages:

View file

@ -43,6 +43,7 @@ import:
- package: github.com/jrick/logrotate - package: github.com/jrick/logrotate
subpackages: subpackages:
- rotator - rotator
- package: github.com/pebbe/zmq4
testImport: testImport:
- package: github.com/davecgh/go-spew - package: github.com/davecgh/go-spew
subpackages: subpackages:

View file

@ -198,7 +198,8 @@ func (s *NotificationServer) notifyUnminedTransaction(dbtx walletdb.ReadTx, deta
// Sanity check: should not be currently coalescing a notification for // Sanity check: should not be currently coalescing a notification for
// mined transactions at the same time that an unmined tx is notified. // mined transactions at the same time that an unmined tx is notified.
if s.currentTxNtfn != nil { if s.currentTxNtfn != nil {
log.Errorf("Notifying unmined tx notification while creating notification for blocks") log.Errorf("Notifying unmined tx notification (%s) while creating notification for blocks",
details.Hash)
} }
defer s.mu.Unlock() defer s.mu.Unlock()

View file

@ -163,6 +163,8 @@ func (w *Wallet) SynchronizeRPC(chainClient chain.Interface) {
switch cc := chainClient.(type) { switch cc := chainClient.(type) {
case *chain.NeutrinoClient: case *chain.NeutrinoClient:
cc.SetStartTime(w.Manager.Birthday()) cc.SetStartTime(w.Manager.Birthday())
case *chain.BitcoindClient:
cc.SetStartTime(w.Manager.Birthday())
} }
w.chainClientLock.Unlock() w.chainClientLock.Unlock()
@ -1436,6 +1438,12 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
switch client := chainClient.(type) { switch client := chainClient.(type) {
case *chain.RPCClient: case *chain.RPCClient:
startResp = client.GetBlockVerboseTxAsync(startBlock.hash) startResp = client.GetBlockVerboseTxAsync(startBlock.hash)
case *chain.BitcoindClient:
var err error
start, err = client.GetBlockHeight(startBlock.hash)
if err != nil {
return nil, err
}
case *chain.NeutrinoClient: case *chain.NeutrinoClient:
var err error var err error
start, err = client.GetBlockHeight(startBlock.hash) start, err = client.GetBlockHeight(startBlock.hash)