haskoin-wallet-0.0.1: Implementation of a Bitcoin hierarchical deterministric wallet (BIP32).

Safe HaskellNone

Network.Haskoin.Wallet.Store

Contents

Description

This module provides an API to the Haskoin wallet. All commands return a Value result which can be encoded to JSON or YAML. The wallet commands run within the Persistent framework for database support:

http://hackage.haskell.org/package/persistent

Synopsis

Documentation

cmdInitSource

Arguments

:: PersistUnique m 
=> String

Secret seed.

-> EitherT String m Value

Returns Null.

Initialize a wallet from a secret seed. This function will fail if the wallet is already initialized.

Account Commands

cmdNewAccSource

Arguments

:: (PersistUnique m, PersistQuery m) 
=> String

Account name.

-> EitherT String m Value

Returns the new account information.

Create a new account from an account name. Accounts are identified by their name and they must be unique.

cmdNewMSSource

Arguments

:: (PersistUnique m, PersistQuery m) 
=> String

Account name.

-> Int

Required number of keys (m in m of n).

-> Int

Total number of keys (n in m of n).

-> [XPubKey]

Thirdparty public keys.

-> EitherT String m Value

Returns the new account information.

Create a new multisignature account. The thirdparty keys can be provided now or later using the cmdAddKeys command. The number of thirdparty keys can not exceed n-1 as your own account key will be used as well in the multisignature scheme. If less than n-1 keys are provided, the account will be in a pending state and no addresses can be generated.

In order to prevent usage mistakes, you can not create a multisignature account with other keys from your own wallet.

cmdAddKeysSource

Arguments

:: (PersistUnique m, PersistQuery m) 
=> AccountName

Account name.

-> [XPubKey]

Thirdparty public keys to add.

-> EitherT String m Value

Returns the account information.

Add new thirdparty keys to a multisignature account. This function can fail if the multisignature account already has all required keys. In order to prevent usage mistakes, adding a key from your own wallet will fail.

cmdAccInfoSource

Arguments

:: PersistUnique m 
=> AccountName

Account name.

-> EitherT String m Value

Account information.

Returns information on an account.

cmdListAccSource

Arguments

:: PersistQuery m 
=> EitherT String m Value

List of accounts

Returns a list of all accounts in the wallet.

cmdDumpKeysSource

Arguments

:: PersistUnique m 
=> AccountName

Account name.

-> EitherT String m Value

Extended key information.

Returns information on extended public and private keys of an account. For a multisignature account, thirdparty keys are also returned.

Address Commands

cmdListSource

Arguments

:: (PersistUnique m, PersistQuery m) 
=> AccountName

Account name.

-> Int

Requested page number.

-> Int

Number of addresses per page.

-> EitherT String m Value

The requested page.

Returns a page of addresses for an account. Pages are numbered starting from page 1. Requesting page 0 will return the last page.

cmdGenAddrsSource

Arguments

:: (PersistUnique m, PersistQuery m) 
=> AccountName

Account name.

-> Int

Number of addresses to generate.

-> EitherT String m Value

List of new addresses.

Generate new payment addresses for an account.

cmdGenWithLabelSource

Arguments

:: (PersistUnique m, PersistQuery m) 
=> AccountName

Account name.

-> [String]

List of address labels.

-> EitherT String m Value

List of new addresses.

Generate new payment addresses with labels for an account.

cmdLabelSource

Arguments

:: PersistUnique m 
=> AccountName

Account name.

-> Int

Derivation index of the address.

-> String

New label.

-> EitherT String m Value

New address information.

Add a label to an address.

cmdWIFSource

Arguments

:: PersistUnique m 
=> AccountName

Account name.

-> Int

Derivation index of the address.

-> EitherT String m Value

WIF value.

Returns the private key tied to a payment address in WIF format.

Coin Commands

cmdBalanceSource

Arguments

:: (PersistUnique m, PersistQuery m) 
=> AccountName

Account name.

-> EitherT String m Value

Account balance.

Returns the balance of an account.

cmdBalancesSource

Arguments

:: PersistQuery m 
=> EitherT String m Value

All account balances

Returns a list of balances for every account in the wallet.

cmdCoinsSource

Arguments

:: (PersistQuery m, PersistUnique m, PersistMonadBackend m ~ SqlBackend) 
=> AccountName

Account name.

-> EitherT String m Value

List of unspent coins.

Returns the list of unspent coins for an account.

cmdAllCoinsSource

Arguments

:: (PersistQuery m, PersistUnique m, PersistMonadBackend m ~ SqlBackend) 
=> EitherT String m Value

Unspent coins for all accounts.

Returns a list of all the unspent coins for every account in the wallet.

Tx Commands

cmdImportTxSource

Arguments

:: (PersistQuery m, PersistUnique m, PersistMonadBackend m ~ SqlBackend) 
=> Tx

Transaction to import.

-> EitherT String m Value

New transaction entries created.

Import a transaction into the wallet. If called multiple times, this command will only update the existing transaction in the wallet. A new transaction entry will be created for every account affected by this transaction. Every transaction entry will summarize the information related to its account only (such as total movement for this account).

cmdRemoveTxSource

Arguments

:: PersistQuery m 
=> String

Transaction id (txid)

-> EitherT String m Value

List of removed transaction entries

Remove a transaction from the database. This will remove all transaction entries for this transaction as well as any child transactions and coins deriving from it.

cmdListTxSource

Arguments

:: (PersistQuery m, PersistUnique m) 
=> AccountName

Account name.

-> EitherT String m Value

List of transaction entries.

List all the transaction entries for an account. Transaction entries summarize information for a transaction in a specific account only (such as the total movement of for this account).

Transaction entries can also be tagged as Orphan or Partial. Orphaned transactions are transactions with a parent transaction that should be in the wallet but has not been imported yet. Balances for orphaned transactions can not be accurately computed until the parent transaction is imported.

Partial transactions are transactions that are not fully signed yet, such as a partially signed multisignature transaction. Partial transactions are visible in the wallet mostly for informational purposes. They can not generate any coins as the txid or partial transactions will change once they are fully signed. However, importing a partial transaction will lock the coins that it spends so that you don't mistakenly spend them. Partial transactions are replaced once the fully signed transaction is imported.

cmdSendSource

Arguments

:: (PersistQuery m, PersistUnique m, PersistMonadBackend m ~ SqlBackend) 
=> AccountName

Account name.

-> String

Recipient address.

-> Int

Amount to send.

-> Int

Fee per 1000 bytes.

-> EitherT String m Value

Payment transaction.

Create a transaction sending some coins to a single recipient address.

cmdSendManySource

Arguments

:: (PersistQuery m, PersistUnique m, PersistMonadBackend m ~ SqlBackend) 
=> AccountName

Account name.

-> [(String, Int)]

List of recipient addresses and amounts.

-> Int

Fee per 1000 bytes.

-> EitherT String m Value

Payment transaction.

Create a transaction sending some coins to a list of recipient addresses.

cmdSignTxSource

Arguments

:: PersistUnique m 
=> AccountName

Account name.

-> Tx

Transaction to sign.

-> SigHash

Signature type to create.

-> EitherT String m Value

Signed transaction.

Try to sign the inputs of an existing transaction using the private keys of an account. This command will return an indication if the transaction is fully signed or if additional signatures are required. This command will work for both normal inputs and multisignature inputs. Signing is limited to the keys of one account only to allow for more control when the wallet is used as the backend of a web service.

Utility Commands

cmdDecodeTxSource

Arguments

:: Monad m 
=> String

HEX encoded transaction

-> EitherT String m Value

Decoded transaction

Decodes a transaction, providing structural information on the inputs and the outputs of the transaction.

cmdBuildRawTxSource

Arguments

:: Monad m 
=> String

List of JSON encoded Outpoints.

-> String

List of JSON encoded Recipients.

-> EitherT String m Value

Transaction result.

Build a raw transaction from a list of outpoints and recipients encoded in JSON.

Outpoint format as JSON:

   [ 
       { "txid": txid
       , "vout": n
       },...
   ] 

Recipient list as JSON:

   { addr: amnt,... }

cmdSignRawTxSource

Arguments

:: Monad m 
=> Tx

Transaction to sign.

-> String

List of JSON encoded signing parameters.

-> String

List of JSON encoded WIF private keys.

-> SigHash

Signature type.

-> EitherT String m Value 

Sign a raw transaction by providing the signing parameters and private keys manually. None of the keys in the wallet will be used for signing.

Signing data as JSON (scriptRedeem is optional):

   [ 
       { "txid": txid
       , "vout": n
       , "scriptPubKey": hex
       , "scriptRedeem": hex
       },...
    ]

Private keys in JSON foramt:

   [ WIF,... ]