From 80ed32a1253ee34436f8e41b429196eca6b52d16 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Thu, 6 Aug 2020 11:21:37 +0200 Subject: [PATCH] add mkInput --- cardano-transactions.cabal | 3 +- package.yaml | 1 + src/Data/UTxO/Transaction/Cardano/Shelley.hs | 36 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cardano-transactions.cabal b/cardano-transactions.cabal index 3b7c073..aca3dca 100644 --- a/cardano-transactions.cabal +++ b/cardano-transactions.cabal @@ -4,7 +4,7 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -- --- hash: df09fbf9727e27a4624e33d59417197d0674b01eba5ab61aab9542b8fb767ec5 +-- hash: a94732c2250228fdf7598e0bbc9b6e58127a3e8102be3ceb8c2974beb71fe2b9 name: cardano-transactions version: 1.0.0 @@ -46,6 +46,7 @@ library , cardano-api , cardano-binary , cardano-crypto + , cardano-crypto-class , cardano-crypto-wrapper , cardano-ledger , cborg diff --git a/package.yaml b/package.yaml index 6aff311..b519070 100644 --- a/package.yaml +++ b/package.yaml @@ -32,6 +32,7 @@ library: - cardano-api - cardano-binary - cardano-crypto + - cardano-crypto-class - cardano-crypto-wrapper - cardano-ledger - cborg diff --git a/src/Data/UTxO/Transaction/Cardano/Shelley.hs b/src/Data/UTxO/Transaction/Cardano/Shelley.hs index 4de4b8d..5289e46 100644 --- a/src/Data/UTxO/Transaction/Cardano/Shelley.hs +++ b/src/Data/UTxO/Transaction/Cardano/Shelley.hs @@ -1,6 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_HADDOCK prune #-} @@ -12,6 +13,10 @@ module Data.UTxO.Transaction.Cardano.Shelley mkInit , mainnetMagic , testnetMagic + , Network (..) + + -- * Constructing Primitives + , mkInput -- Internal , Shelley @@ -19,12 +24,21 @@ module Data.UTxO.Transaction.Cardano.Shelley import Cardano.Api.Typed ( TxIn (..), TxOut (..) ) +import Cardano.Crypto.Hash.Class + ( Hash (UnsafeHash) ) +import Data.ByteString + ( ByteString ) +import Data.ByteString.Short + ( toShort ) import Data.UTxO.Transaction ( MkPayment (..) ) +import Data.Word + ( Word32 ) import Shelley.Spec.Ledger.BaseTypes ( Network (..) ) import qualified Cardano.Api.Typed as Cardano +import qualified Data.ByteString as BS -- | Construct a payment 'Init' for /Shelley/ from primitive types. -- @@ -80,3 +94,25 @@ instance MkPayment Shelley where lock = undefined signWith = undefined serialize = undefined + +-- | Construct a payment 'Input' for /Shelley/ from primitive types. +-- +-- __example__: +-- +-- >>> mkInput 14 =<< fromBase16 "3b402651...aad1c0b7" +-- Just (Input ...) +-- +-- @since 2.0.0 +mkInput + :: Word32 + -- ^ Input index. + -> ByteString + -- ^ Input transaction id. See also: 'fromBase16'. + -> Maybe (Input Shelley) +mkInput ix bytes = + if BS.length bytes == 32 then + Just $ Cardano.TxIn + (Cardano.TxId $ UnsafeHash $ toShort bytes) + (Cardano.TxIx (fromIntegral ix)) + else + Nothing