Copyright | No rights reserved |
---|---|
License | UNLICENSE |
Maintainer | xenog@protonmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Transactions and related code.
Synopsis
- data Tx = Tx {
- txVersion :: !Word32
- txIn :: ![TxIn]
- txOut :: ![TxOut]
- txWitness :: !WitnessData
- txLockTime :: !Word32
- data TxIn = TxIn {
- prevOutput :: !OutPoint
- scriptInput :: !ByteString
- txInSequence :: !Word32
- data TxOut = TxOut {
- outValue :: !Word64
- scriptOutput :: !ByteString
- data OutPoint = OutPoint {
- outPointHash :: !TxHash
- outPointIndex :: !Word32
- newtype TxHash = TxHash {}
- type WitnessData = [WitnessStack]
- type WitnessStack = [WitnessStackItem]
- type WitnessStackItem = ByteString
- txHash :: Tx -> TxHash
- hexToTxHash :: Text -> Maybe TxHash
- txHashToHex :: TxHash -> Text
- nosigTxHash :: Tx -> TxHash
- nullOutPoint :: OutPoint
- genesisTx :: Tx
- buildAddrTx :: Network -> [OutPoint] -> [(Text, Word64)] -> Either String Tx
- buildTx :: [OutPoint] -> [(ScriptOutput, Word64)] -> Either String Tx
- buildInput :: Network -> Tx -> Int -> ScriptOutput -> Word64 -> Maybe RedeemScript -> TxSignature -> PubKeyI -> Either String ScriptInput
- data SigInput = SigInput {
- sigInputScript :: !ScriptOutput
- sigInputValue :: !Word64
- sigInputOP :: !OutPoint
- sigInputSH :: !SigHash
- sigInputRedeem :: !(Maybe RedeemScript)
- signTx :: Network -> Tx -> [SigInput] -> [SecKey] -> Either String Tx
- signInput :: Network -> Tx -> Int -> SigInput -> SecKeyI -> Either String Tx
- verifyStdTx :: Network -> Tx -> [(ScriptOutput, Word64, OutPoint)] -> Bool
- mergeTxs :: Network -> [Tx] -> [(ScriptOutput, Word64, OutPoint)] -> Either String Tx
- sigKeys :: ScriptOutput -> Maybe RedeemScript -> [SecKey] -> Either String [SecKeyI]
- mergeTxInput :: Network -> [Tx] -> Tx -> ((ScriptOutput, Word64), Int) -> Either String Tx
- findSigInput :: [SigInput] -> [TxIn] -> [(SigInput, Int)]
- verifyStdInput :: Network -> Tx -> Int -> ScriptOutput -> Word64 -> Bool
- class Coin c where
- chooseCoins :: Coin c => Word64 -> Word64 -> Int -> Bool -> [c] -> Either String ([c], Word64)
- chooseCoinsSink :: (Monad m, Coin c) => Word64 -> Word64 -> Int -> Bool -> ConduitT c Void m (Either String ([c], Word64))
- chooseMSCoins :: Coin c => Word64 -> Word64 -> (Int, Int) -> Int -> Bool -> [c] -> Either String ([c], Word64)
- chooseMSCoinsSink :: (Monad m, Coin c) => Word64 -> Word64 -> (Int, Int) -> Int -> Bool -> ConduitT c Void m (Either String ([c], Word64))
- countMulSig :: Network -> Tx -> Script -> Word64 -> Int -> [PubKey] -> [TxSignature] -> Int
- greedyAddSink :: (Monad m, Coin c) => Word64 -> (Int -> Word64) -> Bool -> ConduitT c Void m (Maybe ([c], Word64))
- guessTxFee :: Word64 -> Int -> Int -> Word64
- guessMSTxFee :: Word64 -> (Int, Int) -> Int -> Int -> Word64
- guessTxSize :: Int -> [(Int, Int)] -> Int -> Int -> Int
- guessMSSize :: (Int, Int) -> Int
Documentation
Data type representing a transaction.
Tx | |
|
Instances
Data type representing a transaction input.
TxIn | |
|
Instances
Eq TxIn Source # | |
Ord TxIn Source # | |
Read TxIn Source # | |
Show TxIn Source # | |
Generic TxIn Source # | |
Hashable TxIn Source # | |
Defined in Network.Haskoin.Transaction.Common | |
Serialize TxIn Source # | |
type Rep TxIn Source # | |
Defined in Network.Haskoin.Transaction.Common type Rep TxIn = D1 (MetaData "TxIn" "Network.Haskoin.Transaction.Common" "haskoin-core-0.8.4-AWaCExKDMsg51o0OUGuqyW" False) (C1 (MetaCons "TxIn" PrefixI True) (S1 (MetaSel (Just "prevOutput") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 OutPoint) :*: (S1 (MetaSel (Just "scriptInput") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ByteString) :*: S1 (MetaSel (Just "txInSequence") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Word32)))) |
Data type representing a transaction output.
TxOut | |
|
Instances
Eq TxOut Source # | |
Ord TxOut Source # | |
Read TxOut Source # | |
Show TxOut Source # | |
Generic TxOut Source # | |
Hashable TxOut Source # | |
Defined in Network.Haskoin.Transaction.Common | |
Serialize TxOut Source # | |
type Rep TxOut Source # | |
Defined in Network.Haskoin.Transaction.Common type Rep TxOut = D1 (MetaData "TxOut" "Network.Haskoin.Transaction.Common" "haskoin-core-0.8.4-AWaCExKDMsg51o0OUGuqyW" False) (C1 (MetaCons "TxOut" PrefixI True) (S1 (MetaSel (Just "outValue") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Word64) :*: S1 (MetaSel (Just "scriptOutput") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 ByteString))) |
The OutPoint
refers to a transaction output being spent.
OutPoint | |
|
Instances
Eq OutPoint Source # | |
Ord OutPoint Source # | |
Defined in Network.Haskoin.Transaction.Common | |
Read OutPoint Source # | |
Show OutPoint Source # | |
Generic OutPoint Source # | |
Hashable OutPoint Source # | |
Defined in Network.Haskoin.Transaction.Common | |
ToJSON OutPoint Source # | |
Defined in Network.Haskoin.Transaction.Common | |
FromJSON OutPoint Source # | |
Serialize OutPoint Source # | |
type Rep OutPoint Source # | |
Defined in Network.Haskoin.Transaction.Common type Rep OutPoint = D1 (MetaData "OutPoint" "Network.Haskoin.Transaction.Common" "haskoin-core-0.8.4-AWaCExKDMsg51o0OUGuqyW" False) (C1 (MetaCons "OutPoint" PrefixI True) (S1 (MetaSel (Just "outPointHash") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 TxHash) :*: S1 (MetaSel (Just "outPointIndex") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Word32))) |
Transaction id: hash of transaction excluding witness data.
Instances
Eq TxHash Source # | |
Ord TxHash Source # | |
Read TxHash Source # | |
Show TxHash Source # | |
IsString TxHash Source # | |
Defined in Network.Haskoin.Transaction.Common fromString :: String -> TxHash # | |
Generic TxHash Source # | |
Hashable TxHash Source # | |
Defined in Network.Haskoin.Transaction.Common | |
ToJSON TxHash Source # | |
Defined in Network.Haskoin.Transaction.Common | |
FromJSON TxHash Source # | |
Serialize TxHash Source # | |
type Rep TxHash Source # | |
Defined in Network.Haskoin.Transaction.Common |
type WitnessData = [WitnessStack] Source #
Witness stack for SegWit transactions.
type WitnessStack = [WitnessStackItem] Source #
Witness stack for SegWit transactions.
type WitnessStackItem = ByteString Source #
Witness stack item for SegWit transactions.
txHashToHex :: TxHash -> Text Source #
Convert transaction hash to hex form, reversing bytes.
nosigTxHash :: Tx -> TxHash Source #
Transaction hash excluding signatures.
nullOutPoint :: OutPoint Source #
Outpoint used in coinbase transactions.
Transaction Creation & Signing
buildAddrTx :: Network -> [OutPoint] -> [(Text, Word64)] -> Either String Tx Source #
Build a transaction by providing a list of outpoints as inputs and a list of recipient addresses and amounts as outputs.
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.
:: Network | |
-> Tx | transaction where input will be added |
-> Int | input index where signature will go |
-> ScriptOutput | output script being spent |
-> Word64 | amount of previous output |
-> Maybe RedeemScript | redeem script if pay-to-script-hash |
-> TxSignature | |
-> PubKeyI | |
-> Either String ScriptInput |
Construct an input for a transaction given a signature, public key and data about the previous output.
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 | |
|
Instances
:: Network | |
-> Tx | transaction to sign |
-> [SigInput] | signing parameters |
-> [SecKey] | private keys to sign with |
-> Either String Tx | signed transaction |
Sign a transaction by providing the SigInput
signing parametres and a
list of private keys. The signature is computed deterministically as defined
in RFC-6979.
signInput :: Network -> Tx -> Int -> SigInput -> SecKeyI -> Either String Tx Source #
Sign a single input in a transaction deterministically (RFC-6979).
verifyStdTx :: Network -> Tx -> [(ScriptOutput, Word64, OutPoint)] -> Bool Source #
Verify if a transaction is valid and all of its inputs are standard.
mergeTxs :: Network -> [Tx] -> [(ScriptOutput, Word64, OutPoint)] -> Either String Tx Source #
Merge partially-signed multisig transactions.
sigKeys :: ScriptOutput -> Maybe RedeemScript -> [SecKey] -> Either String [SecKeyI] Source #
Find from the list of provided private keys which one is required to sign
the ScriptOutput
.
mergeTxInput :: Network -> [Tx] -> Tx -> ((ScriptOutput, Word64), Int) -> Either String Tx Source #
Merge input from partially-signed multisig transactions.
verifyStdInput :: Network -> Tx -> Int -> ScriptOutput -> Word64 -> 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 | value to send |
-> Word64 | fee per byte |
-> Int | number of outputs (including change) |
-> Bool | try to find better solutions |
-> [c] | list of ordered coins to choose from |
-> Either String ([c], Word64) | coin selection and change |
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 | value to send |
-> Word64 | fee per byte |
-> Int | number of outputs (including change) |
-> Bool | try to find better solution |
-> ConduitT c Void m (Either String ([c], Word64)) | coin selection and change |
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 for conduit-based coin selection.
:: Coin c | |
=> Word64 | value to send |
-> Word64 | fee per byte |
-> (Int, Int) | m of n multisig |
-> Int | number of outputs (including change) |
-> Bool | try to find better solution |
-> [c] | |
-> Either String ([c], Word64) | coin selection change amount |
Coin selection algorithm for 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 function assumes all the coins are script hash outputs that send funds to a multisignature address.
:: (Monad m, Coin c) | |
=> Word64 | value to send |
-> Word64 | fee per byte |
-> (Int, Int) | m of n multisig |
-> Int | number of outputs (including change) |
-> Bool | try to find better solution |
-> ConduitT c Void m (Either String ([c], Word64)) | coin selection and change |
Coin selection algorithm for 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 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.
countMulSig :: Network -> Tx -> Script -> Word64 -> Int -> [PubKey] -> [TxSignature] -> Int Source #
Count the number of valid signatures for a multi-signature transaction.
:: (Monad m, Coin c) | |
=> Word64 | value to send |
-> (Int -> Word64) | coin count to fee function |
-> Bool | try to find better solutions |
-> ConduitT c Void m (Maybe ([c], Word64)) | coin selection and change |
Select coins greedily by starting from an empty solution. If the continue
flag is set, the algorithm will try to find a better solution in the stream
after a solution is found. If the next solution found is not strictly better
than the previously found solution, the algorithm stops and returns the
previous solution. If the continue flag is not set, the algorithm will return
the first solution it finds in the stream.
guessTxFee :: Word64 -> Int -> Int -> Word64 Source #
Estimate tranasction fee to pay based on transaction size estimation.
guessMSTxFee :: Word64 -> (Int, Int) -> Int -> Int -> Word64 Source #
Same as guessTxFee
but for multisig transactions.