haskoin-core-0.3.0: 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

Constructors

Tx 

Fields

txVersion :: !Word32

Transaction data format version

txIn :: ![TxIn]

List of transaction inputs

txOut :: ![TxOut]

List of transaction outputs

txLockTime :: !Word32

The block number of timestamp at which this transaction is locked

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

outValue :: !Word64

Transaction output value.

scriptOutput :: !ByteString

Script specifying the conditions to spend this output.

data OutPoint Source

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

Constructors

OutPoint 

Fields

outPointHash :: !TxHash

The hash of the referenced transaction.

outPointIndex :: !Word32

The position of the specific output in the transaction. The first output position is 0.

data CoinbaseTx Source

Data type representing the coinbase transaction of a Block. Coinbase transactions are special types of transactions which are created by miners when they find a new block. Coinbase transactions have no inputs. They have outputs sending the newly generated bitcoins together with all the block's fees to a bitcoin address (usually the miners address). Data can be embedded in a Coinbase transaction which can be chosen by the miner of a block. This data also typically contains some randomness which is used, together with the nonce, to find a partial hash collision on the block's hash.

Constructors

CoinbaseTx 

Fields

cbVersion :: !Word32

Transaction data format version.

cbPrevOutput :: !OutPoint

Previous outpoint. This is ignored for coinbase transactions but preserved for computing the correct txid.

cbData :: !ByteString

Data embedded inside the coinbase transaction.

cbInSequence :: !Word32

Transaction sequence number. This is ignored for coinbase transactions but preserved for computing the correct txid.

cbOut :: ![TxOut]

List of transaction outputs.

cbLockTime :: !Word32

The block number of timestamp at which this transaction is locked.

txHash :: Tx -> TxHash Source

Computes the hash of a transaction.

cbHash :: CoinbaseTx -> TxHash Source

Computes the hash of a coinbase transaction.

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

sigDataOut :: !ScriptOutput

Output script to spend.

sigDataOP :: !OutPoint

Spending tranasction OutPoint

sigDataSH :: !SigHash

Signature type.

sigDataRedeem :: !(Maybe RedeemScript)

Redeem script

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.

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.