-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Offchain protocol params and directory
- Loading branch information
Showing
11 changed files
with
262 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
module Wst.Offchain.Blacklist () where |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
|
||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
module Wst.Offchain.DirectorySet ( | ||
initDirectorySet, | ||
insertDirectoryNode | ||
) where | ||
|
||
import Cardano.Api qualified as C | ||
import PlutusLedgerApi.V3 qualified as P | ||
import PlutusLedgerApi.V3 ( CurrencySymbol(..), Credential(..) ) | ||
import Convex.BuildTx (MonadBuildTx, mintPlutus, spendPublicKeyOutput, addBtx) | ||
import Convex.PlutusLedger (unTransAssetName, transPolicyId) | ||
import qualified Cardano.Api.Shelley as C | ||
import Convex.CardanoApi.Lenses qualified as L | ||
import GHC.Exts (IsList(..)) | ||
import Convex.Scripts (toHashableScriptData, fromHashableScriptData) | ||
import Control.Lens (over) | ||
import GHC.Generics (Generic) | ||
import qualified PlutusTx | ||
|
||
|
||
directoryNodeMintingScript :: C.TxIn -> C.PlutusScript C.PlutusScriptV3 | ||
directoryNodeMintingScript txIn = undefined | ||
|
||
directoryMintingPolicy :: C.TxIn -> C.PolicyId | ||
directoryMintingPolicy = C.scriptPolicyId . C.PlutusScript C.PlutusScriptV3 . directoryNodeMintingScript | ||
|
||
|
||
directoryNodeToken :: C.AssetName | ||
directoryNodeToken = unTransAssetName $ P.TokenName "DirectoryNodeNFT" | ||
|
||
directoryNodeSpendingScript :: C.Hash C.PaymentKey -> C.SimpleScript | ||
directoryNodeSpendingScript = C.RequireSignature | ||
|
||
data DirectorySetNode = DirectorySetNode | ||
{ key :: CurrencySymbol | ||
, next :: CurrencySymbol | ||
, transferLogicScript :: Credential | ||
, issuerLogicScript :: Credential | ||
} | ||
deriving stock (Show, Eq, Generic) | ||
deriving anyclass (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData) | ||
|
||
initDirectorySet :: (MonadBuildTx C.ConwayEra m) => C.NetworkId -> C.Hash C.PaymentKey -> C.TxIn -> m () | ||
initDirectorySet netId operatorHash txIn = do | ||
|
||
spendPublicKeyOutput txIn | ||
mintPlutus (directoryNodeMintingScript txIn) () directoryNodeToken 1 | ||
|
||
let | ||
val = C.TxOutValueShelleyBased C.ShelleyBasedEraConway $ C.toLedgerValue C.MaryEraOnwardsBabbage | ||
$ fromList [(C.AssetId (directoryMintingPolicy txIn) directoryNodeToken, 1)] | ||
|
||
addr = | ||
C.makeShelleyAddressInEra | ||
C.ShelleyBasedEraConway | ||
netId | ||
(C.PaymentCredentialByScript $ C.hashScript $ C.SimpleScript $ directoryNodeSpendingScript operatorHash) | ||
C.NoStakeAddress | ||
|
||
d = DirectorySetNode (CurrencySymbol "") (CurrencySymbol "") (PubKeyCredential "") (PubKeyCredential "") | ||
dat = C.TxOutDatumInline C.BabbageEraOnwardsConway $ toHashableScriptData d | ||
|
||
output :: C.TxOut C.CtxTx C.ConwayEra | ||
output = C.TxOut addr val dat C.ReferenceScriptNone | ||
|
||
addBtx (over L.txOuts (output :)) | ||
|
||
insertDirectoryNode :: (MonadBuildTx C.ConwayEra m) => C.NetworkId -> C.Hash C.PaymentKey -> (C.TxIn, C.InAnyCardanoEra (C.TxOut ctx)) -> (CurrencySymbol, Credential, Credential) -> m () | ||
insertDirectoryNode netId operatorHash (afterTxIn, afterTxOut) (newKey, transferLogic, issuerLogic) = do | ||
|
||
let | ||
(afterTxVal :: C.TxOutValue C.ConwayEra, afterTxData :: DirectorySetNode) = case afterTxOut of | ||
C.InAnyCardanoEra _ (C.TxOut _ v (C.TxOutDatumInline C.BabbageEraOnwardsConway dat) _) -> case fromHashableScriptData @DirectorySetNode dat of | ||
Just d -> (v, d) | ||
Nothing -> error "insertDirectoryNode: invalid datum" | ||
_ -> error "insertDirectoryNode: invalid output" | ||
|
||
spendPublicKeyOutput afterTxIn | ||
mintPlutus (directoryNodeMintingScript afterTxIn) () directoryNodeToken 1 | ||
|
||
let | ||
newVal = C.TxOutValueShelleyBased C.ShelleyBasedEraConway $ C.toLedgerValue C.MaryEraOnwardsBabbage | ||
$ fromList [(C.AssetId (directoryMintingPolicy afterTxIn) directoryNodeToken, 1)] | ||
|
||
addr = | ||
C.makeShelleyAddressInEra | ||
C.ShelleyBasedEraConway | ||
netId | ||
(C.PaymentCredentialByScript $ C.hashScript $ C.SimpleScript $ directoryNodeSpendingScript operatorHash) | ||
C.NoStakeAddress | ||
|
||
x = DirectorySetNode | ||
{ key = newKey | ||
, next = next afterTxData | ||
, transferLogicScript = transferLogic | ||
, issuerLogicScript = issuerLogic | ||
} | ||
newDat = C.TxOutDatumInline C.BabbageEraOnwardsConway $ toHashableScriptData x | ||
|
||
newOutput :: C.TxOut C.CtxTx C.ConwayEra | ||
newOutput = C.TxOut addr newVal newDat C.ReferenceScriptNone | ||
|
||
modifiedDat = afterTxData { next = transPolicyId $ directoryMintingPolicy afterTxIn } | ||
modifiedOutput = C.TxOut addr afterTxVal (C.TxOutDatumInline C.BabbageEraOnwardsConway $ toHashableScriptData modifiedDat) C.ReferenceScriptNone | ||
|
||
addBtx (over L.txOuts (newOutput :)) | ||
addBtx (over L.txOuts (modifiedOutput :)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
module Wst.Offchain.LinkedList ( | ||
initLinkedList | ||
) where | ||
|
||
import Cardano.Api qualified as C | ||
import PlutusLedgerApi.V3 qualified as P | ||
import Convex.BuildTx (MonadBuildTx, mintPlutus, spendPublicKeyOutput, addBtx) | ||
import Convex.PlutusLedger (unTransAssetName) | ||
import qualified Cardano.Api.Shelley as C | ||
import Convex.CardanoApi.Lenses qualified as L | ||
import GHC.Exts (IsList(..)) | ||
import Convex.Scripts (toHashableScriptData) | ||
import Control.Lens (over) | ||
import PlutusLedgerApi.Data.V3 (BuiltinByteString, CurrencySymbol) | ||
|
||
|
||
initLinkedList :: (MonadBuildTx C.ConwayEra m, P.ToData k) => C.NetworkId -> k -> m () | ||
initLinkedList netId key = do | ||
pure () | ||
|
||
insertLinkedList :: (MonadBuildTx C.ConwayEra m, P.ToData k) => C.NetworkId -> k -> m () | ||
insertLinkedList netId k = do | ||
pure () |
Oops, something went wrong.