Skip to content

Latest commit

 

History

History
61 lines (55 loc) · 2.2 KB

20221214154747-txin.org

File metadata and controls

61 lines (55 loc) · 2.2 KB

TxIn

Transaction input is the output of the previous transaction.

  • Transaction inputs include a pointer and a cryptographic signature that acts as the unlocking key,
  • The pointer points back to the previous transaction output, and the key unlocks this output.
  • When an output is unlocked by an input, the blockchain marks the unlucked as spent
  • New outputs (which have not been unlocked, i.e spent) are the UTXOs
data TxIn = TxIn TxId TxIx
newtype TxIx = TxIx Word
newtype TxId = TxId (Shelley.Hash StandardCrypto Shelley.EraIndependentTxBody)
  • TxId
  • TxIx

related

getTxId

-- | Calculate the transaction identifier for a 'TxBody'.
--
getTxId :: forall era. TxBody era -> TxId
getTxId (ByronTxBody tx) =
    TxId
  . fromMaybe impossible
  . Crypto.hashFromBytesShort
  . Byron.abstractHashToShort
  . Byron.hashDecoded
  $ tx
  where
    impossible =
      error "getTxId: byron and shelley hash sizes do not match"

getTxId (ShelleyTxBody era tx _ _ _ _) =
  obtainConstraints era $ getTxIdShelley era tx
 where
  obtainConstraints
    :: ShelleyBasedEra era
    -> ((Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto, Ledger.EraTxBody (ShelleyLedgerEra era)) => a)
    -> a
  obtainConstraints ShelleyBasedEraShelley f = f
  obtainConstraints ShelleyBasedEraAllegra f = f
  obtainConstraints ShelleyBasedEraMary    f = f
  obtainConstraints ShelleyBasedEraAlonzo  f = f
  obtainConstraints ShelleyBasedEraBabbage f = f

getTxIdShelley
  :: Ledger.Crypto (ShelleyLedgerEra era) ~ StandardCrypto
  => Ledger.EraTxBody (ShelleyLedgerEra era)
  => ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxId
getTxIdShelley _ tx =
    TxId
  . Crypto.castHash
  . (\(Ledger.TxId txhash) -> SafeHash.extractHash txhash)
  $ Ledger.txid tx