From 4f7f19130ea284b9a2fe65c6c7a1b9d5301b50d3 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Wed, 29 Jun 2022 17:10:33 -0600 Subject: [PATCH 01/11] Initial work on adding purchase metadata --- src/Seabug/Contract/MarketPlaceBuy.purs | 73 +++++++++++++++++-------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/src/Seabug/Contract/MarketPlaceBuy.purs b/src/Seabug/Contract/MarketPlaceBuy.purs index 19f4180..aec7f26 100644 --- a/src/Seabug/Contract/MarketPlaceBuy.purs +++ b/src/Seabug/Contract/MarketPlaceBuy.purs @@ -5,11 +5,18 @@ module Seabug.Contract.MarketPlaceBuy import Contract.Prelude -import Contract.Address - ( getNetworkId - , ownPaymentPubKeyHash +import Cardano.Types.Value as Cardano.Types.Value +import Contract.Address (getNetworkId, ownPaymentPubKeyHash) +import Contract.AuxiliaryData (setTxMetadata) +import Contract.Monad (Contract, liftContractE, liftContractM, liftedE, liftedM) +import Contract.Numeric.Natural (toBigInt) +import Contract.PlutusData + ( Datum(Datum) + , Redeemer(Redeemer) + , toData + , unitRedeemer ) - +import Contract.ProtocolParameters.Alonzo (minAdaTxOut) import Contract.ScriptLookups (UnattachedUnbalancedTx, mkUnbalancedTx) import Contract.ScriptLookups ( mintingPolicy @@ -18,21 +25,6 @@ import Contract.ScriptLookups , typedValidatorLookups , unspentOutputs ) as ScriptLookups -import Contract.Monad - ( Contract - , liftContractM - , liftContractE - , liftedE - , liftedM - ) -import Contract.Numeric.Natural (toBigInt) -import Contract.PlutusData - ( Datum(Datum) - , Redeemer(Redeemer) - , toData - , unitRedeemer - ) -import Contract.ProtocolParameters.Alonzo (minAdaTxOut) import Contract.Scripts (applyArgs, typedValidatorEnterpriseAddress) import Contract.Transaction ( BalancedSignedTransaction(BalancedSignedTransaction) @@ -52,7 +44,11 @@ import Contract.Value as Value import Contract.Wallet (getWalletAddress) import Data.Array (find) as Array import Data.BigInt (BigInt, fromInt) +import Data.BigInt as BigInt import Data.Map (insert, toUnfoldable) +import Metadata.Seabug (SeabugMetadata(..)) +import Metadata.Seabug.Share (mkShare) +import Partial.Unsafe (unsafePartial) import Seabug.MarketPlace (marketplaceValidator) import Seabug.MintingPolicy (mintingPolicy) import Seabug.Token (mkTokenName) @@ -62,6 +58,8 @@ import Seabug.Types , NftData(NftData) , NftId(NftId) ) +import Serialization.Hash (scriptHashFromBytes) +import Types.RawBytes (hexToRawBytesUnsafe) -- TODO docstring marketplaceBuy :: forall (r :: Row Type). NftData -> Contract r Unit @@ -131,8 +129,8 @@ mkMarketplaceTx (NftData nftData) = do newName <- liftedM "marketplaceBuy: Cannot hash new token" $ mkTokenName newNft log $ "curr: " <> show curr - log $ "oldName: " <> show oldName - log $ "newName: " <> show newName + log $ "oldName: " <> show oldName + log $ "newName: " <> show newName let oldNftValue = Value.singleton curr oldName $ negate one newNftValue = Value.singleton curr newName one @@ -214,4 +212,35 @@ mkMarketplaceTx (NftData nftData) = do -- the datums and redeemers will be reattached using a server with redeemers -- reindexed also. txDatumsRedeemerTxIns <- liftedE $ mkUnbalancedTx lookup constraints - pure $ txDatumsRedeemerTxIns /\ curr /\ newName + collectionNftCS <- liftedM "Could not convert between currency symbols" + $ pure + $ Cardano.Types.Value.mkCurrencySymbol + $ Value.getCurrencySymbol nftCollection.collectionNftCs + let + natToShare nat = liftedM "Invalid share" + $ pure + $ mkShare + =<< BigInt.toInt (toBigInt nat) + authorShareValidated <- natToShare nftCollection.authorShare + marketplaceShareValidated <- natToShare nftCollection.daoShare + let + meta = SeabugMetadata + { policyId: wrap + $ unsafePartial + $ fromJust + $ scriptHashFromBytes + $ hexToRawBytesUnsafe + "00000000000000000000000000000000000000000000000000000000" + , mintPolicy: mempty + , collectionNftCS + , lockingScript: nftCollection.lockingScript + , collectionNftTN: nft'.collectionNftTn + , authorPkh: unwrap nftCollection.author + , authorShare: authorShareValidated + , marketplaceScript: nftCollection.daoScript + , marketplaceShare: marketplaceShareValidated + , ownerPkh: unwrap nft'.owner + , ownerPrice: nft'.price + } + txWithMetadata <- setTxMetadata txDatumsRedeemerTxIns meta + pure $ txWithMetadata /\ curr /\ newName From b9d287459e8371a80def239a9272ba076959baec Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Thu, 30 Jun 2022 14:22:02 -0600 Subject: [PATCH 02/11] Use patched CTL to fix build The patch branch is based off the previous commit with https://github.com/Plutonomicon/cardano-transaction-lib/commit/f5785cd2005a1884df6398b3baa87533f0867501 applied The use of `/\` in an instance declaration was causing an invalid string literal in the output JS, something like "toMetadataArray/\" --- flake.lock | 8 ++++---- flake.nix | 2 +- packages.dhall | 2 +- spago-packages.nix | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 4776a6b..e1eeb28 100644 --- a/flake.lock +++ b/flake.lock @@ -549,17 +549,17 @@ "servant-purescript": "servant-purescript" }, "locked": { - "lastModified": 1654207766, - "narHash": "sha256-HeN/bCFrR/Epc6NTx5GO6UmEXACdtrLHt6p4VCFI2xE=", + "lastModified": 1656619156, + "narHash": "sha256-lVagCm6DZTMYWkn4M8AFoqjspAXoVwiqFXYG8lmT/6k=", "owner": "Plutonomicon", "repo": "cardano-transaction-lib", - "rev": "5c7e3dd0d6c001df1d7c8e7b675e1d79530dbdff", + "rev": "d1a9d61806e79adb73dcecb591e1bdd310cf4d69", "type": "github" }, "original": { "owner": "Plutonomicon", + "ref": "calum/metadata-invalid-char-fix", "repo": "cardano-transaction-lib", - "rev": "5c7e3dd0d6c001df1d7c8e7b675e1d79530dbdff", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 7244214..d5cf33e 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ type = "github"; owner = "Plutonomicon"; repo = "cardano-transaction-lib"; - rev = "a8aabb842ecc1e287d4a60ea4f4c6cff6fbfeea7"; + ref = "calum/metadata-invalid-char-fix"; }; nixpkgs.follows = "cardano-transaction-lib/nixpkgs"; }; diff --git a/packages.dhall b/packages.dhall index ebc4e01..6e21463 100644 --- a/packages.dhall +++ b/packages.dhall @@ -295,7 +295,7 @@ let additions = , "variant" ] , repo = "https://github.com/Plutonomicon/cardano-transaction-lib.git" - , version = "a8aabb842ecc1e287d4a60ea4f4c6cff6fbfeea7" + , version = "d1a9d61806e79adb73dcecb591e1bdd310cf4d69" } } in upstream // additions diff --git a/spago-packages.nix b/spago-packages.nix index a3ddfc5..7344f1f 100644 --- a/spago-packages.nix +++ b/spago-packages.nix @@ -187,11 +187,11 @@ let "cardano-transaction-lib" = pkgs.stdenv.mkDerivation { name = "cardano-transaction-lib"; - version = "a8aabb842ecc1e287d4a60ea4f4c6cff6fbfeea7"; + version = "d1a9d61806e79adb73dcecb591e1bdd310cf4d69"; src = pkgs.fetchgit { url = "https://github.com/Plutonomicon/cardano-transaction-lib.git"; - rev = "a8aabb842ecc1e287d4a60ea4f4c6cff6fbfeea7"; - sha256 = "189764f69c32556bbf2gkyy9hlv65i96yfb7pqw4fyn1r4nfmsbs"; + rev = "d1a9d61806e79adb73dcecb591e1bdd310cf4d69"; + sha256 = "1agzjdcz41kn2nm0hmz80njfra520p037y29b8c36rc3dq5a0mlm"; }; phases = "installPhase"; installPhase = "ln -s $src $out"; From a9b19bf63e0ffb3f89d5799b03264fa78bed62c1 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Thu, 30 Jun 2022 15:08:17 -0600 Subject: [PATCH 03/11] Move metadata-adding to its own function --- src/Seabug/Contract/MarketPlaceBuy.purs | 62 ++++++++++++++----------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/Seabug/Contract/MarketPlaceBuy.purs b/src/Seabug/Contract/MarketPlaceBuy.purs index aec7f26..e1bb83b 100644 --- a/src/Seabug/Contract/MarketPlaceBuy.purs +++ b/src/Seabug/Contract/MarketPlaceBuy.purs @@ -55,7 +55,7 @@ import Seabug.Token (mkTokenName) import Seabug.Types ( MarketplaceDatum(MarketplaceDatum) , MintAct(ChangeOwner) - , NftData(NftData) + , NftData(..) , NftId(NftId) ) import Serialization.Hash (scriptHashFromBytes) @@ -212,35 +212,45 @@ mkMarketplaceTx (NftData nftData) = do -- the datums and redeemers will be reattached using a server with redeemers -- reindexed also. txDatumsRedeemerTxIns <- liftedE $ mkUnbalancedTx lookup constraints - collectionNftCS <- liftedM "Could not convert between currency symbols" - $ pure - $ Cardano.Types.Value.mkCurrencySymbol - $ Value.getCurrencySymbol nftCollection.collectionNftCs + txWithMetadata <- + setSeabugMetadata (wrap nftData { nftId = newNft }) txDatumsRedeemerTxIns + pure $ txWithMetadata /\ curr /\ newName + +-- | Set metadata on the transaction for the given NFT +setSeabugMetadata + :: forall (r :: Row Type) + . NftData + -> UnattachedUnbalancedTx + -> Contract r UnattachedUnbalancedTx +setSeabugMetadata (NftData nftData) tx = do let + nftCollection = unwrap nftData.nftCollection + nftId = unwrap nftData.nftId natToShare nat = liftedM "Invalid share" $ pure $ mkShare =<< BigInt.toInt (toBigInt nat) + collectionNftCS <- liftedM "Could not convert between currency symbols" + $ pure + $ Cardano.Types.Value.mkCurrencySymbol + $ Value.getCurrencySymbol nftCollection.collectionNftCs authorShareValidated <- natToShare nftCollection.authorShare marketplaceShareValidated <- natToShare nftCollection.daoShare - let - meta = SeabugMetadata - { policyId: wrap - $ unsafePartial - $ fromJust - $ scriptHashFromBytes - $ hexToRawBytesUnsafe - "00000000000000000000000000000000000000000000000000000000" - , mintPolicy: mempty - , collectionNftCS - , lockingScript: nftCollection.lockingScript - , collectionNftTN: nft'.collectionNftTn - , authorPkh: unwrap nftCollection.author - , authorShare: authorShareValidated - , marketplaceScript: nftCollection.daoScript - , marketplaceShare: marketplaceShareValidated - , ownerPkh: unwrap nft'.owner - , ownerPrice: nft'.price - } - txWithMetadata <- setTxMetadata txDatumsRedeemerTxIns meta - pure $ txWithMetadata /\ curr /\ newName + setTxMetadata tx $ SeabugMetadata + { policyId: wrap + $ unsafePartial + $ fromJust + $ scriptHashFromBytes + $ hexToRawBytesUnsafe + "00000000000000000000000000000000000000000000000000000000" + , mintPolicy: mempty + , collectionNftCS + , lockingScript: nftCollection.lockingScript + , collectionNftTN: nftId.collectionNftTn + , authorPkh: unwrap nftCollection.author + , authorShare: authorShareValidated + , marketplaceScript: nftCollection.daoScript + , marketplaceShare: marketplaceShareValidated + , ownerPkh: unwrap nftId.owner + , ownerPrice: nftId.price + } From 409be24207ed8172f0951db2a926b8db973c7456 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Fri, 1 Jul 2022 09:18:53 -0600 Subject: [PATCH 04/11] Update policyId to use collectionNftCs --- src/Seabug/Contract/MarketPlaceBuy.purs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Seabug/Contract/MarketPlaceBuy.purs b/src/Seabug/Contract/MarketPlaceBuy.purs index e1bb83b..f6f0cfa 100644 --- a/src/Seabug/Contract/MarketPlaceBuy.purs +++ b/src/Seabug/Contract/MarketPlaceBuy.purs @@ -48,7 +48,6 @@ import Data.BigInt as BigInt import Data.Map (insert, toUnfoldable) import Metadata.Seabug (SeabugMetadata(..)) import Metadata.Seabug.Share (mkShare) -import Partial.Unsafe (unsafePartial) import Seabug.MarketPlace (marketplaceValidator) import Seabug.MintingPolicy (mintingPolicy) import Seabug.Token (mkTokenName) @@ -59,7 +58,6 @@ import Seabug.Types , NftId(NftId) ) import Serialization.Hash (scriptHashFromBytes) -import Types.RawBytes (hexToRawBytesUnsafe) -- TODO docstring marketplaceBuy :: forall (r :: Row Type). NftData -> Contract r Unit @@ -230,19 +228,20 @@ setSeabugMetadata (NftData nftData) tx = do $ pure $ mkShare =<< BigInt.toInt (toBigInt nat) + collectionNftCSBytes = Value.getCurrencySymbol nftCollection.collectionNftCs collectionNftCS <- liftedM "Could not convert between currency symbols" $ pure $ Cardano.Types.Value.mkCurrencySymbol - $ Value.getCurrencySymbol nftCollection.collectionNftCs + $ collectionNftCSBytes authorShareValidated <- natToShare nftCollection.authorShare marketplaceShareValidated <- natToShare nftCollection.daoShare + policyId <- + liftedM "Could not convert collection NFT currency symbol to script hash" + $ pure + $ wrap + <$> scriptHashFromBytes (wrap collectionNftCSBytes) setTxMetadata tx $ SeabugMetadata - { policyId: wrap - $ unsafePartial - $ fromJust - $ scriptHashFromBytes - $ hexToRawBytesUnsafe - "00000000000000000000000000000000000000000000000000000000" + { policyId , mintPolicy: mempty , collectionNftCS , lockingScript: nftCollection.lockingScript From 3c0714de832ed2f4d7d3f1f8f454461a43f00266 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Fri, 1 Jul 2022 10:49:51 -0600 Subject: [PATCH 05/11] Update policyId creation to use CTL built-in function --- src/Seabug/Contract/MarketPlaceBuy.purs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Seabug/Contract/MarketPlaceBuy.purs b/src/Seabug/Contract/MarketPlaceBuy.purs index f6f0cfa..405d6a2 100644 --- a/src/Seabug/Contract/MarketPlaceBuy.purs +++ b/src/Seabug/Contract/MarketPlaceBuy.purs @@ -57,7 +57,6 @@ import Seabug.Types , NftData(..) , NftId(NftId) ) -import Serialization.Hash (scriptHashFromBytes) -- TODO docstring marketplaceBuy :: forall (r :: Row Type). NftData -> Contract r Unit @@ -228,18 +227,18 @@ setSeabugMetadata (NftData nftData) tx = do $ pure $ mkShare =<< BigInt.toInt (toBigInt nat) - collectionNftCSBytes = Value.getCurrencySymbol nftCollection.collectionNftCs collectionNftCS <- liftedM "Could not convert between currency symbols" $ pure $ Cardano.Types.Value.mkCurrencySymbol - $ collectionNftCSBytes + $ Value.getCurrencySymbol nftCollection.collectionNftCs authorShareValidated <- natToShare nftCollection.authorShare marketplaceShareValidated <- natToShare nftCollection.daoShare policyId <- + -- Note: I don't think this should fail, newer versions of CTL + -- guarantee it won't fail liftedM "Could not convert collection NFT currency symbol to script hash" $ pure - $ wrap - <$> scriptHashFromBytes (wrap collectionNftCSBytes) + $ Value.currencyMPSHash nftCollection.collectionNftCs setTxMetadata tx $ SeabugMetadata { policyId , mintPolicy: mempty From 6e1298eeb527c9bf5543ecec34b7af06a622e3a7 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Fri, 1 Jul 2022 13:34:14 -0600 Subject: [PATCH 06/11] Use liftContractM instead of liftedM --- src/Seabug/Contract/MarketPlaceBuy.purs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Seabug/Contract/MarketPlaceBuy.purs b/src/Seabug/Contract/MarketPlaceBuy.purs index 405d6a2..d2c0c39 100644 --- a/src/Seabug/Contract/MarketPlaceBuy.purs +++ b/src/Seabug/Contract/MarketPlaceBuy.purs @@ -223,12 +223,10 @@ setSeabugMetadata (NftData nftData) tx = do let nftCollection = unwrap nftData.nftCollection nftId = unwrap nftData.nftId - natToShare nat = liftedM "Invalid share" - $ pure + natToShare nat = liftContractM "Invalid share" $ mkShare =<< BigInt.toInt (toBigInt nat) - collectionNftCS <- liftedM "Could not convert between currency symbols" - $ pure + collectionNftCS <- liftContractM "Could not convert between currency symbols" $ Cardano.Types.Value.mkCurrencySymbol $ Value.getCurrencySymbol nftCollection.collectionNftCs authorShareValidated <- natToShare nftCollection.authorShare @@ -236,8 +234,8 @@ setSeabugMetadata (NftData nftData) tx = do policyId <- -- Note: I don't think this should fail, newer versions of CTL -- guarantee it won't fail - liftedM "Could not convert collection NFT currency symbol to script hash" - $ pure + liftContractM + "Could not convert collection NFT currency symbol to script hash" $ Value.currencyMPSHash nftCollection.collectionNftCs setTxMetadata tx $ SeabugMetadata { policyId From 969e65a37d9204a4d66da7726cae29959622910b Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Wed, 6 Jul 2022 10:01:48 -0600 Subject: [PATCH 07/11] Auto-formatting change --- src/Seabug/Seabug.purs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Seabug/Seabug.purs b/src/Seabug/Seabug.purs index f10ce17..c09e8b3 100644 --- a/src/Seabug/Seabug.purs +++ b/src/Seabug/Seabug.purs @@ -9,7 +9,11 @@ import Control.Promise (Promise, fromAff) import Data.Maybe (Maybe) import Effect (Effect) import QueryM (callNami) -import Seabug.CallContract (callMarketPlaceBuy, callMarketPlaceBuyTest, callMarketPlaceListNft) +import Seabug.CallContract + ( callMarketPlaceBuy + , callMarketPlaceBuyTest + , callMarketPlaceListNft + ) import Serialization.Types (Value) import Wallet (Wallet(..), mkNamiWalletAff) From 4892ef22867b1cc4926c9cbf02c25e8f922d835d Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Fri, 8 Jul 2022 10:33:11 -0600 Subject: [PATCH 08/11] Fix build following CTL update --- src/Seabug/Contract/MarketPlaceBuy.purs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Seabug/Contract/MarketPlaceBuy.purs b/src/Seabug/Contract/MarketPlaceBuy.purs index 54d2d57..713eb07 100644 --- a/src/Seabug/Contract/MarketPlaceBuy.purs +++ b/src/Seabug/Contract/MarketPlaceBuy.purs @@ -46,8 +46,8 @@ import Data.BigInt (BigInt, fromInt) import Data.BigInt as BigInt import Data.Map (insert, toUnfoldable) import Data.String.Common (joinWith) -import Metadata.Seabug (SeabugMetadata(..)) -import Metadata.Seabug.Share (mkShare) +import Seabug.Metadata.Types (SeabugMetadata(..)) +import Seabug.Metadata.Share (mkShare) import Seabug.MarketPlace (marketplaceValidator) import Seabug.MintingPolicy (mintingPolicy) import Seabug.Token (mkTokenName) @@ -240,17 +240,12 @@ setSeabugMetadata (NftData nftData) tx = do natToShare nat = liftContractM "Invalid share" $ mkShare =<< BigInt.toInt (toBigInt nat) + policyId = Value.currencyMPSHash nftCollection.collectionNftCs collectionNftCS <- liftContractM "Could not convert between currency symbols" $ Cardano.Types.Value.mkCurrencySymbol $ Value.getCurrencySymbol nftCollection.collectionNftCs authorShareValidated <- natToShare nftCollection.authorShare marketplaceShareValidated <- natToShare nftCollection.daoShare - policyId <- - -- Note: I don't think this should fail, newer versions of CTL - -- guarantee it won't fail - liftContractM - "Could not convert collection NFT currency symbol to script hash" - $ Value.currencyMPSHash nftCollection.collectionNftCs setTxMetadata tx $ SeabugMetadata { policyId , mintPolicy: mempty From af51048f6cb1dca25c19f9504a104aabcf215416 Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Fri, 8 Jul 2022 10:33:48 -0600 Subject: [PATCH 09/11] Update CTL version to calum/metadata-invalid-char-fix HEAD This branch has the https://github.com/Plutonomicon/cardano-transaction-lib/pull/696 commit merged into it + includes my change to fix the build --- flake.nix | 2 +- packages.dhall | 4 +++- spago-packages.nix | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 79ebbe3..954eaa8 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ owner = "Plutonomicon"; repo = "cardano-transaction-lib"; # should be same rev as in packages.dhall - # Oh update, do `spago2nix generate` + # To update, do `spago2nix generate` ref = "calum/metadata-invalid-char-fix"; }; nixpkgs.follows = "cardano-transaction-lib/nixpkgs"; diff --git a/packages.dhall b/packages.dhall index 07f9e4d..faf8b24 100644 --- a/packages.dhall +++ b/packages.dhall @@ -330,7 +330,9 @@ let additions = -- should be same rev as in flake.nix -- https://github.com/Plutonomicon/cardano-transaction-lib/pull/696 -- PR: Return error if no utxo is specified for a tx input & Fix transaction inputs locking - , version = "d1a9d61806e79adb73dcecb591e1bdd310cf4d69" + -- Commit is from our branch calum/metadata-invalid-char-fix which is based off this PR and + -- includes a small fix to get the build working. + , version = "8ff7b75d2048a9ea9d625f97d27176f59b09fb6a" } } in upstream // additions diff --git a/spago-packages.nix b/spago-packages.nix index 1b41dd2..9f1c096 100644 --- a/spago-packages.nix +++ b/spago-packages.nix @@ -199,11 +199,11 @@ let "cardano-transaction-lib" = pkgs.stdenv.mkDerivation { name = "cardano-transaction-lib"; - version = "d1a9d61806e79adb73dcecb591e1bdd310cf4d69"; + version = "8ff7b75d2048a9ea9d625f97d27176f59b09fb6a"; src = pkgs.fetchgit { url = "https://github.com/Plutonomicon/cardano-transaction-lib.git"; - rev = "d1a9d61806e79adb73dcecb591e1bdd310cf4d69"; - sha256 = "1agzjdcz41kn2nm0hmz80njfra520p037y29b8c36rc3dq5a0mlm"; + rev = "8ff7b75d2048a9ea9d625f97d27176f59b09fb6a"; + sha256 = "18hi8q8dpk2fjvb4hcyrizhbmrcajb43kz23bjwgsrqzgd3jb9gb"; }; phases = "installPhase"; installPhase = "ln -s $src $out"; From d210a62314c4ad6eaaf89cfe4a2050cb31353c6a Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Fri, 8 Jul 2022 11:31:29 -0600 Subject: [PATCH 10/11] Use Contract.Value.CurrencySymbol in SeabugMetadata --- src/Seabug/CallContract.purs | 17 ++++++----------- src/Seabug/Contract/MarketPlaceBuy.purs | 6 +----- src/Seabug/Metadata.purs | 9 +-------- src/Seabug/Metadata/Types.purs | 2 +- test/Fixtures.purs | 7 +++---- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/Seabug/CallContract.purs b/src/Seabug/CallContract.purs index 880b20a..96e0561 100644 --- a/src/Seabug/CallContract.purs +++ b/src/Seabug/CallContract.purs @@ -6,7 +6,6 @@ module Seabug.CallContract import Contract.Prelude -import Cardano.Types.Value as Cardano.Types.Value import Contract.Address (Slot(Slot)) import Contract.Monad ( ConfigParams(ConfigParams) @@ -16,10 +15,7 @@ import Contract.Monad , runContract_ ) import Contract.Numeric.Natural (toBigInt) -import Contract.Prim.ByteArray - ( byteArrayToHex - , hexToByteArray - ) +import Contract.Prim.ByteArray (byteArrayToHex, hexToByteArray) import Contract.Transaction ( TransactionInput(TransactionInput) , TransactionOutput(TransactionOutput) @@ -38,19 +34,19 @@ import Control.Promise (Promise) import Control.Promise as Promise import Data.BigInt (BigInt) import Data.BigInt as BigInt +import Data.Log.Level (LogLevel(..)) import Data.Tuple.Nested ((/\)) import Data.UInt as UInt import Effect (Effect) import Effect.Aff (error) import Effect.Class (liftEffect) -import Data.Log.Level (LogLevel(..)) import Effect.Exception (Error) -import Seabug.Metadata.Types (SeabugMetadata(SeabugMetadata)) -import Seabug.Metadata.Share (unShare) import Partial.Unsafe (unsafePartial) import Plutus.Conversion (fromPlutusAddress) import Seabug.Contract.MarketPlaceBuy (marketplaceBuy) import Seabug.Contract.MarketPlaceListNft (ListNftResult, marketPlaceListNft) +import Seabug.Metadata.Share (unShare) +import Seabug.Metadata.Types (SeabugMetadata(SeabugMetadata)) import Seabug.Types ( NftCollection(NftCollection) , NftData(NftData) @@ -63,9 +59,9 @@ import Serialization.Hash , scriptHashFromBech32 , scriptHashToBech32Unsafe ) +import Types.BigNum as BigNum import Types.Natural as Nat import Wallet (mkNamiWalletAff) -import Types.BigNum as BigNum -- | Exists temporarily for testing purposes callMarketPlaceBuyTest :: String -> Effect (Promise String) @@ -228,8 +224,7 @@ buildNftList convertSeabugMetaData (SeabugMetadata m) = { policyId: scriptHashToBech32Unsafe "policy_vkh" $ unwrap m.policyId -- or the prefix should just be 'script' , mintPolicy: byteArrayToHex m.mintPolicy - , collectionNftCS: byteArrayToHex $ Cardano.Types.Value.getCurrencySymbol $ - m.collectionNftCS + , collectionNftCS: byteArrayToHex $ getCurrencySymbol m.collectionNftCS , collectionNftTN: byteArrayToHex $ getTokenName m.collectionNftTN , lockingScript: scriptHashToBech32Unsafe "script" $ unwrap m.lockingScript , authorPkh: byteArrayToHex $ unwrap $ ed25519KeyHashToBytes $ unwrap diff --git a/src/Seabug/Contract/MarketPlaceBuy.purs b/src/Seabug/Contract/MarketPlaceBuy.purs index 713eb07..1944f6e 100644 --- a/src/Seabug/Contract/MarketPlaceBuy.purs +++ b/src/Seabug/Contract/MarketPlaceBuy.purs @@ -5,7 +5,6 @@ module Seabug.Contract.MarketPlaceBuy import Contract.Prelude -import Cardano.Types.Value as Cardano.Types.Value import Contract.Address (getNetworkId, ownPaymentPubKeyHash) import Contract.AuxiliaryData (setTxMetadata) import Contract.Monad (Contract, liftContractE, liftContractM, liftedE, liftedM) @@ -241,15 +240,12 @@ setSeabugMetadata (NftData nftData) tx = do $ mkShare =<< BigInt.toInt (toBigInt nat) policyId = Value.currencyMPSHash nftCollection.collectionNftCs - collectionNftCS <- liftContractM "Could not convert between currency symbols" - $ Cardano.Types.Value.mkCurrencySymbol - $ Value.getCurrencySymbol nftCollection.collectionNftCs authorShareValidated <- natToShare nftCollection.authorShare marketplaceShareValidated <- natToShare nftCollection.daoShare setTxMetadata tx $ SeabugMetadata { policyId , mintPolicy: mempty - , collectionNftCS + , collectionNftCS: nftCollection.collectionNftCs , lockingScript: nftCollection.lockingScript , collectionNftTN: nftId.collectionNftTn , authorPkh: unwrap nftCollection.author diff --git a/src/Seabug/Metadata.purs b/src/Seabug/Metadata.purs index c9bcaa6..26dea18 100644 --- a/src/Seabug/Metadata.purs +++ b/src/Seabug/Metadata.purs @@ -10,7 +10,6 @@ import Aeson as Aeson import Affjax as Affjax import Affjax.RequestHeader as Affjax.RequestHeader import Affjax.ResponseFormat as Affjax.ResponseFormat -import Cardano.Types.Value as Cardano.Types.Value import Contract.Monad (Contract) import Contract.Prim.ByteArray (byteArrayToHex) import Contract.Transaction @@ -21,7 +20,6 @@ import Contract.Value , TokenName , getCurrencySymbol , getTokenName - , mkCurrencySymbol ) import Control.Alternative (guard) import Control.Monad.Except.Trans (ExceptT(ExceptT), except, runExceptT) @@ -33,7 +31,6 @@ import Data.Function (on) import Data.HTTP.Method (Method(GET)) import Data.Newtype (unwrap) import Seabug.Metadata.Types (SeabugMetadata(SeabugMetadata)) -import Partial.Unsafe (unsafePartial) import Debug (traceM) @@ -60,11 +57,7 @@ getIpfsHash -> ExceptT ClientError (Contract (projectId :: String | r)) Hash getIpfsHash (SeabugMetadata { collectionNftCS, collectionNftTN }) = do except <<< (decodeField "image" <=< decodeFieldJson "onchain_metadata") - =<< mkGetRequest ("assets/" <> mkAsset curr collectionNftTN) - where - curr :: CurrencySymbol - curr = unsafePartial $ fromJust $ mkCurrencySymbol $ - Cardano.Types.Value.getCurrencySymbol collectionNftCS + =<< mkGetRequest ("assets/" <> mkAsset collectionNftCS collectionNftTN) getMintingTxSeabugMetadata :: forall (r :: Row Type) diff --git a/src/Seabug/Metadata/Types.purs b/src/Seabug/Metadata/Types.purs index 6cc5f34..2bed9e9 100644 --- a/src/Seabug/Metadata/Types.purs +++ b/src/Seabug/Metadata/Types.purs @@ -40,7 +40,7 @@ import Types.Natural (Natural) import Types.PlutusData (PlutusData(Map)) import Types.PubKeyHash (PubKeyHash) import Types.Scripts (MintingPolicyHash, ValidatorHash) -import Cardano.Types.Value (CurrencySymbol, mkCurrencySymbol) +import Contract.Value (CurrencySymbol, mkCurrencySymbol) import Types.TokenName (TokenName, mkTokenName) import Types.TransactionMetadata (TransactionMetadatum(MetadataMap)) diff --git a/test/Fixtures.purs b/test/Fixtures.purs index c849110..0719dbc 100644 --- a/test/Fixtures.purs +++ b/test/Fixtures.purs @@ -21,14 +21,13 @@ import Contract.Numeric.Natural as Natural import Contract.Prelude (fromJust) import Contract.Prim.ByteArray (hexToByteArrayUnsafe) import Contract.Scripts (MintingPolicyHash(..), ScriptHash, ValidatorHash(..)) -import Contract.Value (TokenName, mkTokenName) +import Contract.Value (CurrencySymbol, mkCurrencySymbol, TokenName, mkTokenName) import Data.BigInt as BigInt -import Seabug.Metadata.Types (SeabugMetadata(..), SeabugMetadataDelta(..)) -import Seabug.Metadata.Share (Share, mkShare) import Partial.Unsafe (unsafePartial) +import Seabug.Metadata.Share (Share, mkShare) +import Seabug.Metadata.Types (SeabugMetadata(..), SeabugMetadataDelta(..)) import Serialization.Hash (ed25519KeyHashFromBytes, scriptHashFromBytes) import Types.RawBytes (hexToRawBytesUnsafe) -import Cardano.Types.Value (CurrencySymbol, mkCurrencySymbol) currencySymbol1 :: CurrencySymbol currencySymbol1 = unsafePartial $ fromJust $ mkCurrencySymbol $ From 9b65c0a0396ced1f66c4d3b0d7ed5e618d9114fe Mon Sep 17 00:00:00 2001 From: Calum Sieppert Date: Fri, 8 Jul 2022 11:35:26 -0600 Subject: [PATCH 11/11] Remove other usage of Cardano.Types.Value.CurrencySymbol --- src/Seabug/Types.purs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Seabug/Types.purs b/src/Seabug/Types.purs index bf2d02e..87c3414 100644 --- a/src/Seabug/Types.purs +++ b/src/Seabug/Types.purs @@ -11,13 +11,11 @@ module Seabug.Types import Contract.Prelude -import Cardano.Types.Value as Cardano.Types.Value import Contract.Value ( CurrencySymbol , TokenName , getCurrencySymbol , getTokenName - , mkCurrencySymbol ) import Contract.Monad (Contract) import Contract.Address (PaymentPubKeyHash, PubKeyHash) @@ -161,12 +159,7 @@ instance Aeson.DecodeAeson NftCollection where (Left $ Json.TypeMismatch "Expected Json Object") ( \o -> do - collectionNftCs <- do - nftCs <- Aeson.getField o "nftCollection'collectionNftCs" - note (Json.TypeMismatch "expected currency symbol") - $ mkCurrencySymbol - $ Cardano.Types.Value.getCurrencySymbol nftCs - + collectionNftCs <- Aeson.getField o "nftCollection'collectionNftCs" lockLockupEnd <- Aeson.getField o "nftCollection'lockLockupEnd" lockingScript <- Aeson.getField o "nftCollection'lockingScript" author <- Aeson.getField o "nftCollection'author"