haskoin-0.1.0.2: 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 

Fields

sigDataOut :: !ScriptOutput

Output script to spend.

sigDataOP :: !OutPoint

Spending tranasction OutPoint

sigDataSH :: !SigHash

Signature type.

sigDataRedeem :: !(Maybe RedeemScript)

Redeem script

signTxSource

Arguments

:: Monad m 
=> Tx

Transaction to sign

-> [SigInput]

SigInput signing parameters

-> [PrvKey]

List of private keys to use for signing

-> EitherT String (SecretT m) (Tx, Bool)

(Signed transaction, Status)

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. This function returns a transaction completion status. If false, some of the inputs are not fully signed or are non-standard.

signInput :: Monad m => Tx -> Int -> SigInput -> PrvKey -> EitherT String (SecretT m) (Tx, Bool)Source

Sign a single input in a transaction within the SecretT monad. This function will return a completion status only for that input. If false, that input is either non-standard or not fully signed.

detSignTxSource

Arguments

:: Tx

Transaction to sign

-> [SigInput]

SigInput signing parameters

-> [PrvKey]

List of private keys to use for signing

-> Either String (Tx, Bool)

(Signed transaction, Status)

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. This function returns a transaction completion status. If false, some of the inputs are not fully signed or are non-standard.

detSignInput :: Tx -> Int -> SigInput -> PrvKey -> Either String (Tx, Bool)Source

Sign a single input in a transaction deterministically (RFC-6979). This function will return a completion status only for that input. If false, that input is either non-standard or not fully signed.

verifyStdTx :: Tx -> [(ScriptOutput, OutPoint)] -> BoolSource

Verify if a transaction is valid and all of its inputs are standard.

verifyStdInput :: Tx -> Int -> ScriptOutput -> BoolSource

Verify if a transaction input is valid and standard.

Coin selection

data Coin Source

A Coin is an output of a transaction that can be spent by another transaction.

Constructors

Coin 

Fields

coinValue :: !Word64

Value in satoshi

coinScript :: !ScriptOutput

Output script

coinOutPoint :: !OutPoint

Previous outpoint

coinRedeem :: !(Maybe RedeemScript)

Redeem script

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.