Safe Haskell | None |
---|
This package provides functions for building and signing both simple transactions and multisignature transactions.
- buildTx :: [OutPoint] -> [(ScriptOutput, Word64)] -> Either String Tx
- buildAddrTx :: [OutPoint] -> [(String, Word64)] -> Either String Tx
- data SigInput = SigInput {
- sigDataOut :: !ScriptOutput
- sigDataOP :: !OutPoint
- sigDataSH :: !SigHash
- sigDataRedeem :: !(Maybe RedeemScript)
- signTx :: Monad m => Tx -> [SigInput] -> [PrvKey] -> EitherT String (SecretT m) (Tx, Bool)
- signInput :: Monad m => Tx -> Int -> SigInput -> PrvKey -> EitherT String (SecretT m) (Tx, Bool)
- detSignTx :: Tx -> [SigInput] -> [PrvKey] -> Either String (Tx, Bool)
- detSignInput :: Tx -> Int -> SigInput -> PrvKey -> Either String (Tx, Bool)
- verifyStdTx :: Tx -> [(ScriptOutput, OutPoint)] -> Bool
- verifyStdInput :: Tx -> Int -> ScriptOutput -> Bool
- data Coin = Coin {
- coinValue :: !Word64
- coinScript :: !ScriptOutput
- coinOutPoint :: !OutPoint
- coinRedeem :: !(Maybe RedeemScript)
- chooseCoins :: Word64 -> Word64 -> [Coin] -> Either String ([Coin], Word64)
- chooseMSCoins :: Word64 -> Word64 -> (Int, Int) -> [Coin] -> Either String ([Coin], Word64)
- guessTxSize :: Int -> [(Int, Int)] -> Int -> Int -> Int
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 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 | |
|
:: 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.
:: 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
A Coin is an output of a transaction that can be spent by another transaction.
Coin | |
|
:: 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.
:: 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.
:: 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.