forked from Roasbeef/btcwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make rescan a struct, add spending tx to GetUtxo, start integration.
- Loading branch information
Showing
9 changed files
with
574 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package chain | ||
|
||
import ( | ||
"github.com/btcsuite/btcd/chaincfg/chainhash" | ||
"github.com/btcsuite/btcd/wire" | ||
"github.com/btcsuite/btcutil" | ||
"github.com/btcsuite/btcwallet/waddrmgr" | ||
) | ||
|
||
// 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 | ||
// it. | ||
type Interface interface { | ||
Start() error | ||
Stop() | ||
WaitForShutdown() | ||
GetBestBlock() (*chainhash.Hash, int32, error) | ||
GetBlock(*chainhash.Hash) (*wire.MsgBlock, error) | ||
BlockStamp() (*waddrmgr.BlockStamp, error) | ||
SendRawTransaction(*wire.MsgTx, bool) (*chainhash.Hash, error) | ||
Rescan(*chainhash.Hash, []btcutil.Address, []*wire.OutPoint) error | ||
NotifyReceived([]btcutil.Address) error | ||
NotifyBlocks() error | ||
Notifications() <-chan interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package spvchain | ||
|
||
import ( | ||
"github.com/btcsuite/btcd/chaincfg/chainhash" | ||
"github.com/btcsuite/btcd/wire" | ||
"github.com/btcsuite/btcwallet/waddrmgr" | ||
) | ||
|
||
// SPVChain is an implementation of the btcwalet chain.Interface interface. | ||
type SPVChain struct { | ||
cs *ChainService | ||
} | ||
|
||
// NewSPVChain creates a new SPVChain struct with a backing ChainService | ||
func NewSPVChain(chainService *ChainService) *SPVChain { | ||
return &SPVChain{ | ||
cs: chainService, | ||
} | ||
} | ||
|
||
// Start replicates the RPC client's Start method. | ||
func (s *SPVChain) Start() error { | ||
s.cs.Start() | ||
return nil | ||
} | ||
|
||
// Stop replicates the RPC client's Stop method. | ||
func (s *SPVChain) Stop() { | ||
s.cs.Stop() | ||
} | ||
|
||
// WaitForShutdown replicates the RPC client's WaitForShutdown method. | ||
func (s *SPVChain) WaitForShutdown() { | ||
s.cs.Stop() | ||
} | ||
|
||
// SendRawTransaction replicates the RPC client's SendRawTransaction command. | ||
func (s *SPVChain) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) ( | ||
*chainhash.Hash, error) { | ||
err := s.cs.SendTransaction(tx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
hash := tx.TxHash() | ||
return &hash, nil | ||
} | ||
|
||
// GetBlock replicates the RPC client's GetBlock command. | ||
func (s *SPVChain) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) { | ||
block, err := s.cs.GetBlockFromNetwork(*hash) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return block.MsgBlock(), nil | ||
} | ||
|
||
// GetBestBlock replicates the RPC client's GetBestBlock command. | ||
func (s *SPVChain) GetBestBlock() (*chainhash.Hash, int32, error) { | ||
header, height, err := s.cs.LatestBlock() | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
hash := header.BlockHash() | ||
return &hash, int32(height), nil | ||
} | ||
|
||
// BlockStamp replicates the RPC client's BlockStamp command. | ||
func (s *SPVChain) BlockStamp() (*waddrmgr.BlockStamp, error) { | ||
return s.cs.SyncedTo() | ||
} |
Oops, something went wrong.