-------------------- Transaction signing
signedTransaction :: UTXO -> Script -> (PublicKey, PrivateKey) -> [TxOutput] -> Transaction
signedTransaction utxo' oldInputScript keys outputs'  = 
  set (inputs.mapped.signatureScript) newInputScript transaction
  where
    newInputScript = scriptSig (signedHash oldInputScript (snd keys) transaction) (fst keys)
    
    transaction = Transaction
      {_inputs = [TxInput { _utxo = utxo'
                          , _sequence = defaultSequence}]
      , _outputs = outputs'
      , _txVersion = TxVersion 1
      , _locktime = defaultLockTime}

-- We need to sign the double SHA the intermediateTransaction.
-- Since `signWith` always performs a SHA, we achieve correct
-- behaviour by performing one SHA in `intermediateHash`
-- and allowing `signWith` to perform the second hash
signedTransaction :: UTXO -> Script -> (PublicKey, PrivateKey) -> [TxOutput] -> Transaction
signedTransaction utxo' oldInputScript keys outputs'  = 
  set (inputs.mapped.signatureScript) newInputScript transaction
  where
    newInputScript = scriptSig (signedHash oldInputScript (snd keys) transaction) (fst keys)
    
    transaction = Transaction
      {_inputs = [TxInput { _utxo = utxo'
                          , _sequence = defaultSequence}]
      , _outputs = outputs'
      , _txVersion = TxVersion 1
      , _locktime = defaultLockTime}

-- We need to sign the double SHA the intermediateTransaction.
-- Since `signWith` always performs a SHA, we achieve correct
-- behaviour by performing one SHA in `intermediateHash`
-- and allowing `signWith` to perform the second hash
signedTransaction utxo' oldInputScript keys outputs'  = 
  set (inputs.mapped.signatureScript) newInputScript transaction
  where
    newInputScript = scriptSig (signedHash oldInputScript (snd keys) transaction) (fst keys)
    
    transaction = Transaction
      {_inputs = [TxInput { _utxo = utxo'
                          , _sequence = defaultSequence}]
      , _outputs = outputs'
      , _txVersion = TxVersion 1
      , _locktime = defaultLockTime}

-- We need to sign the double SHA the intermediateTransaction.
-- Since `signWith` always performs a SHA, we achieve correct
-- behaviour by performing one SHA in `intermediateHash`
-- and allowing `signWith` to perform the second hash