package
0.0.23
Repository: https://github.com/cybriq/p9.git
Documentation: pkg.go.dev

# README

pod wallet

Build Status Build status

btcwallet is a daemon handling bitcoin wallet functionality for a single user. It acts as both an RPC client to pod and an RPC server for wallet clients and legacy RPC applications.

Public and private keys are derived using the hierarchical deterministic format described by BIP0032. Unencrypted private keys are not supported and are never written to disk. btcwallet uses the m/44'/<coin type>'/<account>'/<branch>/<address index> HD path for all derived addresses, as described by BIP0044.

Due to the sensitive nature of public data in a BIP0032 wallet, btcwallet provides the option of encrypting not just private keys, but public data as well. This is intended to thwart privacy risks where a wallet file is compromised without exposing all current and future addresses (public keys) managed by the wallet. While access to this information would not allow an attacker to spend or steal coins, it does mean they could track all transactions involving your addresses and therefore know your exact balance. In a future release, public data encryption will extend to transactions as well.

btcwallet is not an SPV client and requires connecting to a local or remote pod instance for asynchronous blockchain queries and notifications over websockets. Full pod installation instructions can be found here. An alternative SPV mode that is compatible with pod and Bitcoin Core is planned for a future release.

Wallet clients can use one of two RPC servers:

  1. A legacy JSON-RPC server mostly compatible with Bitcoin Core

    The JSON-RPC server exists to ease the migration of wallet applications from Core, but complete compatibility is not guaranteed. Some portions of the API (and especially accounts) have to work differently due to other design decisions (mostly due to BIP0044). However, if you find a compatibility issue and feel that it could be reasonably supported, please report an issue. This server is enabled by default.

  2. An experimental gRPC server

    The gRPC server uses a new API built for btcwallet, but the API is not stabilized and the server is feature gated behind a config option (--experimentalrpclisten). If you don't mind applications breaking due to API changes, don't want to deal with issues of the legacy API, or need notifications for changes to the wallet, this is the RPC server to use. The gRPC server is documented here.

Installation and updating

Windows - MSIs Available

Install the latest MSIs available here:

https://github.com/cybriq/p9/releases

https://github.com/cybriq/p9/walletmain/releases

Windows/Linux/BSD/POSIX - Build from source

Building or updating from source requires the following build dependencies:

  • Go 1.5 or 1.6

    Installation instructions can be found here: http://golang.org/doc/install. It is recommended to add $GOPATH/bin to your PATH at this point.

    Note: If you are using Go 1.5, you must manually enable the vendor experiment by setting the GO15VENDOREXPERIMENT environment variable to 1. This step is not required for Go 1.6.

  • Glide

    Glide is used to manage project dependencies and provide reproducible builds. To install:

    go get -u github.com/Masterminds/glide

Unfortunately, the use of glide prevents a handy tool such as go get from automatically downloading, building, and installing the source in a single command. Instead, the latest project and dependency sources must be first obtained manually with git and glide, and then go is used to build and install the project.

Getting the source:

For a first time installation, the project and dependency sources can be obtained manually with git and glide ( create directories as needed):

git clone https://github.com/cybriq/p9/walletmain $GOPATH/src/github.com/cybriq/p9/walletmain
cd $GOPATH/src/github.com/cybriq/p9/walletmain
glide install

To update an existing source tree, pull the latest changes and install the matching dependencies:

cd $GOPATH/src/github.com/cybriq/p9/walletmain
git pull
glide install

Building/Installing:

The go tool is used to build or install (to GOPATH) the project. Some example build instructions are provided below (all must run from the btcwallet project directory).

To build and install btcwallet and all helper commands (in the cmd directory) to $GOPATH/bin/, as well as installing all compiled packages to $GOPATH/pkg/ (use this if you are unsure which command to run):

go install . ./cmd/...

To build a btcwallet executable and install it to $GOPATH/bin/:

go install

To build a btcwallet executable and place it in the current directory:

go build

Getting Started

The following instructions detail how to get started with btcwallet connecting to a localhost pod. Commands should be run in cmd.exe or PowerShell on Windows, or any terminal emulator on *nix.

  • Run the following command to start pod:
pod -u rpcuser -P rpcpass
  • Run the following command to create a wallet:
btcwallet -u rpcuser -P rpcpass --create
  • Run the following command to start btcwallet:
btcwallet -u rpcuser -P rpcpass

If everything appears to be working, it is recommended at this point to copy the sample pod and btcwallet configurations and update with your RPC username and password.

PowerShell (Installed from MSI):

PS> cp "$env:ProgramFiles\Pod Suite\Pod\sample-pod.conf" $env:LOCALAPPDATA\Pod\pod.conf
PS> cp "$env:ProgramFiles\Pod Suite\Btcwallet\sample-btcwallet.conf" $env:LOCALAPPDATA\Btcwallet\btcwallet.conf
PS> $editor $env:LOCALAPPDATA\Pod\pod.conf
PS> $editor $env:LOCALAPPDATA\Btcwallet\btcwallet.conf

PowerShell (Installed from source):

PS> cp $env:GOPATH\src\github.com\btcsuite\pod\sample-pod.conf $env:LOCALAPPDATA\Pod\pod.conf
PS> cp $env:GOPATH\src\github.com\btcsuite\btcwallet\sample-btcwallet.conf $env:LOCALAPPDATA\Btcwallet\btcwallet.conf
PS> $editor $env:LOCALAPPDATA\Pod\pod.conf
PS> $editor $env:LOCALAPPDATA\Btcwallet\btcwallet.conf

Linux/BSD/POSIX (Installed from source):

$ cp $GOPATH/src/github.com/cybriq/p9/sample-pod.conf ~/.pod/pod.conf
$ cp $GOPATH/src/github.com/cybriq/p9/walletmain/sample-btcwallet.conf ~/.btcwallet/btcwallet.conf
$ $EDITOR ~/.pod/pod.conf
$ $EDITOR ~/.btcwallet/btcwallet.conf

Issue Tracker

The integrated github issue tracker is used for this project.

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from the btcsuite developers. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

btcwallet is licensed under the liberal ISC License.

# Packages

No description provided by the author

# Functions

AddMultiSigAddress handles an addmultisigaddress request by adding a multisig address to the given wallet.
Confirms returns the number of confirmations for a transaction in a block at height txHeight (or -1 for an unconfirmed tx) given the chain height curHeight.
Create creates an new wallet, writing it to an empty database.
CreateMultiSig handles an createmultisig request by returning a multisig address for the given inputs.
CreateNewAccount handles a createnewaccount request by creating and returning a new account.
CreateSimulationWallet is intended to be called from the rpcclient and used to create a wallet for actors involved in simulations.
CreateWallet prompts the user for information needed to generate a new wallet and generates the wallet accordingly.
No description provided by the author
DecodeHexStr decodes the hex encoding of a string, possibly prepending a leading '0' character if there is an odd number of bytes in the hex string.
No description provided by the author
DumpPrivKey handles a dumpprivkey request with the private key for a single address, or an appropriate error if the wallet is locked.
ExposeUnstableAPI exposes additional unstable public APIs for a Wallet.
GenerateRPCKeyPair generates a new RPC TLS keypair and writes the cert and possibly also the key in PEM format to the paths specified by the config.
GetAccount handles a getaccount request by returning the account name associated with a single address.
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 pod mempool).
GetAddressesByAccount handles a getaddressesbyaccount request by returning all addresses for an account, or an error if the requested account does not exist.
GetBalance handles a getbalance request by returning the balance for an account (wallet), or an error if the requested account does not exist.
GetBestBlock handles a getbestblock request by returning a JSON object with the height and hash of the most recently processed block.
GetBestBlockHash handles a getbestblockhash request by returning the hash of the most recently processed block.
GetBlockCount handles a getblockcount request by returning the chain height of the most recently processed block.
GetInfo handles a getinfo request by returning the a structure containing information about the current state of btcwallet.
GetNewAddress handles a getnewaddress request by returning a new address for an account.
GetRawChangeAddress handles a getrawchangeaddress request by creating and returning a new change address for an account.
GetReceivedByAccount handles a getreceivedbyaccount request by returning the total amount received by addresses of an account.
GetReceivedByAddress handles a getreceivedbyaddress request by returning the total amount received by a single address.
GetTransaction handles a gettransaction request by returning details about a single transaction saved by wallet.
GetUnconfirmedBalance handles a getunconfirmedbalance extension request by returning the current unconfirmed balance of an account.
No description provided by the author
Help handles the Help request by returning one line usage of all available methods, or full Help for a specific method.
No description provided by the author
HelpNoChainRPC handles the help request when the RPC server has not been associated with a consensus RPC client.
HelpWithChainRPC handles the help request when the RPC server has been associated with a consensus RPC client.
HTTPBasicAuth returns the UTF-8 bytes of the HTTP Basic authentication string: "Basic " + base64(username + ":" + password).
IDPointer returns a pointer to the passed ID, or nil if the interface is nil.
ImportPrivKey handles an importprivkey request by parsing a WIF-encoded private key and adding it to an account.
No description provided by the author
JSONAuthFail sends a message back to the client if the http auth is rejected.
JSONError creates a JSON-RPC error from the Go error.
KeypoolRefill handles the keypoolrefill command.
LazyApplyHandler looks up the best request handler func for the method, returning a closure that will execute it with the (required) wallet and (optional) consensus RPC server.
ListAccounts handles a listaccounts request by returning a map of account names to their balances.
ListAddressTransactions handles a listaddresstransactions request by returning an array of maps with details of spent and received wallet transactions.
ListAllTransactions handles a listalltransactions request by returning a map with details of sent and received wallet transactions.
ListLockUnspent handles a listlockunspent request by returning an slice of all locked outpoints.
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.
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.
ListSinceBlock handles a listsinceblock request by returning an array of maps with details of sent and received wallet transactions since the given block.
ListTransactions handles a listtransactions request by returning an array of maps with details of sent and recevied wallet transactions.
ListUnspent handles the listunspent command.
LoadWallet ...
LockUnspent handles the lockunspent command.
Main is a work-around main function that is required since deferred functions (such as log flushing) are not called with calls to os.Exit.
MakeMultiSigScript is a helper function to combine common logic for AddMultiSig and CreateMultiSig.
MakeOutputs creates a slice of transaction outputs from a pair of address strings to amounts.
MakeResponse makes the JSON-RPC response struct for the result and error returned by a requestHandler.
NetworkDir returns the directory name of a network directory to hold wallet files.
NewBlockIdentifierFromHash constructs a BlockIdentifier for a block hash.
NewBlockIdentifierFromHeight constructs a BlockIdentifier for a block height.
NewBranchRecoveryState creates a new BranchRecoveryState that can be used to track either the external or internal branch of an account's derivation path.
NewCAPI returns a new CAPI .
NewCAPIClient creates a new client for a kopach_worker.
NewLoader constructs a Loader with an optional recovery window.
NewRecoveryManager initializes a new RecoveryManager with a derivation look-ahead of `recoveryWindow` child indexes, and pre-allocates a backing array for `batchSize` blocks to scan at once.
NewRecoveryState creates a new RecoveryState using the provided recoveryWindow.
NewScopeRecoveryState initializes an ScopeRecoveryState with the chosen recovery window.
NewServer creates a new server for serving legacy RPC client connections, both HTTP POST and websocket.
No description provided by the author
Open loads an already-created wallet from the passed database and namespaces.
OpenRPCKeyPair creates or loads the RPC TLS keypair specified by the application config.
RecvCategory returns the category of received credit outputs from a transaction record.
RenameAccount handles a renameaccount request by renaming an account.
RunAPI starts up the api handler server that receives rpc.API messages and runs the handler and returns the result Note that the parameters are type asserted to prevent the consumer of the API from sending wrong message types not because it's necessary since they are interfaces end to end.
SendFrom handles a sendfrom RPC request by creating a new transaction spending unspent transaction outputs for a wallet to another payment address.
SendMany handles a sendmany RPC request by creating a new transaction spending unspent transaction outputs for a wallet to any number of payment addresses.
SendPairs creates and sends payment transactions.
SendToAddress handles a sendtoaddress RPC request by creating a new transaction spending unspent transaction outputs for a wallet to another payment address.
SetTxFee sets the transaction fee per kilobyte added to transactions.
SignMessage signs the given message with the private key for the given address.
SignRawTransaction handles the signrawtransaction command.
StartChainRPC opens a RPC client connection to a pod server for blockchain services.
Throttled wraps an http.Handler with throttling of concurrent active clients by responding with an HTTP 429 when the threshold is crossed.
ThrottledFn wraps an http.HandlerFunc with throttling of concurrent active clients by responding with an HTTP 429 when the threshold is crossed.
Unimplemented handles an Unimplemented RPC request with the appropiate error.
Unsupported handles a standard bitcoind RPC request which is Unsupported by btcwallet due to design differences.
ValidateAddress handles the validateaddress command.
VerifyMessage handles the verifymessage command by verifying the provided compact signature for the given address and message.
WalletIsLocked handles the walletislocked extension request by returning the current lock state (false for unlocked, true for locked) of an account.
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).
WalletPassphrase responds to the walletpassphrase request by unlocking the wallet.
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.

# Constants

These constants define the possible credit categories.
These constants define the possible credit categories.
These constants define the possible credit categories.
InsecurePubPassphrase is the default outer encryption passphrase used for public data (everything but private keys).
MaxRequestSize specifies the maximum number of bytes in the request body that may be read from a client.
Defined OutputKind constants.
Defined OutputKind constants.

# Variables

No description provided by the author
No description provided by the author
Errors variables that are defined once here to avoid duplication below.
Errors variables that are defined once here to avoid duplication below.
ErrExists describes the error condition of attempting to create a new wallet when one exists already.
ErrLoaded describes the error condition of attempting to load or create a wallet when the loader has already done so.
Errors variables that are defined once here to avoid duplication below.
Errors variables that are defined once here to avoid duplication below.
ErrNoAuth represents an error where authentication could not succeed due to a missing Authorization HTTP header.
Errors variables that are defined once here to avoid duplication below.
ErrNotLoaded describes the error condition of attempting to close a loaded wallet when a wallet has not been loaded.
Errors variables that are defined once here to avoid duplication below.
ErrNotSynced describes an error where an operation cannot complete due wallet being out of sync (and perhaps currently syncing with) the remote chain server.
Errors variables that are defined once here to avoid duplication below.
Errors variables that are defined once here to avoid duplication below.
Errors variables that are defined once here to avoid duplication below.
No description provided by the author
No description provided by the author
Help may execute concurrently, so synchronize access.
No description provided by the author
No description provided by the author
No description provided by the author
RPCHandlers is all of the RPC calls available - Handler is the handler function - Call is a channel carrying a struct containing parameters and error that is listened to in RunAPI to dispatch the calls - Result is a bundle of command parameters and a channel that the result will be sent back on Get and save the Result function's return, and you can then call the call functions check, result and wait functions for asynchronous and synchronous calls to RPC functions.
No description provided by the author
No description provided by the author

# Structs

AccountBalance associates a total (zero confirmation) balance with an account.
AccountBalanceResult is a single result for the Wallet.AccountBalances method.
AccountNotification contains properties regarding an account, such as its name and the number of derived and imported keys.
AccountNotificationsClient receives AccountNotifications over the channel C.
AccountResult is a single account result for the AccountsResult type.
AccountsResult is the result of the wallet's Accounts method.
AccountTotalReceivedResult is a single result for the Wallet.TotalReceivedForAccounts method.
No description provided by the author
API stores the channel, parameters and result values from calls via the channel.
Balances records total, spendable (by policy), and immature coinbase reward balance amounts.
Block contains the properties and all relevant transactions of an attached block.
BlockIdentifier identifies a block by either a height or a hash.
BlockIdentity identifies a block, or the lack of one (used to describe an unmined transaction).
BranchRecoveryState maintains the required state in-order to properly recover addresses derived from a particular account's internal or external derivation branch.
CAPI is the central structure for configuration and access to a net/rpc API access endpoint for this RPC API.
CAPIClient is a wrapper around RPC calls.
No description provided by the author
No description provided by the author
TODO(jrick): There are several error paths which 'replace' various errors with a more appropiate error from the json package.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetTransactionsResult is the result of the wallet's GetTransactions method.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TODO(jrick): There are several error paths which 'replace' various errors with a more appropiate error from the json package.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Loader implements the creating of new and opening of existing wallets, while providing a callback system for other subsystems to handle the loading of a wallet.
No description provided by the author
No description provided by the author
NotificationServer is a server that interested clients may hook into to receive notifications of changes in a wallet.
Options contains the required options for running the legacy RPC server.
OutputRedeemer identifies the transaction input which redeems an output.
OutputSelectionPolicy describes the rules for selecting an output from the wallet.
P2SHMultiSigOutput describes a transaction output with a pay-to-script-hash output script and an imported redemption script.
TODO(jrick): There are several error paths which 'replace' various errors with a more appropiate error from the json package.
RecoveryManager maintains the state required to recover previously used addresses, and coordinates batched processing of the blocks to search.
RecoveryState manages the initialization and lookup of ScopeRecoveryStates for any actively used key scopes.
No description provided by the author
RescanFinishedMsg reports the addresses that were rescanned when a rescanfinished message was received rescanning a batch of addresses.
RescanJob is a job to be processed by the RescanManager.
RescanProgressMsg reports the current progress made by a rescan for a set of wallet addresses.
ScopeRecoveryState is used to manage the recovery of addresses generated under a particular BIP32 account.
No description provided by the author
No description provided by the author
Server holds the items the RPC server may need to access (auth, config, shutdown, etc.).
No description provided by the author
SignatureError records the underlying error when validating a transaction input signature.
No description provided by the author
No description provided by the author
SpentnessNotifications is a notification that is fired for transaction outputs controlled by some account's keys.
SpentnessNotificationsClient receives SpentnessNotifications from the NotificationServer over the channel C.
TransactionNotifications is a notification of changes to the wallet's transaction set and the current chain tip that wallet is considered to be synced with.
TransactionNotificationsClient receives TransactionNotifications from the NotificationServer over the channel C.
TransactionOutput describes an output that was or is at least partially controlled by the wallet.
TransactionSummary contains a transaction relevant to the wallet and marks which inputs and outputs were relevant.
TransactionSummaryInput describes a transaction input that is relevant to the wallet.
TransactionSummaryOutput describes wallet properties of a transaction output controlled by the wallet.
UnstableAPI exposes unstable api in the wallet.
No description provided by the author
No description provided by the author
Wallet is a structure containing all the components for a complete wallet.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

CreditCategory describes the type of wallet transaction output.
LazyHandler is a closure over a requestHandler or passthrough request with the RPC server's wallet and chain server variables as part of the closure context.
OutputKind describes a kind of transaction output.
RequestHandler is a handler function to handle an unmarshaled and parsed request into a marshalable response.