lnwallet+lnrpc: convert GetCurrentHeight to GetBestBlock in BlockChainIO

This commit expands the data returned by the current GetCurrentHeight
to also return the current best block hash, expanding the method into
GetBestBlock. Additionally, the current best BlockHash is also now
displayed within the GetInfo RPC call.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-22 12:34:51 -08:00
parent 3d32c4e90e
commit 782fc61dc1
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
4 changed files with 33 additions and 34 deletions

@ -256,16 +256,18 @@ message ListPeersResponse {
message GetInfoRequest{}
message GetInfoResponse {
string identity_pubkey = 1;
string alias = 2;
uint32 num_pending_channels = 2;
uint32 num_active_channels = 3;
uint32 num_pending_channels = 3;
uint32 num_active_channels = 4;
uint32 num_peers = 4;
uint32 num_peers = 5;
uint32 block_height = 5;
uint32 block_height = 6;
string block_hash = 8;
bool synced_to_chain = 6;
bool testnet = 7;
bool synced_to_chain = 9;
bool testnet = 10;
}
message ConfirmationUpdate {

@ -6,17 +6,12 @@ import (
"github.com/roasbeef/btcd/wire"
)
// GetCurrentHeight returns the current height of the known block within the
// main chain.
// GetBestBlock returns the current height and hash of the best known block
// within the main chain.
//
// This method is a part of the lnwallet.BlockChainIO interface.
func (b *BtcWallet) GetCurrentHeight() (int32, error) {
_, height, err := b.rpc.GetBestBlock()
if err != nil {
return 0, err
}
return height, nil
func (b *BtcWallet) GetBestBlock() (*wire.ShaHash, int32, error) {
return b.rpc.GetBestBlock()
}
// GetTxOut returns the original output referenced by the passed outpoint.

@ -114,7 +114,7 @@ type WalletController interface {
ConfirmedBalance(confs int32, witness bool) (btcutil.Amount, error)
// NewAddress returns the next external or internal address for the
// wallet dicatated by the value of the `change` paramter. If change is
// wallet dictated by the value of the `change` parameter. If change is
// true, then an internal address should be used, otherwise an external
// address should be returned. The type of address returned is dictated
// by the wallet's capabilities, and may be of type: p2sh, p2pkh,
@ -162,7 +162,7 @@ type WalletController interface {
LockOutpoint(o wire.OutPoint)
// UnlockOutpoint unlocks an previously locked output, marking it
// eligible for coin seleciton.
// eligible for coin selection.
UnlockOutpoint(o wire.OutPoint)
// PublishTransaction performs cursory validation (dust checks, etc),
@ -201,23 +201,24 @@ type WalletController interface {
// TODO(roasbeef): move to diff package perhaps?
// TODO(roasbeef): move publish txn here?
type BlockChainIO interface {
// GetCurrentHeight returns the current height of the valid most-work
// chain the implementation is aware of.
GetCurrentHeight() (int32, error)
// GetBestBlock returns the current height and block hash of the valid
// most-work chain the implementation is aware of.
GetBestBlock() (*wire.ShaHash, int32, error)
// GetTxOut returns the original output referenced by the passed
// outpoint.
GetUtxo(txid *wire.ShaHash, index uint32) (*wire.TxOut, error)
// GetTransaction returns the full transaction identified by the passed
// transaction ID.
GetTransaction(txid *wire.ShaHash) (*wire.MsgTx, error)
// transaction ID.
GetTransaction(txid *wire.ShaHash) (*wire.MsgTx, error)
// GetBlockHash returns the hash of the block in the best block chain at the
// given height.
// GetBlockHash returns the hash of the block in the best block chain
// at the given height.
GetBlockHash(blockHeight int64) (*wire.ShaHash, error)
// GetBlock returns a block by the given hash.
// GetBlock returns the block in the main chain identified by the given
// hash.
GetBlock(blockHash *wire.ShaHash) (*wire.MsgBlock, error)
}
@ -278,14 +279,14 @@ type Signer interface {
// transaction with the signature as defined within the passed
// SignDescriptor. This method should be capable of generating the
// proper input script for both regular p2wkh output and p2wkh outputs
// nested within a regualr p2sh output.
// nested within a regular p2sh output.
ComputeInputScript(tx *wire.MsgTx, signDesc *SignDescriptor) (*InputScript, error)
}
// WalletDriver represents a "driver" for a particular concrete
// WalletController implementation. A driver is indentified by a globally
// unique string identifier along with a 'New()' method which is responsible
// for initializing a particular WalletController concrete implementation.
// WalletController implementation. A driver is identified by a globally unique
// string identifier along with a 'New()' method which is responsible for
// initializing a particular WalletController concrete implementation.
type WalletDriver struct {
// WalletType is a string which uniquely identifes the WalletController
// that this driver, drives.
@ -293,8 +294,8 @@ type WalletDriver struct {
// New creates a new instance of a concrete WalletController
// implementation given a variadic set up arguments. The function takes
// a varidaic number of interface paramters in order to provide
// initialization flexibility, thereby accomodating several potential
// a varidaic number of interface parameters in order to provide
// initialization flexibility, thereby accommodating several potential
// WalletController implementations.
New func(args ...interface{}) (WalletController, error)
}
@ -337,7 +338,7 @@ func RegisterWallet(driver *WalletDriver) error {
return nil
}
// SupportedWallets returns a slice of strings that represents the walelt
// SupportedWallets returns a slice of strings that represents the wallet
// drivers that have been registered and are therefore supported.
//
// NOTE: This function is safe for concurrent access.

@ -422,7 +422,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
pendingChannels := r.server.fundingMgr.NumPendingChannels()
idPub := r.server.identityPriv.PubKey().SerializeCompressed()
currentHeight, err := r.server.bio.GetCurrentHeight()
bestHash, bestHeight, err := r.server.bio.GetBestBlock()
if err != nil {
return nil, err
}
@ -437,7 +437,8 @@ func (r *rpcServer) GetInfo(ctx context.Context,
NumPendingChannels: pendingChannels,
NumActiveChannels: activeChannels,
NumPeers: uint32(len(serverPeers)),
BlockHeight: uint32(currentHeight),
BlockHeight: uint32(bestHeight),
BlockHash: bestHash.String(),
SyncedToChain: isSynced,
Testnet: activeNetParams.Params == &chaincfg.TestNet3Params,
}, nil