From 2eb1936cce3a4b3c493ccc43a277b0b61c98a7c3 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 15 Oct 2016 14:07:05 -0700 Subject: [PATCH] lnwallet: extend the WalletController with a new txn pub/sub client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new simple interface related to the WalletController which allows for subscribing to new notifications as transactions relevant to the wallet are seen on at the network and/or mined. The TransactionSubscription interface will prove useful for building higher level UI’s on-top of the daemon which update the presentation layer in response to received notifications. --- lnwallet/interface.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 0d4b3c9a9..5a9b5880a 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -72,6 +72,24 @@ type TransactionDetail struct { // TotalFees is the total fee in satoshis paid by this transaction. TotalFees int64 } + +// TransactionSubscription is an interface which describes an object capable of +// receiving notifications of new transaction related to the underlying wallet. +// TODO(roasbeef): add balance updates? +type TransactionSubscription interface { + // ConfirmedTransactions returns a channel which will be sent on as new + // relevant transactions are confirmed. + ConfirmedTransactions() chan *TransactionDetail + + // UnconfirmedTransactions returns a channel which will be sent on as + // new relevant transactions are seen within the network. + UnconfirmedTransactions() chan *TransactionDetail + + // Cancel finalizes the subscription, cleaning up any resources + // allocated. + Cancel() +} + // WalletController defines an abstract interface for controlling a local Pure // Go wallet, a local or remote wallet via an RPC mechanism, or possibly even // a daemon assisted hardware wallet. This interface serves the purpose of @@ -151,6 +169,17 @@ type WalletController interface { // then finally broadcasts the passed transaction to the Bitcoin network. PublishTransaction(tx *wire.MsgTx) error + // SubscribeTransactions returns a TransactionSubscription client which + // is capable of receiving async notifications as new transactions + // related to the wallet are seen within the network, or found in + // blocks. + // + // NOTE: a non-nil error shuold be returned if notifications aren't + // supported. + // + // TODO(roasbeef): make distinct interface? + SubscribeTransactions() (TransactionSubscription, error) + // Start initializes the wallet, making any neccessary connections, // starting up required goroutines etc. Start() error