Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# seabug-contracts

A library for interacting with Seabug smart contracts via the Cardano Transaction Lib (CTL).

## Tests

Use `spago test` to run the tests. Something like `nix build .#checks.<system>.seabug-contracts` can also be used, where `<system>` is something like `x86_64-linux`.
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ You can edit this file as you like.
, "bifunctors"
, "bigints"
, "cardano-transaction-lib"
, "const"
, "control"
, "debug"
, "effect"
, "either"
, "exceptions"
, "foldable-traversable"
, "http-methods"
, "maybe"
, "mote"
, "newtype"
, "ordered-collections"
, "partial"
, "prelude"
, "spec"
, "transformers"
, "tuples"
, "uint"
Expand Down
4 changes: 2 additions & 2 deletions src/Seabug/CallContract.purs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import Effect (Effect)
import Effect.Aff (error)
import Effect.Class (liftEffect)
import Effect.Exception (Error)
import Metadata.Seabug (SeabugMetadata(SeabugMetadata))
import Metadata.Seabug.Share (unShare)
import Seabug.Metadata.Types (SeabugMetadata(SeabugMetadata))
import Seabug.Metadata.Share (unShare)
import Partial.Unsafe (unsafePartial)
import Plutus.FromPlutusType (fromPlutusType)
import Seabug.Contract.MarketPlaceBuy (marketplaceBuy)
Expand Down
4 changes: 2 additions & 2 deletions src/Seabug/Contract/MarketPlaceBuy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,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
Expand Down
2 changes: 1 addition & 1 deletion src/Seabug/Metadata.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Data.Bifunctor (bimap, lmap)
import Data.Function (on)
import Data.HTTP.Method (Method(GET))
import Data.Newtype (unwrap)
import Metadata.Seabug (SeabugMetadata(SeabugMetadata))
import Seabug.Metadata.Types (SeabugMetadata(SeabugMetadata))
import Partial.Unsafe (unsafePartial)
import Types.CborBytes (cborBytesToByteArray)

Expand Down
49 changes: 49 additions & 0 deletions src/Seabug/Metadata/Share.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Seabug.Metadata.Share
( Share
, mkShare
, unShare
) where

import Prelude

import Data.BigInt (BigInt)
import Data.BigInt as BigInt
import Data.Maybe (Maybe(Just, Nothing))
import FromData (class FromData)
import Metadata.FromMetadata (class FromMetadata)
import Metadata.ToMetadata (class ToMetadata, toMetadata)
import ToData (class ToData)
import Types.Int (toBigInt) as Int
import Types.PlutusData (PlutusData(Integer))
import Types.TransactionMetadata (TransactionMetadatum(Int)) as Metadata

-- | A number between 0 and 10000 (inclusive) representing percentage of the price.
newtype Share = Share BigInt

derive newtype instance ToData Share

instance FromData Share where
fromData (Integer n) = BigInt.toInt n >>= mkShare
fromData _ = Nothing

instance ToMetadata Share where
-- Must be safe when `Share` is built using `mkShare` smart constructor.
toMetadata = toMetadata <<< unShare

instance FromMetadata Share where
fromMetadata (Metadata.Int n) =
BigInt.toInt (Int.toBigInt n) >>= mkShare
fromMetadata _ = Nothing

instance Show Share where
show (Share share) = "(mkShare (" <> show share <> "))"

derive instance Eq Share

mkShare :: Int -> Maybe Share
mkShare n
| n >= 0 && n <= 10000 = Just $ Share $ BigInt.fromInt n
| otherwise = Nothing

unShare :: Share -> BigInt
unShare (Share n) = n
Loading