Safe Haskell | None |
---|---|
Language | Haskell98 |
This package provides functions for building and signing both simple transactions and multisignature transactions.
- data Tx = Tx {}
- data TxIn = TxIn {
- prevOutput :: !OutPoint
- scriptInput :: !ByteString
- txInSequence :: !Word32
- data TxOut = TxOut {
- outValue :: !Word64
- scriptOutput :: !ByteString
- data OutPoint = OutPoint {
- outPointHash :: !TxHash
- outPointIndex :: !Word32
- data CoinbaseTx = CoinbaseTx {
- cbVersion :: !Word32
- cbPrevOutput :: !OutPoint
- cbData :: !ByteString
- cbInSequence :: !Word32
- cbOut :: ![TxOut]
- cbLockTime :: !Word32
- newtype TxHash = TxHash {}
- txHash :: Tx -> TxHash
- hexToTxHash :: ByteString -> Maybe TxHash
- txHashToHex :: TxHash -> ByteString
- nosigTxHash :: Tx -> TxHash
- cbHash :: CoinbaseTx -> TxHash
- buildTx :: [OutPoint] -> [(ScriptOutput, Word64)] -> Either String Tx
- buildAddrTx :: [OutPoint] -> [(ByteString, Word64)] -> Either String Tx
- data SigInput = SigInput {
- sigDataOut :: !ScriptOutput
- sigDataOP :: !OutPoint
- sigDataSH :: !SigHash
- sigDataRedeem :: !(Maybe RedeemScript)
- signTx :: Tx -> [SigInput] -> [PrvKey] -> Either String Tx
- signInput :: Tx -> Int -> SigInput -> PrvKey -> Either String Tx
- mergeTxs :: [Tx] -> [(ScriptOutput, OutPoint)] -> Either String Tx
- verifyStdTx :: Tx -> [(ScriptOutput, OutPoint)] -> Bool
- verifyStdInput :: Tx -> Int -> ScriptOutput -> Bool
- class Coin c where
- chooseCoins :: Coin c => Word64 -> Word64 -> Bool -> [c] -> Either String ([c], Word64)
- chooseCoinsSink :: (Monad m, Coin c) => Word64 -> Word64 -> Bool -> Sink c m (Either String ([c], Word64))
- chooseMSCoins :: Coin c => Word64 -> Word64 -> (Int, Int) -> Bool -> [c] -> Either String ([c], Word64)
- chooseMSCoinsSink :: (Monad m, Coin c) => Word64 -> Word64 -> (Int, Int) -> Bool -> Sink c m (Either String ([c], Word64))
- guessTxSize :: Int -> [(Int, Int)] -> Int -> Int -> Int
- getFee :: Word64 -> Int -> Word64
- getMSFee :: Word64 -> (Int, Int) -> Int -> Word64
Transaction Types
Data type representing a bitcoin transaction
Data type representing a transaction input.
TxIn | |
|
Data type representing a transaction output.
TxOut | |
|
The OutPoint is used inside a transaction input to reference the previous transaction output that it is spending.
OutPoint | |
|
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.
CoinbaseTx | |
|
hexToTxHash :: ByteString -> Maybe TxHash Source
txHashToHex :: TxHash -> ByteString Source
nosigTxHash :: Tx -> TxHash Source
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 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.
SigInput | |
|
:: 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
Any type can be used as a Coin if it can provide a value in Satoshi. The value is used in coin selection algorithms.
:: 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.
:: (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.
:: 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.
:: (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.
:: 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.