Modify websocket endpoint from 'frontend' to 'ws'.

This commit is contained in:
Josh Rickmar 2014-06-12 12:54:58 -05:00
parent ec92578194
commit 3ff16d7539
5 changed files with 34 additions and 31 deletions

View file

@ -6,7 +6,7 @@ btcwallet
btcwallet is a daemon handling bitcoin wallet functionality for a
single user. It acts as both an RPC client to btcd and an RPC server
for wallet frontends and legacy RPC applications.
for wallet clients and legacy RPC applications.
The wallet file format is based on
[Armory](https://github.com/etotheipi/BitcoinArmory) and provides a
@ -14,7 +14,7 @@ deterministic wallet where all future generated private keys can be
recovered from a previous wallet backup. Unencrypted wallets are
unsupported and are never written to disk. This design decision has
the consequence of generating new wallets on the fly impossible: a
frontend is required to provide a wallet encryption passphrase.
client is required to provide a wallet encryption passphrase.
btcwallet is not an SPV client and requires connecting to a local or
remote btcd instance for asynchronous blockchain queries and
@ -24,7 +24,7 @@ can be found [here](https://github.com/conformal/btcd).
As a daemon, btcwallet provides no user interface and an additional
graphical or command line client is required for normal, personal
wallet usage. Conformal has written
[btcgui](https://github.com/conformal/btcgui) as a graphical frontend
[btcgui](https://github.com/conformal/btcgui) as a graphical client
to btcwallet.
This project is currently under active development is not production
@ -108,12 +108,12 @@ $ $EDITOR ~/.btcd/btcd.conf
$ $EDITOR ~/.btcwallet/btcwallet.conf
```
## Frontend Usage
## Client Usage
Frontends wishing to use btcwallet must connect to the path
`/frontend` over a websocket connection. Messages sent to btcwallet
over this websocket are expected to follow the standard Bitcoin JSON
API (partially documented
Clients wishing to use btcwallet must connect to the `ws` endpoint
over a websocket connection. Messages sent to btcwallet over this
websocket are expected to follow the standard Bitcoin JSON API
(partially documented
[here](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list)).
Websocket connections also enable additional API extensions and
JSON-RPC notifications (currently undocumented). The btcd packages

View file

@ -630,7 +630,7 @@ func (am *AccountManager) Rollback(height int32, hash *btcwire.ShaHash) error {
return nil
}
// BlockNotify notifies all frontends of any changes from the new block,
// BlockNotify notifies all wallet clients of any changes from the new block,
// including changed balances. Each account is then set to be synced
// with the latest block.
func (am *AccountManager) BlockNotify(bs *wallet.BlockStamp) {

5
cmd.go
View file

@ -178,8 +178,7 @@ func main() {
os.Exit(1)
}
// Start HTTP server to listen and send messages to frontend and btcd
// backend. Try reconnection if connection failed.
// Start HTTP server to serve wallet client connections.
server.Start()
// Begin maintanence goroutines.
@ -194,6 +193,8 @@ func main() {
NotifyBalanceSyncerChans.remove,
NotifyBalanceSyncerChans.access)
// Start client connection to a btcd chain server. Attempt
// reconnections if the client could not be successfully connected.
clientChan := make(chan *rpcClient)
go clientAccess(clientChan)
clientConnect(certs, clientChan)

View file

@ -135,7 +135,7 @@ func (n blockConnected) handleNotification() error {
}
AcctMgr.BlockNotify(bs)
// Pass notification to frontends too.
// Pass notification to wallet clients too.
if server != nil {
// TODO: marshaling should be perfomred by the server, and
// sent only to client that have requested the notification.
@ -163,7 +163,7 @@ func (n blockDisconnected) handleNotification() error {
return err
}
// Pass notification to frontends too.
// Pass notification to wallet clients too.
if server != nil {
// TODO: marshaling should be perfomred by the server, and
// sent only to client that have requested the notification.
@ -260,10 +260,10 @@ func (n recvTx) handleNotification() error {
}
AcctMgr.ds.ScheduleTxStoreWrite(a)
// Notify frontends of tx. If the tx is unconfirmed, it is always
// Notify wallet clients of tx. If the tx is unconfirmed, it is always
// notified and the outpoint is marked as notified. If the outpoint
// has already been notified and is now in a block, a txmined notifiction
// should be sent once to let frontends that all previous send/recvs
// should be sent once to let wallet clients that all previous send/recvs
// for this unconfirmed tx are now confirmed.
op := *cred.OutPoint()
previouslyNotifiedReq := NotifiedRecvTxRequest{
@ -274,7 +274,7 @@ func (n recvTx) handleNotification() error {
if <-previouslyNotifiedReq.response {
NotifiedRecvTxChans.remove <- op
} else {
// Notify frontends of new recv tx and mark as notified.
// Notify clients of new recv tx and mark as notified.
NotifiedRecvTxChans.add <- op
ltr, err := cred.ToJSON(a.Name(), bs.Height, a.Wallet.Net())
@ -284,7 +284,7 @@ func (n recvTx) handleNotification() error {
server.NotifyNewTxDetails(a.Name(), ltr)
}
// Notify frontends of new account balance.
// Notify clients of new account balance.
confirmed := a.CalculateBalance(1)
unconfirmed := a.CalculateBalance(0) - confirmed
server.NotifyWalletBalance(a.name, confirmed)

View file

@ -320,7 +320,7 @@ func (s *rpcServer) Start() {
}
s.PostClientRPC(w, r)
})
serveMux.HandleFunc("/frontend", func(w http.ResponseWriter, r *http.Request) {
serveMux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
authenticated := false
switch s.checkAuthHeader(r) {
case nil:
@ -1350,7 +1350,7 @@ func KeypoolRefill(icmd btcjson.Cmd) (interface{}, error) {
return nil, nil
}
// NotifyNewBlockChainHeight notifies all frontends of a new
// NotifyNewBlockChainHeight notifies all websocket clients of a new
// blockchain height. This sends the same notification as
// btcd, so this can probably be removed.
func (s *rpcServer) NotifyNewBlockChainHeight(bs *wallet.BlockStamp) {
@ -1363,8 +1363,8 @@ func (s *rpcServer) NotifyNewBlockChainHeight(bs *wallet.BlockStamp) {
s.broadcasts <- mntfn
}
// NotifyBalances notifies an attached frontend of the current confirmed
// and unconfirmed account balances.
// NotifyBalances notifies an attached websocket clients of the current
// confirmed and unconfirmed account balances.
//
// TODO(jrick): Switch this to return a single JSON object
// (map[string]interface{}) of all accounts and their balances, instead of
@ -2060,7 +2060,7 @@ func handleSendRawTxReply(icmd btcjson.Cmd, txSha *btcwire.ShaHash, a *Account,
}
AcctMgr.ds.ScheduleTxStoreWrite(a)
// Notify frontends of new SendTx.
// Notify websocket clients of the transaction.
bs, err := GetCurBlock()
if err == nil {
ltr, err := debits.ToJSON(a.Name(), bs.Height, a.Net())
@ -2082,7 +2082,7 @@ func handleSendRawTxReply(icmd btcjson.Cmd, txSha *btcwire.ShaHash, a *Account,
return err
}
// Notify all frontends of account's new unconfirmed and
// Notify websocket clients of account's new unconfirmed and
// confirmed balance.
confirmed := a.CalculateBalance(1)
unconfirmed := a.CalculateBalance(0) - confirmed
@ -2693,15 +2693,15 @@ func WalletPassphraseChange(icmd btcjson.Cmd) (interface{}, error) {
}
// AccountNtfn is a struct for marshalling any generic notification
// about a account for a wallet frontend.
// about a account for a websocket client.
//
// TODO(jrick): move to btcjson so it can be shared with frontends?
// TODO(jrick): move to btcjson so it can be shared with clients?
type AccountNtfn struct {
Account string `json:"account"`
Notification interface{} `json:"notification"`
}
// NotifyWalletLockStateChange sends a notification to all frontends
// NotifyWalletLockStateChange sends a notification to all websocket clients
// that the wallet has just been locked or unlocked.
func (s *rpcServer) NotifyWalletLockStateChange(account string, locked bool) {
ntfn := btcws.NewWalletLockStateNtfn(account, locked)
@ -2715,7 +2715,7 @@ func (s *rpcServer) NotifyWalletLockStateChange(account string, locked bool) {
}
// NotifyWalletBalance sends a confirmed account balance notification
// to a frontend.
// to all websocket clients.
func (s *rpcServer) NotifyWalletBalance(account string, balance float64) {
ntfn := btcws.NewAccountBalanceNtfn(account, balance, true)
mntfn, err := ntfn.MarshalJSON()
@ -2728,7 +2728,7 @@ func (s *rpcServer) NotifyWalletBalance(account string, balance float64) {
}
// NotifyWalletBalanceUnconfirmed sends a confirmed account balance
// notification to a frontend.
// notification to all websocket clients.
func (s *rpcServer) NotifyWalletBalanceUnconfirmed(account string, balance float64) {
ntfn := btcws.NewAccountBalanceNtfn(account, balance, false)
mntfn, err := ntfn.MarshalJSON()
@ -2740,7 +2740,8 @@ func (s *rpcServer) NotifyWalletBalanceUnconfirmed(account string, balance float
s.broadcasts <- mntfn
}
// NotifyNewTxDetails sends details of a new transaction to a frontend.
// NotifyNewTxDetails sends details of a new transaction to all websocket
// clients.
func (s *rpcServer) NotifyNewTxDetails(account string, details btcjson.ListTransactionsResult) {
ntfn := btcws.NewTxNtfn(account, &details)
mntfn, err := ntfn.MarshalJSON()
@ -2777,7 +2778,7 @@ var NotifiedRecvTxChans = struct {
// StoreNotifiedMempoolRecvTxs maintains a set of previously-sent
// received transaction notifications originating from the btcd
// mempool. This is used to prevent duplicate frontend transaction
// mempool. This is used to prevent duplicate client transaction
// notifications once a mempool tx is mined into a block.
func StoreNotifiedMempoolRecvTxs(add, remove chan btcwire.OutPoint,
access chan NotifiedRecvTxRequest) {
@ -2831,7 +2832,8 @@ type NotifyBalanceRequest struct {
// NotifyBalanceSyncer maintains a map of block hashes to WaitGroups
// for worker goroutines that must finish before it is safe to notify
// frontends of a new balance in the blockconnected notification handler.
// websocket clientss of a new balance in the blockconnected notification
// handler.
func NotifyBalanceSyncer(add chan NotifyBalanceWorker,
remove chan btcwire.ShaHash,
access chan NotifyBalanceRequest) {