haskoin-core-0.4.2: Implementation of the core Bitcoin protocol features.

Safe HaskellNone
LanguageHaskell98

Network.Haskoin.Transaction

Contents

Description

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

Synopsis

Transaction Types

data Tx Source #

Data type representing a bitcoin transaction

Instances

createTx :: Word32 -> [TxIn] -> [TxOut] -> Word32 -> Tx Source #

txIn :: Tx -> [TxIn] Source #

data TxIn Source #

Data type representing a transaction input.

Constructors

TxIn 

Fields

  • prevOutput :: !OutPoint

    Reference the previous transaction output (hash + position)

  • scriptInput :: !ByteString

    Script providing the requirements of the previous transaction output to spend those coins.

  • txInSequence :: !Word32

    Transaction version as defined by the sender of the transaction. The intended use is for replacing transactions with new information before the transaction is included in a block.

data TxOut Source #

Data type representing a transaction output.

Constructors

TxOut 

Fields

data OutPoint Source #

The OutPoint is used inside a transaction input to reference the previous transaction output that it is spending.

Constructors

OutPoint 

Fields

Build Transactions

buildTx :: [OutPoint] -> [(ScriptOutput, Word64)] -> Either String Tx Source #

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

buildAddrTx :: [OutPoint] -> [(ByteString, Word64)] -> Either String Tx Source #

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

Sign Transactions

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

signTx Source #

Arguments

:: Tx

Transaction to sign

-> [SigInput]

SigInput signing parameters

-> [PrvKey]

List of private keys to use for signing

-> Either String 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.

signInput :: Tx -> Int -> SigInput -> PrvKey -> Either String Tx Source #

Sign a single input in a transaction deterministically (RFC-6979).

verifyStdTx :: Tx -> [(ScriptOutput, OutPoint)] -> Bool Source #

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

verifyStdInput :: Tx -> Int -> ScriptOutput -> Bool Source #

Verify if a transaction input is valid and standard.

Coin selection

class Coin c where Source #

Any type can be used as a Coin if it can provide a value in Satoshi. The value is used in coin selection algorithms.

Minimal complete definition

coinValue

Methods

coinValue :: c -> Word64 Source #

chooseCoins Source #

Arguments

:: Coin c 
=> Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> Bool

Try to find better solution when one is found

-> [c]

List of ordered coins to choose from.

-> Either String ([c], 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.

chooseCoinsSink Source #

Arguments

:: (Monad m, Coin c) 
=> Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> Bool

Try to find better solution when one is found

-> Sink c m (Either String ([c], 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. This version uses a Sink if you need conduit-based coin selection.

chooseMSCoins Source #

Arguments

:: Coin c 
=> Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> (Int, Int)

Multisig parameters m of n (m,n).

-> Bool

Try to find better solution when one is found

-> [c] 
-> Either String ([c], 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.

chooseMSCoinsSink Source #

Arguments

:: (Monad m, Coin c) 
=> Word64

Target price to pay.

-> Word64

Fee price per 1000 bytes.

-> (Int, Int)

Multisig parameters m of n (m,n).

-> Bool

Try to find better solution when one is found

-> Sink c m (Either String ([c], 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. This version uses a Sink if you need conduit-based coin selection.

guessTxSize Source #

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.