Skip to content

Commit a46a35c

Browse files
committed
WIP build tx
1 parent 53afaa1 commit a46a35c

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

src/aiken-example/haskell/aiken-example.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ library
6565
, bytestring
6666
, cardano-api
6767
, containers
68+
, convex-base
69+
, mtl
70+
, plutus-ledger-api
6871
, text
72+
, transformers
6973
, wst-poc
7074

7175
test-suite wst-aiken-test
Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,68 @@
1+
{-# LANGUAGE AllowAmbiguousTypes #-}
2+
{-# LANGUAGE NamedFieldPuns #-}
3+
{-# LANGUAGE ScopedTypeVariables #-}
4+
15
-- | Off-chain code for the aiken example
26
module Wst.Aiken.Offchain
37
( register,
8+
Cip143Blueprint (..),
9+
lookupScripts,
410
)
511
where
612

13+
import Cardano.Api (ScriptInAnyLang)
14+
import Cardano.Api qualified as C
15+
import Cardano.Api.Shelley qualified as C
16+
import Control.Monad.Reader (MonadReader, runReaderT)
17+
import Convex.BuildTx qualified as BuildTx
18+
import Convex.Class (MonadBlockchain)
19+
import Data.Functor.Constant (Constant (..))
20+
import Data.Functor.Identity (Identity (..))
21+
import Data.Map qualified as Map
22+
import PlutusLedgerApi.V3 (CurrencySymbol)
23+
import Wst.Aiken.Blueprint (Blueprint (..), BlueprintKey)
724
import Wst.Offchain.BuildTx.DirectorySet (InsertNodeArgs (..))
825
import Wst.Offchain.BuildTx.DirectorySet qualified as Directory
26+
import Wst.Offchain.Env (HasDirectoryEnv)
27+
import Wst.Offchain.Query qualified as Query
28+
29+
data Cip143Blueprint v
30+
= Cip143Blueprint
31+
{ cbSymbol :: CurrencySymbol,
32+
cbTransfer :: v ScriptInAnyLang,
33+
cbIssuance :: v ScriptInAnyLang,
34+
cbGlobalStateCS :: Maybe CurrencySymbol
35+
}
36+
37+
-- | Lookup the scripts that are referenced in the CIP 143 blueprint
38+
lookupScripts :: Blueprint -> Cip143Blueprint (Constant BlueprintKey) -> Either String (Cip143Blueprint Identity)
39+
lookupScripts Blueprint {validators} b@Cip143Blueprint {cbTransfer, cbIssuance} = do
40+
tr <- maybe (Left $ "Failed to find key " <> show (getConstant cbTransfer)) Right (Map.lookup (getConstant cbTransfer) validators)
41+
i <- maybe (Left $ "Failed to find key " <> show (getConstant cbIssuance)) Right (Map.lookup (getConstant cbIssuance) validators)
42+
pure $ b {cbIssuance = Identity i, cbTransfer = Identity tr}
943

10-
-- | Register the policy
11-
register :: (Applicative m) => m ()
12-
register = do
13-
let args =
14-
InsertNodeArgs
15-
{ inaNewKey = undefined
16-
}
44+
scriptHash :: ScriptInAnyLang -> C.ScriptHash
45+
scriptHash (C.ScriptInAnyLang _ s) = C.hashScript s
46+
47+
mkArgs :: Cip143Blueprint Identity -> InsertNodeArgs
48+
mkArgs Cip143Blueprint {cbSymbol, cbTransfer, cbIssuance, cbGlobalStateCS} =
49+
InsertNodeArgs
50+
{ inaNewKey = cbSymbol,
51+
inaTransferLogic = C.StakeCredentialByScript $ scriptHash $ runIdentity cbTransfer,
52+
inaIssuerLogic = C.StakeCredentialByScript $ scriptHash $ runIdentity cbIssuance,
53+
inaGlobalStateCS = cbGlobalStateCS
54+
}
55+
56+
-- | Register the policies
57+
register :: forall era env m. (Monad m, C.IsBabbageBasedEra era, MonadReader env m, HasDirectoryEnv env, C.HasScriptLanguageInEra C.PlutusScriptV3 era, MonadBlockchain era m) => Cip143Blueprint Identity -> m ()
58+
register blueprint = do
59+
let args = mkArgs blueprint
60+
paramsNode <- Query.globalParamsNode @era
61+
tx <- BuildTx.runBuildTxT @era (Directory.insertDirectoryNode @era _ _ args)
1762
pure ()
63+
64+
-- other endpoints
65+
-- mint
66+
-- burn
67+
-- transfer
68+
-- force-transfer

src/regulated-stablecoin/lib/Wst/Offchain/BuildTx/DirectorySet.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ initDirectorySet = Utils.inBabbage @era $ do
8383

8484
prependTxOut output
8585

86-
8786
{-| Data for a new node to be inserted into the directory
8887
-}
8988
data InsertNodeArgs =
9089
InsertNodeArgs
91-
{ inaNewKey :: CurrencySymbol -- ^ currency symbol of the CIP-0143 token
90+
{ inaNewKey :: CurrencySymbol -- ^ currency symbol of the CIP-0143 token
9291
, inaTransferLogic :: C.StakeCredential -- ^ Stake validator for transfers
93-
, inaIssuerLogic :: C.StakeCredential -- ^ Stake validator for minting and burning
92+
, inaIssuerLogic :: C.StakeCredential -- ^ Stake validator for minting and burning
9493
, inaGlobalStateCS :: Maybe CurrencySymbol -- ^ Currency symbol of an NFT that identifies a UTxO with global parameters specific to the new token
9594
}
9695

0 commit comments

Comments
 (0)