-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Utility functions for manipulating bitcoin transactions
--   
--   This library provides the same functionality as the bitcoin-tx command
--   line utility, which was introduced in Bitcoin Core v0.10. These
--   functions are pure and require no communication with a bitcoin daemon.
@package bitcoin-tx
@version 0.13.1

module Data.Bitcoin.Transaction

-- | Decodes a hex representation of a transaction into a
--   <a>Transaction</a> object.
decode :: HexString -> Transaction

-- | Encodes a <a>Transaction</a> object into a hex representation.
encode :: Transaction -> HexString

-- | Calculates the transaction id of a <a>Transaction</a> as a
--   <a>TransactionId</a> so it can be used in RPC interfaces.
transactionId :: Transaction -> TransactionId
data TxnOutputType

-- | JSON of "pubkey" received.
TxnPubKey :: TxnOutputType

-- | JSON of "pubkeyhash" received.
TxnPubKeyHash :: TxnOutputType

-- | JSON of "scripthash" received.
TxnScriptHash :: TxnOutputType

-- | JSON of "multisig" received.
TxnMultisig :: TxnOutputType
data TransactionHash
TransactionHash :: Integer -> TransactionHash

-- | The OutPoint is used inside a transaction input to reference the
--   previous transaction output that it is spending.
data OutPoint
OutPoint :: TransactionHash -> Word32 -> OutPoint

-- | The hash of the referenced transaction.
[_outPointHash] :: OutPoint -> TransactionHash

-- | The position of the specific output in the transaction. The first
--   output position is 0.
[_outPointIndex] :: OutPoint -> Word32
outPointIndex :: Lens' OutPoint Word32
outPointHash :: Lens' OutPoint TransactionHash

-- | Data type representing a transaction input.
data TransactionIn
TransactionIn :: OutPoint -> Script -> Word32 -> TransactionIn

-- | Reference the previous transaction output (hash + position)
[_prevOutput] :: TransactionIn -> OutPoint

-- | Script providing the requirements of the previous transaction output
--   to spend those coins.
[_scriptInput] :: TransactionIn -> Script

-- | 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.
[_txInSequence] :: TransactionIn -> Word32
txInSequence :: Lens' TransactionIn Word32
scriptInput :: Lens' TransactionIn Script
prevOutput :: Lens' TransactionIn OutPoint

-- | Data type representing a transaction output.
data TransactionOut
TransactionOut :: Word64 -> Script -> TransactionOut

-- | Transaction output value.
[_outValue] :: TransactionOut -> Word64

-- | Script specifying the conditions to spend this output.
[_scriptOutput] :: TransactionOut -> Script
scriptOutput :: Lens' TransactionOut Script
outValue :: Lens' TransactionOut Word64

-- | Data type representing a bitcoin transaction
data Transaction
Transaction :: Word32 -> [TransactionIn] -> [TransactionOut] -> Word32 -> Transaction

-- | Transaction data format version
[_txVersion] :: Transaction -> Word32

-- | List of transaction inputs
[_txIn] :: Transaction -> [TransactionIn]

-- | List of transaction outputs
[_txOut] :: Transaction -> [TransactionOut]

-- | The block number of timestamp at which this transaction is locked
[_txLockTime] :: Transaction -> Word32
txVersion :: Lens' Transaction Word32
txOut :: Lens' Transaction [TransactionOut]
txLockTime :: Lens' Transaction Word32
txIn :: Lens' Transaction [TransactionIn]

-- | Data type representing the coinbase transaction of a <tt>Block</tt>.
--   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.
data Coinbase
Coinbase :: Word32 -> OutPoint -> ByteString -> Word32 -> [TransactionOut] -> Word32 -> Coinbase

-- | Transaction data format version.
[_cbVersion] :: Coinbase -> Word32

-- | Previous outpoint. This is ignored for coinbase transactions but
--   preserved for computing the correct txid.
[_cbPrevOutput] :: Coinbase -> OutPoint

-- | Data embedded inside the coinbase transaction.
[_cbData] :: Coinbase -> ByteString

-- | Transaction sequence number. This is ignored for coinbase transactions
--   but preserved for computing the correct txid.
[_cbInSequence] :: Coinbase -> Word32

-- | List of transaction outputs.
[_cbOut] :: Coinbase -> [TransactionOut]

-- | The block number of timestamp at which this transaction is locked.
[_cbLockTime] :: Coinbase -> Word32
cbVersion :: Lens' Coinbase Word32
cbPrevOutput :: Lens' Coinbase OutPoint
cbOut :: Lens' Coinbase [TransactionOut]
cbLockTime :: Lens' Coinbase Word32
cbInSequence :: Lens' Coinbase Word32
cbData :: Lens' Coinbase ByteString
