haskoin-0.0.2.1: Implementation of the Bitcoin protocol.

Safe HaskellNone

Network.Haskoin.Transaction

Contents

Description

This package provides functions for building and signing both simple transactions and multisignature transactions.

Synopsis

Build Transactions

buildTx :: [OutPoint] -> [(ScriptOutput, Word64)] -> Either String TxSource

Build a transaction by providing a list of outpoints as inputs and a list of ScriptOutput and amounts as outputs.

buildAddrTx :: [OutPoint] -> [(String, Word64)] -> Either String TxSource

Build a transaction by providing a list of outpoints as inputs and a list of recipients addresses and amounts as outputs.

Transaction signing

data SigInput Source

Data type used to specify the signing parameters of a transaction input. To sign an input, the previous output script, outpoint and sighash are required. When signing a pay to script hash output, an additional redeem script is required.

Constructors

SigInput

Parameters for signing a pay to public key hash output.

Fields

sigDataOut :: Script

Output script to spend.

sigDataOP :: OutPoint

Reference to the transaction output to spend.

sigDataSH :: SigHash

Signature type.

SigInputSH

Parameters for signing a pay to script hash output.

Fields

sigDataOut :: Script

Output script to spend.

sigDataOP :: OutPoint

Reference to the transaction output to spend.

sigRedeem :: Script

Redeem script.

sigDataSH :: SigHash

Signature type.

Instances

signTxSource

Arguments

:: Monad m 
=> Tx

Transaction to sign

-> [SigInput]

SigInput signing parameters

-> [PrvKey]

List of private keys to use for signing

-> SecretT (BuildT m) Tx

Signed transaction

Sign a transaction by providing the SigInput signing parameters and a list of private keys. The signature is computed within the SecretT monad to generate the random signing nonce and within the BuildT monad to add information on wether the result was fully or partially signed.

detSignTxSource

Arguments

:: Tx

Transaction to sign

-> [SigInput]

SigInput signing parameters

-> [PrvKey]

List of private keys to use for signing

-> Build Tx

Signed transaction

Sign a transaction by providing the SigInput signing paramters and a list of private keys. The signature is computed deterministically as defined in RFC-6979. The signature is computed within the Build monad to add information on wether the result was fully or partially signed.

isTxComplete :: Tx -> BoolSource

Returns True if all the inputs of a transactions are non-empty and if all multisignature inputs are fully signed.

Coin selection

data Coin Source

A Coin is something that can be spent by a transaction and is represented by a transaction output, an outpoint and optionally a redeem script.

Constructors

Coin 

Fields

coinTxOut :: TxOut

Transaction output

coinOutPoint :: OutPoint

Previous outpoint

coinRedeem :: Maybe Script

Redeem script

Instances

chooseCoinsSource

Arguments

:: Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> [Coin]

List of coins to choose from.

-> Either String ([Coin], Word64)

Coin selection result and change amount.

Coin selection algorithm for normal (non-multisig) transactions. This function returns the selected coins together with the amount of change to send back to yourself, taking the fee into account.

chooseMSCoinsSource

Arguments

:: Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> (Int, Int)

Multisig parameters m of n (m,n).

-> [Coin]

List of coins to choose from.

-> Either String ([Coin], Word64)

Coin selection result and change amount.

Coin selection algorithm for multisignature transactions. This function returns the selected coins together with the amount of change to send back to yourself, taking the fee into account. This function assumes all the coins are script hash outputs that send funds to a multisignature address.

guessTxSizeSource

Arguments

:: Int

Number of regular transaction inputs.

-> [(Int, Int)]

For every multisig input in the transaction, provide the multisig parameters m of n (m,n) for that input.

-> Int

Number of pay to public key hash outputs.

-> Int

Number of pay to script hash outputs.

-> Int

Upper bound on the transaction size.

Computes an upper bound on the size of a transaction based on some known properties of the transaction.