legacyrpc

package
v0.0.0-...-d7d402c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2016 License: ISC Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNeedPositiveAmount = InvalidParameterError{
		errors.New("amount must be positive"),
	}

	ErrNeedPositiveMinconf = InvalidParameterError{
		errors.New("minconf must be positive"),
	}

	ErrAddressNotInWallet = btcjson.RPCError{
		Code:    btcjson.ErrRPCWallet,
		Message: "address not found in wallet",
	}

	ErrAccountNameNotFound = btcjson.RPCError{
		Code:    btcjson.ErrRPCWalletInvalidAccountName,
		Message: "account name not found",
	}

	ErrUnloadedWallet = btcjson.RPCError{
		Code:    btcjson.ErrRPCWallet,
		Message: "Request requires a wallet but wallet has not loaded yet",
	}

	ErrWalletUnlockNeeded = btcjson.RPCError{
		Code:    btcjson.ErrRPCWalletUnlockNeeded,
		Message: "Enter the wallet passphrase with walletpassphrase first",
	}

	ErrNotImportedAccount = btcjson.RPCError{
		Code:    btcjson.ErrRPCWallet,
		Message: "imported addresses must belong to the imported account",
	}

	ErrNoTransactionInfo = btcjson.RPCError{
		Code:    btcjson.ErrRPCNoTxInfo,
		Message: "No information for transaction",
	}

	ErrReservedAccountName = btcjson.RPCError{
		Code:    btcjson.ErrRPCInvalidParameter,
		Message: "Account name is reserved by RPC server",
	}
)

Errors variables that are defined once here to avoid duplication below.

View Source
var ErrNoAuth = errors.New("no auth")

ErrNoAuth represents an error where authentication could not succeed due to a missing Authorization HTTP header.

Functions

func AddMultiSigAddress

func AddMultiSigAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

AddMultiSigAddress handles an addmultisigaddress request by adding a multisig address to the given wallet.

func CreateMultiSig

func CreateMultiSig(icmd interface{}, w *wallet.Wallet) (interface{}, error)

CreateMultiSig handles an createmultisig request by returning a multisig address for the given inputs.

func CreateNewAccount

func CreateNewAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error)

CreateNewAccount handles a createnewaccount request by creating and 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.

func DumpPrivKey

func DumpPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error)

DumpPrivKey handles a dumpprivkey request with the private key for a single address, or an appropiate error if the wallet is locked.

func DumpWallet

func DumpWallet(icmd interface{}, w *wallet.Wallet) (interface{}, error)

DumpWallet handles a dumpwallet request by returning all private 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.

func ExportWatchingWallet

func ExportWatchingWallet(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ExportWatchingWallet handles an exportwatchingwallet request by exporting the current wallet as a watching wallet (with no private keys), and returning base64-encoding of serialized account files.

func GetAccount

func GetAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetAccount handles a getaccount request by returning the account name associated with a single address.

func GetAccountAddress

func GetAccountAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetAccountAddress handles a getaccountaddress by returning the most 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). 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 runs out (and will return btcjson.ErrRPCWalletKeypoolRanOut if that happens).

func GetAddressesByAccount

func GetAddressesByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetAddressesByAccount handles a getaddressesbyaccount request by returning all addresses for an account, or an error if the requested account does not exist.

func GetBalance

func GetBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetBalance handles a getbalance request by returning the balance for an account (wallet), or an error if the requested account does not exist.

func GetBestBlock

func GetBestBlock(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetBestBlock handles a getbestblock request by returning a JSON object with the height and hash of the most recently processed block.

func GetBestBlockHash

func GetBestBlockHash(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetBestBlockHash handles a getbestblockhash request by returning the hash of the most recently processed block.

func GetBlockCount

func GetBlockCount(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetBlockCount handles a getblockcount request by returning the chain height of the most recently processed block.

func GetInfo

func GetInfo(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error)

GetInfo handles a getinfo request by returning the a structure containing information about the current state of btcwallet. exist.

func GetNewAddress

func GetNewAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetNewAddress handles a getnewaddress request by returning a new address for an account. If the account does not exist an appropiate error is returned. TODO: Follow BIP 0044 and warn if number of unused addresses exceeds the gap limit.

func GetRawChangeAddress

func GetRawChangeAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetRawChangeAddress handles a getrawchangeaddress request by creating and returning a new change address for an account.

Note: bitcoind allows specifying the account as an optional parameter, but ignores the parameter.

func GetReceivedByAccount

func GetReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetReceivedByAccount handles a getreceivedbyaccount request by returning the total amount received by addresses of an account.

func GetReceivedByAddress

func GetReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetReceivedByAddress handles a getreceivedbyaddress request by returning the total amount received by a single address.

func GetTransaction

func GetTransaction(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetTransaction handles a gettransaction request by returning details about a single transaction saved by wallet.

func GetUnconfirmedBalance

func GetUnconfirmedBalance(icmd interface{}, w *wallet.Wallet) (interface{}, error)

GetUnconfirmedBalance handles a getunconfirmedbalance extension request by returning the current unconfirmed balance of an account.

func HelpNoChainRPC

func HelpNoChainRPC(icmd interface{}, w *wallet.Wallet) (interface{}, error)

HelpNoChainRPC handles the help request when the RPC server has not been associated with a consensus RPC client. No help messages are included for passthrough requests.

func HelpWithChainRPC

func HelpWithChainRPC(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error)

HelpWithChainRPC handles the help request when the RPC server has been 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 passthrough.

func ImportPrivKey

func ImportPrivKey(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ImportPrivKey handles an importprivkey request by parsing a WIF-encoded private key and adding it to an account.

func KeypoolRefill

func KeypoolRefill(icmd interface{}, w *wallet.Wallet) (interface{}, error)

KeypoolRefill handles the keypoolrefill command. Since we handle the keypool automatically this does nothing since refilling is never manually required.

func ListAccounts

func ListAccounts(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListAccounts handles a listaccounts request by returning a map of account names to their balances.

func ListAddressTransactions

func ListAddressTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListAddressTransactions handles a listaddresstransactions request by returning an array of maps with details of spent and received wallet transactions. The form of the reply is identical to listtransactions, but the array elements are limited to transaction details which are about the addresess included in the request.

func ListAllTransactions

func ListAllTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListAllTransactions handles a listalltransactions request by returning a map with details of sent and recevied wallet transactions. This is similar to ListTransactions, except it takes only a single optional argument for the account name and replies with all transactions.

func ListLockUnspent

func ListLockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListLockUnspent handles a listlockunspent request by returning an slice of all locked outpoints.

func ListReceivedByAccount

func ListReceivedByAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListReceivedByAccount handles a listreceivedbyaccount request by returning a slice of objects, each one containing:

"account": the receiving account;
"amount": total amount received by the account;
"confirmations": number of confirmations of the most recent transaction.

It takes two parameters:

"minconf": minimum number of confirmations to consider a transaction -
           default: one;
"includeempty": whether or not to include addresses that have no transactions -
                default: false.

func ListReceivedByAddress

func ListReceivedByAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListReceivedByAddress handles a listreceivedbyaddress request by returning a slice of objects, each one containing:

"account": the account of the receiving address;
"address": the receiving address;
"amount": total amount received by the address;
"confirmations": number of confirmations of the most recent transaction.

It takes two parameters:

"minconf": minimum number of confirmations to consider a transaction -
           default: one;
"includeempty": whether or not to include addresses that have no transactions -
                default: false.

func ListSinceBlock

func ListSinceBlock(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error)

ListSinceBlock handles a listsinceblock request by returning an array of maps with details of sent and received wallet transactions since the given block.

func ListTransactions

func ListTransactions(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListTransactions handles a listtransactions request by returning an array of maps with details of sent and recevied wallet transactions.

func ListUnspent

func ListUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ListUnspent handles the listunspent command.

func LockUnspent

func LockUnspent(icmd interface{}, w *wallet.Wallet) (interface{}, error)

LockUnspent handles the lockunspent command.

func RenameAccount

func RenameAccount(icmd interface{}, w *wallet.Wallet) (interface{}, error)

RenameAccount handles a renameaccount request by renaming an account. If the account does not exist an appropiate error will be returned.

func SendFrom

func SendFrom(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error)

SendFrom handles a sendfrom RPC request by creating a new transaction spending unspent transaction outputs for a wallet to another 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, the TxID for the created transaction is returned.

func SendMany

func SendMany(icmd interface{}, w *wallet.Wallet) (interface{}, error)

SendMany handles a sendmany RPC request by creating a new transaction spending unspent transaction outputs for a wallet to any number of 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. Upon success, the TxID for the created transaction is returned.

func SendToAddress

func SendToAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

SendToAddress handles a sendtoaddress RPC request by creating a new transaction spending unspent transaction outputs for a wallet to another 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, the TxID for the created transaction is returned.

func SetTxFee

func SetTxFee(icmd interface{}, w *wallet.Wallet) (interface{}, error)

SetTxFee sets the transaction fee per kilobyte added to transactions.

func SignMessage

func SignMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error)

SignMessage signs the given message with the private key for the given address

func SignRawTransaction

func SignRawTransaction(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) (interface{}, error)

SignRawTransaction handles the signrawtransaction command.

func Unimplemented

func Unimplemented(interface{}, *wallet.Wallet) (interface{}, error)

Unimplemented handles an unimplemented RPC request with the appropiate error.

func Unsupported

func Unsupported(interface{}, *wallet.Wallet) (interface{}, error)

Unsupported handles a standard bitcoind RPC request which is unsupported by btcwallet due to design differences.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger sets the package-wide logger. Any calls to this function must be made before a server is created and used (it is not concurrent safe).

func ValidateAddress

func ValidateAddress(icmd interface{}, w *wallet.Wallet) (interface{}, error)

ValidateAddress handles the validateaddress command.

func VerifyMessage

func VerifyMessage(icmd interface{}, w *wallet.Wallet) (interface{}, error)

VerifyMessage handles the verifymessage command by verifying the provided compact signature for the given address and message.

func WalletIsLocked

func WalletIsLocked(icmd interface{}, w *wallet.Wallet) (interface{}, error)

WalletIsLocked handles the walletislocked extension request by returning the current lock state (false for unlocked, true for locked) of an account.

func WalletLock

func WalletLock(icmd interface{}, w *wallet.Wallet) (interface{}, error)

WalletLock handles a walletlock request by locking the all account wallets, returning an error if any wallet is not encrypted (for example, a watching-only wallet).

func WalletPassphrase

func WalletPassphrase(icmd interface{}, w *wallet.Wallet) (interface{}, error)

WalletPassphrase responds to the walletpassphrase request by unlocking the wallet. The decryption key is saved in the wallet until timeout seconds expires, after which the wallet is locked.

func WalletPassphraseChange

func WalletPassphraseChange(icmd interface{}, w *wallet.Wallet) (interface{}, error)

WalletPassphraseChange responds to the walletpassphrasechange request by unlocking all accounts with the provided old passphrase, and re-encrypting each private key with an AES key derived from the new passphrase.

If the old passphrase is correct and the passphrase is changed, all wallets will be immediately locked.

Types

type DeserializationError

type DeserializationError struct {
	// contains filtered or unexported fields
}

DeserializationError describes a failed deserializaion due to bad user input. It corresponds to btcjson.ErrRPCDeserialization.

type InvalidParameterError

type InvalidParameterError struct {
	// contains filtered or unexported fields
}

InvalidParameterError describes an invalid parameter passed by the user. It corresponds to btcjson.ErrRPCInvalidParameter.

type Options

type Options struct {
	Username string
	Password string

	MaxPOSTClients      int64
	MaxWebsocketClients int64
}

Options contains the required options for running the legacy RPC server.

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

ParseError describes a failed parse due to bad user input. It corresponds to btcjson.ErrRPCParse.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the items the RPC server may need to access (auth, config, shutdown, etc.)

func NewServer

func NewServer(opts *Options, walletLoader *wallet.Loader, listeners []net.Listener) *Server

NewServer creates a new server for serving legacy RPC client connections, both HTTP POST and websocket.

func (*Server) PostClientRPC

func (s *Server) PostClientRPC(w http.ResponseWriter, r *http.Request)

PostClientRPC processes and replies to a JSON-RPC client request.

func (*Server) RegisterWallet

func (s *Server) RegisterWallet(w *wallet.Wallet)

RegisterWallet associates the legacy RPC server with the wallet. This function must be called before any wallet RPCs can be called by clients.

func (*Server) RequestProcessShutdown

func (s *Server) RequestProcessShutdown() <-chan struct{}

RequestProcessShutdown returns a channel that is sent to when an authorized client requests remote shutdown.

func (*Server) SetChainServer

func (s *Server) SetChainServer(chainClient *chain.RPCClient)

SetChainServer sets the chain server client component needed to run a fully functional bitcoin wallet RPC server. This can be called to enable RPC passthrough even before a loaded wallet is set, but the wallet's RPC client is preferred.

func (*Server) Stop

func (s *Server) Stop()

Stop gracefully shuts down the rpc server by stopping and disconnecting all clients, disconnecting the chain server connection, and closing the wallet's account files. This blocks until shutdown completes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL