Skip to content

Commit

Permalink
add mkInput
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Aug 6, 2020
1 parent 1a5f624 commit 80ed32a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cardano-transactions.cabal
Expand Up @@ -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
Expand Down Expand Up @@ -46,6 +46,7 @@ library
, cardano-api
, cardano-binary
, cardano-crypto
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-ledger
, cborg
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Expand Up @@ -32,6 +32,7 @@ library:
- cardano-api
- cardano-binary
- cardano-crypto
- cardano-crypto-class
- cardano-crypto-wrapper
- cardano-ledger
- cborg
Expand Down
36 changes: 36 additions & 0 deletions src/Data/UTxO/Transaction/Cardano/Shelley.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

{-# OPTIONS_HADDOCK prune #-}
Expand All @@ -12,19 +13,32 @@ module Data.UTxO.Transaction.Cardano.Shelley
mkInit
, mainnetMagic
, testnetMagic
, Network (..)

-- * Constructing Primitives
, mkInput

-- Internal
, Shelley
) where

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.
--
Expand Down Expand Up @@ -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

0 comments on commit 80ed32a

Please sign in to comment.