Unexport private methods from legacyrpc package.

This unexports every RPC handler function, as well as the
Server.PostClientRPC method which was only called by this package.

Fixes #435.
This commit is contained in:
Josh Rickmar 2016-05-05 11:28:18 -04:00
parent 4d51f8358f
commit ce3bd39238
2 changed files with 154 additions and 154 deletions

View file

@ -78,84 +78,84 @@ var rpcHandlers = map[string]struct {
noHelp bool noHelp bool
}{ }{
// Reference implementation wallet methods (implemented) // Reference implementation wallet methods (implemented)
"addmultisigaddress": {handler: AddMultiSigAddress}, "addmultisigaddress": {handler: addMultiSigAddress},
"createmultisig": {handler: CreateMultiSig}, "createmultisig": {handler: createMultiSig},
"dumpprivkey": {handler: DumpPrivKey}, "dumpprivkey": {handler: dumpPrivKey},
"getaccount": {handler: GetAccount}, "getaccount": {handler: getAccount},
"getaccountaddress": {handler: GetAccountAddress}, "getaccountaddress": {handler: getAccountAddress},
"getaddressesbyaccount": {handler: GetAddressesByAccount}, "getaddressesbyaccount": {handler: getAddressesByAccount},
"getbalance": {handler: GetBalance}, "getbalance": {handler: getBalance},
"getbestblockhash": {handler: GetBestBlockHash}, "getbestblockhash": {handler: getBestBlockHash},
"getblockcount": {handler: GetBlockCount}, "getblockcount": {handler: getBlockCount},
"getinfo": {handlerWithChain: GetInfo}, "getinfo": {handlerWithChain: getInfo},
"getnewaddress": {handler: GetNewAddress}, "getnewaddress": {handler: getNewAddress},
"getrawchangeaddress": {handler: GetRawChangeAddress}, "getrawchangeaddress": {handler: getRawChangeAddress},
"getreceivedbyaccount": {handler: GetReceivedByAccount}, "getreceivedbyaccount": {handler: getReceivedByAccount},
"getreceivedbyaddress": {handler: GetReceivedByAddress}, "getreceivedbyaddress": {handler: getReceivedByAddress},
"gettransaction": {handler: GetTransaction}, "gettransaction": {handler: getTransaction},
"help": {handler: HelpNoChainRPC, handlerWithChain: HelpWithChainRPC}, "help": {handler: helpNoChainRPC, handlerWithChain: helpWithChainRPC},
"importprivkey": {handler: ImportPrivKey}, "importprivkey": {handler: importPrivKey},
"keypoolrefill": {handler: KeypoolRefill}, "keypoolrefill": {handler: keypoolRefill},
"listaccounts": {handler: ListAccounts}, "listaccounts": {handler: listAccounts},
"listlockunspent": {handler: ListLockUnspent}, "listlockunspent": {handler: listLockUnspent},
"listreceivedbyaccount": {handler: ListReceivedByAccount}, "listreceivedbyaccount": {handler: listReceivedByAccount},
"listreceivedbyaddress": {handler: ListReceivedByAddress}, "listreceivedbyaddress": {handler: listReceivedByAddress},
"listsinceblock": {handlerWithChain: ListSinceBlock}, "listsinceblock": {handlerWithChain: listSinceBlock},
"listtransactions": {handler: ListTransactions}, "listtransactions": {handler: listTransactions},
"listunspent": {handler: ListUnspent}, "listunspent": {handler: listUnspent},
"lockunspent": {handler: LockUnspent}, "lockunspent": {handler: lockUnspent},
"sendfrom": {handlerWithChain: SendFrom}, "sendfrom": {handlerWithChain: sendFrom},
"sendmany": {handler: SendMany}, "sendmany": {handler: sendMany},
"sendtoaddress": {handler: SendToAddress}, "sendtoaddress": {handler: sendToAddress},
"settxfee": {handler: SetTxFee}, "settxfee": {handler: setTxFee},
"signmessage": {handler: SignMessage}, "signmessage": {handler: signMessage},
"signrawtransaction": {handlerWithChain: SignRawTransaction}, "signrawtransaction": {handlerWithChain: signRawTransaction},
"validateaddress": {handler: ValidateAddress}, "validateaddress": {handler: validateAddress},
"verifymessage": {handler: VerifyMessage}, "verifymessage": {handler: verifyMessage},
"walletlock": {handler: WalletLock}, "walletlock": {handler: walletLock},
"walletpassphrase": {handler: WalletPassphrase}, "walletpassphrase": {handler: walletPassphrase},
"walletpassphrasechange": {handler: WalletPassphraseChange}, "walletpassphrasechange": {handler: walletPassphraseChange},
// Reference implementation methods (still unimplemented) // Reference implementation methods (still unimplemented)
"backupwallet": {handler: Unimplemented, noHelp: true}, "backupwallet": {handler: unimplemented, noHelp: true},
"dumpwallet": {handler: Unimplemented, noHelp: true}, "dumpwallet": {handler: unimplemented, noHelp: true},
"getwalletinfo": {handler: Unimplemented, noHelp: true}, "getwalletinfo": {handler: unimplemented, noHelp: true},
"importwallet": {handler: Unimplemented, noHelp: true}, "importwallet": {handler: unimplemented, noHelp: true},
"listaddressgroupings": {handler: Unimplemented, noHelp: true}, "listaddressgroupings": {handler: unimplemented, noHelp: true},
// Reference methods which can't be implemented by btcwallet due to // Reference methods which can't be implemented by btcwallet due to
// design decision differences // design decision differences
"encryptwallet": {handler: Unsupported, noHelp: true}, "encryptwallet": {handler: unsupported, noHelp: true},
"move": {handler: Unsupported, noHelp: true}, "move": {handler: unsupported, noHelp: true},
"setaccount": {handler: Unsupported, noHelp: true}, "setaccount": {handler: unsupported, noHelp: true},
// Extensions to the reference client JSON-RPC API // Extensions to the reference client JSON-RPC API
"createnewaccount": {handler: CreateNewAccount}, "createnewaccount": {handler: createNewAccount},
"exportwatchingwallet": {handler: ExportWatchingWallet}, "exportwatchingwallet": {handler: exportWatchingWallet},
"getbestblock": {handler: GetBestBlock}, "getbestblock": {handler: getBestBlock},
// This was an extension but the reference implementation added it as // This was an extension but the reference implementation added it as
// well, but with a different API (no account parameter). It's listed // well, but with a different API (no account parameter). It's listed
// here because it hasn't been update to use the reference // here because it hasn't been update to use the reference
// implemenation's API. // implemenation's API.
"getunconfirmedbalance": {handler: GetUnconfirmedBalance}, "getunconfirmedbalance": {handler: getUnconfirmedBalance},
"listaddresstransactions": {handler: ListAddressTransactions}, "listaddresstransactions": {handler: listAddressTransactions},
"listalltransactions": {handler: ListAllTransactions}, "listalltransactions": {handler: listAllTransactions},
"renameaccount": {handler: RenameAccount}, "renameaccount": {handler: renameAccount},
"walletislocked": {handler: WalletIsLocked}, "walletislocked": {handler: walletIsLocked},
} }
// Unimplemented handles an unimplemented RPC request with the // unimplemented handles an unimplemented RPC request with the
// appropiate error. // appropiate error.
func Unimplemented(interface{}, *wallet.Wallet) (interface{}, error) { func unimplemented(interface{}, *wallet.Wallet) (interface{}, error) {
return nil, &btcjson.RPCError{ return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCUnimplemented, Code: btcjson.ErrRPCUnimplemented,
Message: "Method unimplemented", Message: "Method unimplemented",
} }
} }
// Unsupported handles a standard bitcoind RPC request which is // unsupported handles a standard bitcoind RPC request which is
// unsupported by btcwallet due to design differences. // unsupported by btcwallet due to design differences.
func Unsupported(interface{}, *wallet.Wallet) (interface{}, error) { func unsupported(interface{}, *wallet.Wallet) (interface{}, error) {
return nil, &btcjson.RPCError{ return nil, &btcjson.RPCError{
Code: -1, Code: -1,
Message: "Request unsupported by btcwallet", Message: "Request unsupported by btcwallet",
@ -316,9 +316,9 @@ func makeMultiSigScript(w *wallet.Wallet, keys []string, nRequired int) ([]byte,
return txscript.MultiSigScript(keysesPrecious, nRequired) return txscript.MultiSigScript(keysesPrecious, nRequired)
} }
// AddMultiSigAddress handles an addmultisigaddress request by adding a // addMultiSigAddress handles an addmultisigaddress request by adding a
// multisig address to the given wallet. // multisig address to the given wallet.
func AddMultiSigAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func addMultiSigAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.AddMultisigAddressCmd) cmd := icmd.(*btcjson.AddMultisigAddressCmd)
// If an account is specified, ensure that is the imported account. // If an account is specified, ensure that is the imported account.
@ -345,9 +345,9 @@ func AddMultiSigAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)
return addr.Address().EncodeAddress(), nil return addr.Address().EncodeAddress(), nil
} }
// CreateMultiSig handles an createmultisig request by returning a // createMultiSig handles an createmultisig request by returning a
// multisig address for the given inputs. // multisig address for the given inputs.
func CreateMultiSig(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func createMultiSig(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.CreateMultisigCmd) cmd := icmd.(*btcjson.CreateMultisigCmd)
script, err := makeMultiSigScript(w, cmd.Keys, cmd.NRequired) script, err := makeMultiSigScript(w, cmd.Keys, cmd.NRequired)
@ -367,10 +367,10 @@ func CreateMultiSig(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
}, nil }, nil
} }
// DumpPrivKey handles a dumpprivkey request with the private key // dumpPrivKey handles a dumpprivkey request with the private key
// for a single address, or an appropiate error if the wallet // for a single address, or an appropiate error if the wallet
// is locked. // is locked.
func DumpPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func dumpPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.DumpPrivKeyCmd) cmd := icmd.(*btcjson.DumpPrivKeyCmd)
addr, err := decodeAddress(cmd.Address, w.ChainParams()) addr, err := decodeAddress(cmd.Address, w.ChainParams())
@ -387,10 +387,10 @@ func DumpPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return key, err return key, err
} }
// DumpWallet handles a dumpwallet request by returning all private // dumpWallet handles a dumpwallet request by returning all private
// keys in a wallet, or an appropiate error if the wallet is locked. // keys in a wallet, or an appropiate error if the wallet is locked.
// TODO: finish this to match bitcoind by writing the dump to a file. // TODO: finish this to match bitcoind by writing the dump to a file.
func DumpWallet(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func dumpWallet(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
keys, err := w.DumpPrivKeys() keys, err := w.DumpPrivKeys()
if waddrmgr.IsError(err, waddrmgr.ErrLocked) { if waddrmgr.IsError(err, waddrmgr.ErrLocked) {
return nil, &ErrWalletUnlockNeeded return nil, &ErrWalletUnlockNeeded
@ -399,10 +399,10 @@ func DumpWallet(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return keys, err return keys, err
} }
// ExportWatchingWallet handles an exportwatchingwallet request by exporting the // exportWatchingWallet handles an exportwatchingwallet request by exporting the
// current wallet as a watching wallet (with no private keys), and returning // current wallet as a watching wallet (with no private keys), and returning
// base64-encoding of serialized account files. // base64-encoding of serialized account files.
func ExportWatchingWallet(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func exportWatchingWallet(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ExportWatchingWalletCmd) cmd := icmd.(*btcjson.ExportWatchingWalletCmd)
if cmd.Account != nil && *cmd.Account != "*" { if cmd.Account != nil && *cmd.Account != "*" {
@ -415,10 +415,10 @@ func ExportWatchingWallet(icmd interface{}, w *wallet.Wallet) (interface{}, erro
return w.ExportWatchingWallet() return w.ExportWatchingWallet()
} }
// GetAddressesByAccount handles a getaddressesbyaccount request by returning // getAddressesByAccount handles a getaddressesbyaccount request by returning
// all addresses for an account, or an error if the requested account does // all addresses for an account, or an error if the requested account does
// not exist. // not exist.
func GetAddressesByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getAddressesByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetAddressesByAccountCmd) cmd := icmd.(*btcjson.GetAddressesByAccountCmd)
account, err := w.Manager.LookupAccount(cmd.Account) account, err := w.Manager.LookupAccount(cmd.Account)
@ -435,10 +435,10 @@ func GetAddressesByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, err
return addrStrs, err return addrStrs, err
} }
// GetBalance handles a getbalance request by returning the balance for an // getBalance handles a getbalance request by returning the balance for an
// account (wallet), or an error if the requested account does not // account (wallet), or an error if the requested account does not
// exist. // exist.
func GetBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetBalanceCmd) cmd := icmd.(*btcjson.GetBalanceCmd)
var balance btcutil.Amount var balance btcutil.Amount
@ -467,9 +467,9 @@ func GetBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return balance.ToBTC(), nil return balance.ToBTC(), nil
} }
// GetBestBlock handles a getbestblock request by returning a JSON object // getBestBlock handles a getbestblock request by returning a JSON object
// with the height and hash of the most recently processed block. // with the height and hash of the most recently processed block.
func GetBestBlock(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getBestBlock(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
blk := w.Manager.SyncedTo() blk := w.Manager.SyncedTo()
result := &btcjson.GetBestBlockResult{ result := &btcjson.GetBestBlockResult{
Hash: blk.Hash.String(), Hash: blk.Hash.String(),
@ -478,24 +478,24 @@ func GetBestBlock(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return result, nil return result, nil
} }
// GetBestBlockHash handles a getbestblockhash request by returning the hash // getBestBlockHash handles a getbestblockhash request by returning the hash
// of the most recently processed block. // of the most recently processed block.
func GetBestBlockHash(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getBestBlockHash(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
blk := w.Manager.SyncedTo() blk := w.Manager.SyncedTo()
return blk.Hash.String(), nil return blk.Hash.String(), nil
} }
// GetBlockCount handles a getblockcount request by returning the chain height // getBlockCount handles a getblockcount request by returning the chain height
// of the most recently processed block. // of the most recently processed block.
func GetBlockCount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getBlockCount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
blk := w.Manager.SyncedTo() blk := w.Manager.SyncedTo()
return blk.Height, nil return blk.Height, nil
} }
// GetInfo handles a getinfo request by returning the a structure containing // getInfo handles a getinfo request by returning the a structure containing
// information about the current state of btcwallet. // information about the current state of btcwallet.
// exist. // exist.
func GetInfo(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) { func getInfo(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) {
// Call down to btcd for all of the information in this command known // Call down to btcd for all of the information in this command known
// by them. // by them.
info, err := chainClient.GetInfo() info, err := chainClient.GetInfo()
@ -541,9 +541,9 @@ func decodeAddress(s string, params *chaincfg.Params) (btcutil.Address, error) {
return addr, nil return addr, nil
} }
// GetAccount handles a getaccount request by returning the account name // getAccount handles a getaccount request by returning the account name
// associated with a single address. // associated with a single address.
func GetAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetAccountCmd) cmd := icmd.(*btcjson.GetAccountCmd)
addr, err := decodeAddress(cmd.Address, w.ChainParams()) addr, err := decodeAddress(cmd.Address, w.ChainParams())
@ -564,13 +564,13 @@ func GetAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return acctName, nil return acctName, nil
} }
// GetAccountAddress handles a getaccountaddress by returning the most // getAccountAddress handles a getaccountaddress by returning the most
// recently-created chained address that has not yet been used (does not yet // recently-created chained address that has not yet been used (does not yet
// appear in the blockchain, or any tx that has arrived in the btcd mempool). // appear in the blockchain, or any tx that has arrived in the btcd mempool).
// If the most recently-requested address has been used, a new address (the // If the most recently-requested address has been used, a new address (the
// next chained address in the keypool) is used. This can fail if the keypool // next chained address in the keypool) is used. This can fail if the keypool
// runs out (and will return btcjson.ErrRPCWalletKeypoolRanOut if that happens). // runs out (and will return btcjson.ErrRPCWalletKeypoolRanOut if that happens).
func GetAccountAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getAccountAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetAccountAddressCmd) cmd := icmd.(*btcjson.GetAccountAddressCmd)
account, err := w.Manager.LookupAccount(cmd.Account) account, err := w.Manager.LookupAccount(cmd.Account)
@ -585,9 +585,9 @@ func GetAccountAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)
return addr.EncodeAddress(), err return addr.EncodeAddress(), err
} }
// GetUnconfirmedBalance handles a getunconfirmedbalance extension request // getUnconfirmedBalance handles a getunconfirmedbalance extension request
// by returning the current unconfirmed balance of an account. // by returning the current unconfirmed balance of an account.
func GetUnconfirmedBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getUnconfirmedBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetUnconfirmedBalanceCmd) cmd := icmd.(*btcjson.GetUnconfirmedBalanceCmd)
acctName := "default" acctName := "default"
@ -606,9 +606,9 @@ func GetUnconfirmedBalance(icmd interface{}, w *wallet.Wallet) (interface{}, err
return (bals.Total - bals.Spendable).ToBTC(), nil return (bals.Total - bals.Spendable).ToBTC(), nil
} }
// ImportPrivKey handles an importprivkey request by parsing // importPrivKey handles an importprivkey request by parsing
// a WIF-encoded private key and adding it to an account. // a WIF-encoded private key and adding it to an account.
func ImportPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func importPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ImportPrivKeyCmd) cmd := icmd.(*btcjson.ImportPrivKeyCmd)
// Ensure that private keys are only imported to the correct account. // Ensure that private keys are only imported to the correct account.
@ -645,16 +645,16 @@ func ImportPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return nil, err return nil, err
} }
// KeypoolRefill handles the keypoolrefill command. Since we handle the keypool // keypoolRefill handles the keypoolrefill command. Since we handle the keypool
// automatically this does nothing since refilling is never manually required. // automatically this does nothing since refilling is never manually required.
func KeypoolRefill(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func keypoolRefill(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return nil, nil return nil, nil
} }
// CreateNewAccount handles a createnewaccount request by creating and // createNewAccount handles a createnewaccount request by creating and
// returning a new account. If the last account has no transaction history // returning a new account. If the last account has no transaction history
// as per BIP 0044 a new account cannot be created so an error will be returned. // as per BIP 0044 a new account cannot be created so an error will be returned.
func CreateNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func createNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.CreateNewAccountCmd) cmd := icmd.(*btcjson.CreateNewAccountCmd)
// The wildcard * is reserved by the rpc server with the special meaning // The wildcard * is reserved by the rpc server with the special meaning
@ -690,9 +690,9 @@ func CreateNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return nil, err return nil, err
} }
// RenameAccount handles a renameaccount request by renaming an account. // renameAccount handles a renameaccount request by renaming an account.
// If the account does not exist an appropiate error will be returned. // If the account does not exist an appropiate error will be returned.
func RenameAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func renameAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.RenameAccountCmd) cmd := icmd.(*btcjson.RenameAccountCmd)
// The wildcard * is reserved by the rpc server with the special meaning // The wildcard * is reserved by the rpc server with the special meaning
@ -709,12 +709,12 @@ func RenameAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return nil, w.RenameAccount(account, cmd.NewAccount) return nil, w.RenameAccount(account, cmd.NewAccount)
} }
// GetNewAddress handles a getnewaddress request by returning a new // getNewAddress handles a getnewaddress request by returning a new
// address for an account. If the account does not exist an appropiate // address for an account. If the account does not exist an appropiate
// error is returned. // error is returned.
// TODO: Follow BIP 0044 and warn if number of unused addresses exceeds // TODO: Follow BIP 0044 and warn if number of unused addresses exceeds
// the gap limit. // the gap limit.
func GetNewAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getNewAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetNewAddressCmd) cmd := icmd.(*btcjson.GetNewAddressCmd)
acctName := "default" acctName := "default"
@ -734,12 +734,12 @@ func GetNewAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return addr.EncodeAddress(), nil return addr.EncodeAddress(), nil
} }
// GetRawChangeAddress handles a getrawchangeaddress request by creating // getRawChangeAddress handles a getrawchangeaddress request by creating
// and returning a new change address for an account. // and returning a new change address for an account.
// //
// Note: bitcoind allows specifying the account as an optional parameter, // Note: bitcoind allows specifying the account as an optional parameter,
// but ignores the parameter. // but ignores the parameter.
func GetRawChangeAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getRawChangeAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetRawChangeAddressCmd) cmd := icmd.(*btcjson.GetRawChangeAddressCmd)
acctName := "default" acctName := "default"
@ -759,9 +759,9 @@ func GetRawChangeAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error
return addr.EncodeAddress(), nil return addr.EncodeAddress(), nil
} }
// GetReceivedByAccount handles a getreceivedbyaccount request by returning // getReceivedByAccount handles a getreceivedbyaccount request by returning
// the total amount received by addresses of an account. // the total amount received by addresses of an account.
func GetReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetReceivedByAccountCmd) cmd := icmd.(*btcjson.GetReceivedByAccountCmd)
account, err := w.Manager.LookupAccount(cmd.Account) account, err := w.Manager.LookupAccount(cmd.Account)
@ -777,9 +777,9 @@ func GetReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, erro
return bal.ToBTC(), nil return bal.ToBTC(), nil
} }
// GetReceivedByAddress handles a getreceivedbyaddress request by returning // getReceivedByAddress handles a getreceivedbyaddress request by returning
// the total amount received by a single address. // the total amount received by a single address.
func GetReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetReceivedByAddressCmd) cmd := icmd.(*btcjson.GetReceivedByAddressCmd)
addr, err := decodeAddress(cmd.Address, w.ChainParams()) addr, err := decodeAddress(cmd.Address, w.ChainParams())
@ -794,9 +794,9 @@ func GetReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, erro
return total.ToBTC(), nil return total.ToBTC(), nil
} }
// GetTransaction handles a gettransaction request by returning details about // getTransaction handles a gettransaction request by returning details about
// a single transaction saved by wallet. // a single transaction saved by wallet.
func GetTransaction(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func getTransaction(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.GetTransactionCmd) cmd := icmd.(*btcjson.GetTransactionCmd)
txSha, err := wire.NewShaHashFromStr(cmd.Txid) txSha, err := wire.NewShaHashFromStr(cmd.Txid)
@ -953,18 +953,18 @@ func GetTransaction(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
var helpDescs map[string]string var helpDescs map[string]string
var helpDescsMu sync.Mutex // Help may execute concurrently, so synchronize access. var helpDescsMu sync.Mutex // Help may execute concurrently, so synchronize access.
// HelpWithChainRPC handles the help request when the RPC server has been // helpWithChainRPC handles the help request when the RPC server has been
// associated with a consensus RPC client. The additional RPC client is used to // associated with a consensus RPC client. The additional RPC client is used to
// include help messages for methods implemented by the consensus server via RPC // include help messages for methods implemented by the consensus server via RPC
// passthrough. // passthrough.
func HelpWithChainRPC(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) { func helpWithChainRPC(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) {
return help(icmd, w, chainClient) return help(icmd, w, chainClient)
} }
// HelpNoChainRPC handles the help request when the RPC server has not been // helpNoChainRPC handles the help request when the RPC server has not been
// associated with a consensus RPC client. No help messages are included for // associated with a consensus RPC client. No help messages are included for
// passthrough requests. // passthrough requests.
func HelpNoChainRPC(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func helpNoChainRPC(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return help(icmd, w, nil) return help(icmd, w, nil)
} }
@ -1052,9 +1052,9 @@ func help(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (int
} }
} }
// ListAccounts handles a listaccounts request by returning a map of account // listAccounts handles a listaccounts request by returning a map of account
// names to their balances. // names to their balances.
func ListAccounts(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listAccounts(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ListAccountsCmd) cmd := icmd.(*btcjson.ListAccountsCmd)
accountBalances := map[string]float64{} accountBalances := map[string]float64{}
@ -1082,13 +1082,13 @@ func ListAccounts(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return accountBalances, nil return accountBalances, nil
} }
// ListLockUnspent handles a listlockunspent request by returning an slice of // listLockUnspent handles a listlockunspent request by returning an slice of
// all locked outpoints. // all locked outpoints.
func ListLockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listLockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return w.LockedOutpoints(), nil return w.LockedOutpoints(), nil
} }
// ListReceivedByAccount handles a listreceivedbyaccount request by returning // listReceivedByAccount handles a listreceivedbyaccount request by returning
// a slice of objects, each one containing: // a slice of objects, each one containing:
// "account": the receiving account; // "account": the receiving account;
// "amount": total amount received by the account; // "amount": total amount received by the account;
@ -1098,7 +1098,7 @@ func ListLockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
// default: one; // default: one;
// "includeempty": whether or not to include addresses that have no transactions - // "includeempty": whether or not to include addresses that have no transactions -
// default: false. // default: false.
func ListReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ListReceivedByAccountCmd) cmd := icmd.(*btcjson.ListReceivedByAccountCmd)
var accounts []uint32 var accounts []uint32
@ -1131,7 +1131,7 @@ func ListReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, err
return ret, nil return ret, nil
} }
// ListReceivedByAddress handles a listreceivedbyaddress request by returning // listReceivedByAddress handles a listreceivedbyaddress request by returning
// a slice of objects, each one containing: // a slice of objects, each one containing:
// "account": the account of the receiving address; // "account": the account of the receiving address;
// "address": the receiving address; // "address": the receiving address;
@ -1142,7 +1142,7 @@ func ListReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, err
// default: one; // default: one;
// "includeempty": whether or not to include addresses that have no transactions - // "includeempty": whether or not to include addresses that have no transactions -
// default: false. // default: false.
func ListReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ListReceivedByAddressCmd) cmd := icmd.(*btcjson.ListReceivedByAddressCmd)
// Intermediate data for each address. // Intermediate data for each address.
@ -1230,9 +1230,9 @@ func ListReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, err
return ret, nil return ret, nil
} }
// ListSinceBlock handles a listsinceblock request by returning an array of maps // listSinceBlock handles a listsinceblock request by returning an array of maps
// with details of sent and received wallet transactions since the given block. // with details of sent and received wallet transactions since the given block.
func ListSinceBlock(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) { func listSinceBlock(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) {
cmd := icmd.(*btcjson.ListSinceBlockCmd) cmd := icmd.(*btcjson.ListSinceBlockCmd)
syncBlock := w.Manager.SyncedTo() syncBlock := w.Manager.SyncedTo()
@ -1274,9 +1274,9 @@ func ListSinceBlock(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCCl
return res, nil return res, nil
} }
// ListTransactions handles a listtransactions request by returning an // listTransactions handles a listtransactions request by returning an
// array of maps with details of sent and recevied wallet transactions. // array of maps with details of sent and recevied wallet transactions.
func ListTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ListTransactionsCmd) cmd := icmd.(*btcjson.ListTransactionsCmd)
// TODO: ListTransactions does not currently understand the difference // TODO: ListTransactions does not currently understand the difference
@ -1296,12 +1296,12 @@ func ListTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return w.ListTransactions(*cmd.From, *cmd.Count) return w.ListTransactions(*cmd.From, *cmd.Count)
} }
// ListAddressTransactions handles a listaddresstransactions request by // listAddressTransactions handles a listaddresstransactions request by
// returning an array of maps with details of spent and received wallet // returning an array of maps with details of spent and received wallet
// transactions. The form of the reply is identical to listtransactions, // transactions. The form of the reply is identical to listtransactions,
// but the array elements are limited to transaction details which are // but the array elements are limited to transaction details which are
// about the addresess included in the request. // about the addresess included in the request.
func ListAddressTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listAddressTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ListAddressTransactionsCmd) cmd := icmd.(*btcjson.ListAddressTransactionsCmd)
if cmd.Account != nil && *cmd.Account != "*" { if cmd.Account != nil && *cmd.Account != "*" {
@ -1324,11 +1324,11 @@ func ListAddressTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, e
return w.ListAddressTransactions(hash160Map) return w.ListAddressTransactions(hash160Map)
} }
// ListAllTransactions handles a listalltransactions request by returning // listAllTransactions handles a listalltransactions request by returning
// a map with details of sent and recevied wallet transactions. This is // a map with details of sent and recevied wallet transactions. This is
// similar to ListTransactions, except it takes only a single optional // similar to ListTransactions, except it takes only a single optional
// argument for the account name and replies with all transactions. // argument for the account name and replies with all transactions.
func ListAllTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listAllTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ListAllTransactionsCmd) cmd := icmd.(*btcjson.ListAllTransactionsCmd)
if cmd.Account != nil && *cmd.Account != "*" { if cmd.Account != nil && *cmd.Account != "*" {
@ -1341,8 +1341,8 @@ func ListAllTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error
return w.ListAllTransactions() return w.ListAllTransactions()
} }
// ListUnspent handles the listunspent command. // listUnspent handles the listunspent command.
func ListUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func listUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ListUnspentCmd) cmd := icmd.(*btcjson.ListUnspentCmd)
var addresses map[string]struct{} var addresses map[string]struct{}
@ -1361,8 +1361,8 @@ func ListUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return w.ListUnspent(int32(*cmd.MinConf), int32(*cmd.MaxConf), addresses) return w.ListUnspent(int32(*cmd.MinConf), int32(*cmd.MaxConf), addresses)
} }
// LockUnspent handles the lockunspent command. // lockUnspent handles the lockunspent command.
func LockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func lockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.LockUnspentCmd) cmd := icmd.(*btcjson.LockUnspentCmd)
switch { switch {
@ -1444,12 +1444,12 @@ func isNilOrEmpty(s *string) bool {
return s == nil || *s == "" return s == nil || *s == ""
} }
// SendFrom handles a sendfrom RPC request by creating a new transaction // sendFrom handles a sendfrom RPC request by creating a new transaction
// spending unspent transaction outputs for a wallet to another payment // spending unspent transaction outputs for a wallet to another payment
// address. Leftover inputs not sent to the payment address or a fee for // address. Leftover inputs not sent to the payment address or a fee for
// the miner are sent back to a new address in the wallet. Upon success, // the miner are sent back to a new address in the wallet. Upon success,
// the TxID for the created transaction is returned. // the TxID for the created transaction is returned.
func SendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) { func sendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) {
cmd := icmd.(*btcjson.SendFromCmd) cmd := icmd.(*btcjson.SendFromCmd)
// Transaction comments are not yet supported. Error instead of // Transaction comments are not yet supported. Error instead of
@ -1486,12 +1486,12 @@ func SendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient)
return sendPairs(w, pairs, account, minConf) return sendPairs(w, pairs, account, minConf)
} }
// SendMany handles a sendmany RPC request by creating a new transaction // sendMany handles a sendmany RPC request by creating a new transaction
// spending unspent transaction outputs for a wallet to any number of // spending unspent transaction outputs for a wallet to any number of
// payment addresses. Leftover inputs not sent to the payment address // payment addresses. Leftover inputs not sent to the payment address
// or a fee for the miner are sent back to a new address in the wallet. // or a fee for the miner are sent back to a new address in the wallet.
// Upon success, the TxID for the created transaction is returned. // Upon success, the TxID for the created transaction is returned.
func SendMany(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func sendMany(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.SendManyCmd) cmd := icmd.(*btcjson.SendManyCmd)
// Transaction comments are not yet supported. Error instead of // Transaction comments are not yet supported. Error instead of
@ -1527,12 +1527,12 @@ func SendMany(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return sendPairs(w, pairs, account, minConf) return sendPairs(w, pairs, account, minConf)
} }
// SendToAddress handles a sendtoaddress RPC request by creating a new // sendToAddress handles a sendtoaddress RPC request by creating a new
// transaction spending unspent transaction outputs for a wallet to another // transaction spending unspent transaction outputs for a wallet to another
// payment address. Leftover inputs not sent to the payment address or a fee // payment address. Leftover inputs not sent to the payment address or a fee
// for the miner are sent back to a new address in the wallet. Upon success, // for the miner are sent back to a new address in the wallet. Upon success,
// the TxID for the created transaction is returned. // the TxID for the created transaction is returned.
func SendToAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func sendToAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.SendToAddressCmd) cmd := icmd.(*btcjson.SendToAddressCmd)
// Transaction comments are not yet supported. Error instead of // Transaction comments are not yet supported. Error instead of
@ -1563,8 +1563,8 @@ func SendToAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return sendPairs(w, pairs, waddrmgr.DefaultAccountNum, 1) return sendPairs(w, pairs, waddrmgr.DefaultAccountNum, 1)
} }
// SetTxFee sets the transaction fee per kilobyte added to transactions. // setTxFee sets the transaction fee per kilobyte added to transactions.
func SetTxFee(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func setTxFee(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.SetTxFeeCmd) cmd := icmd.(*btcjson.SetTxFeeCmd)
// Check that amount is not negative. // Check that amount is not negative.
@ -1582,9 +1582,9 @@ func SetTxFee(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return true, nil return true, nil
} }
// SignMessage signs the given message with the private key for the given // signMessage signs the given message with the private key for the given
// address // address
func SignMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func signMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.SignMessageCmd) cmd := icmd.(*btcjson.SignMessageCmd)
addr, err := decodeAddress(cmd.Address, w.ChainParams()) addr, err := decodeAddress(cmd.Address, w.ChainParams())
@ -1622,8 +1622,8 @@ func SignMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return base64.StdEncoding.EncodeToString(sigbytes), nil return base64.StdEncoding.EncodeToString(sigbytes), nil
} }
// SignRawTransaction handles the signrawtransaction command. // signRawTransaction handles the signrawtransaction command.
func SignRawTransaction(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) { func signRawTransaction(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error) {
cmd := icmd.(*btcjson.SignRawTransactionCmd) cmd := icmd.(*btcjson.SignRawTransactionCmd)
serializedTx, err := decodeHexStr(cmd.RawTx) serializedTx, err := decodeHexStr(cmd.RawTx)
@ -1796,8 +1796,8 @@ func SignRawTransaction(icmd interface{}, w *wallet.Wallet, chainClient *chain.R
}, nil }, nil
} }
// ValidateAddress handles the validateaddress command. // validateAddress handles the validateaddress command.
func ValidateAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func validateAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.ValidateAddressCmd) cmd := icmd.(*btcjson.ValidateAddressCmd)
result := btcjson.ValidateAddressWalletResult{} result := btcjson.ValidateAddressWalletResult{}
@ -1876,9 +1876,9 @@ func ValidateAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return result, nil return result, nil
} }
// VerifyMessage handles the verifymessage command by verifying the provided // verifyMessage handles the verifymessage command by verifying the provided
// compact signature for the given address and message. // compact signature for the given address and message.
func VerifyMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func verifyMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.VerifyMessageCmd) cmd := icmd.(*btcjson.VerifyMessageCmd)
addr, err := decodeAddress(cmd.Address, w.ChainParams()) addr, err := decodeAddress(cmd.Address, w.ChainParams())
@ -1921,25 +1921,25 @@ func VerifyMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
} }
} }
// WalletIsLocked handles the walletislocked extension request by // walletIsLocked handles the walletislocked extension request by
// returning the current lock state (false for unlocked, true for locked) // returning the current lock state (false for unlocked, true for locked)
// of an account. // of an account.
func WalletIsLocked(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func walletIsLocked(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return w.Locked(), nil return w.Locked(), nil
} }
// WalletLock handles a walletlock request by locking the all account // walletLock handles a walletlock request by locking the all account
// wallets, returning an error if any wallet is not encrypted (for example, // wallets, returning an error if any wallet is not encrypted (for example,
// a watching-only wallet). // a watching-only wallet).
func WalletLock(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func walletLock(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
w.Lock() w.Lock()
return nil, nil return nil, nil
} }
// WalletPassphrase responds to the walletpassphrase request by unlocking // walletPassphrase responds to the walletpassphrase request by unlocking
// the wallet. The decryption key is saved in the wallet until timeout // the wallet. The decryption key is saved in the wallet until timeout
// seconds expires, after which the wallet is locked. // seconds expires, after which the wallet is locked.
func WalletPassphrase(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func walletPassphrase(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.WalletPassphraseCmd) cmd := icmd.(*btcjson.WalletPassphraseCmd)
timeout := time.Second * time.Duration(cmd.Timeout) timeout := time.Second * time.Duration(cmd.Timeout)
@ -1951,14 +1951,14 @@ func WalletPassphrase(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
return nil, err return nil, err
} }
// WalletPassphraseChange responds to the walletpassphrasechange request // walletPassphraseChange responds to the walletpassphrasechange request
// by unlocking all accounts with the provided old passphrase, and // by unlocking all accounts with the provided old passphrase, and
// re-encrypting each private key with an AES key derived from the new // re-encrypting each private key with an AES key derived from the new
// passphrase. // passphrase.
// //
// If the old passphrase is correct and the passphrase is changed, all // If the old passphrase is correct and the passphrase is changed, all
// wallets will be immediately locked. // wallets will be immediately locked.
func WalletPassphraseChange(icmd interface{}, w *wallet.Wallet) (interface{}, error) { func walletPassphraseChange(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*btcjson.WalletPassphraseChangeCmd) cmd := icmd.(*btcjson.WalletPassphraseChangeCmd)
err := w.ChangePassphrase([]byte(cmd.OldPassphrase), err := w.ChangePassphrase([]byte(cmd.OldPassphrase),

View file

@ -126,7 +126,7 @@ func NewServer(opts *Options, walletLoader *wallet.Loader, listeners []net.Liste
return return
} }
server.wg.Add(1) server.wg.Add(1)
server.PostClientRPC(w, r) server.postClientRPC(w, r)
server.wg.Done() server.wg.Done()
})) }))
@ -562,8 +562,8 @@ func (s *Server) websocketClientRPC(wsc *websocketClient) {
// that may be read from a client. This is currently limited to 4MB. // that may be read from a client. This is currently limited to 4MB.
const maxRequestSize = 1024 * 1024 * 4 const maxRequestSize = 1024 * 1024 * 4
// PostClientRPC processes and replies to a JSON-RPC client request. // postClientRPC processes and replies to a JSON-RPC client request.
func (s *Server) PostClientRPC(w http.ResponseWriter, r *http.Request) { func (s *Server) postClientRPC(w http.ResponseWriter, r *http.Request) {
body := http.MaxBytesReader(w, r.Body, maxRequestSize) body := http.MaxBytesReader(w, r.Body, maxRequestSize)
rpcRequest, err := ioutil.ReadAll(body) rpcRequest, err := ioutil.ReadAll(body)
if err != nil { if err != nil {