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
16 changes: 9 additions & 7 deletions bot-plutus-interface.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ library

other-modules: BotPlutusInterface.Server
build-depends:
, aeson ^>=1.5.0.0
, attoparsec >=0.13.2.2
, bytestring ^>=0.10.12.0
, aeson ^>=1.5.0.0
, attoparsec >=0.13.2.2
, bytestring ^>=0.10.12.0
, cardano-api
, cardano-crypto
, cardano-ledger-alonzo
Expand All @@ -101,6 +101,7 @@ library
, filepath
, freer-extras
, freer-simple
, hex
, http-client
, http-types
, lens
Expand All @@ -125,7 +126,7 @@ library
, servant-websockets
, split
, stm
, text ^>=1.2.4.0
, text ^>=1.2.4.0
, transformers
, transformers-either
, uuid
Expand All @@ -147,12 +148,12 @@ test-suite bot-plutus-interface-test
Spec.MockContract

build-depends:
, aeson ^>=1.5.0.0
, aeson ^>=1.5.0.0
, attoparsec
, base
, base-compat
, bot-plutus-interface
, bytestring ^>=0.10.12.0
, bytestring ^>=0.10.12.0
, cardano-api
, cardano-crypto-class
, containers
Expand All @@ -163,6 +164,7 @@ test-suite bot-plutus-interface-test
, freer-extras
, freer-simple
, generic-arbitrary
, hex
, lens
, neat-interpolation
, plutus-chain-index
Expand All @@ -183,7 +185,7 @@ test-suite bot-plutus-interface-test
, tasty
, tasty-hunit
, tasty-quickcheck
, text ^>=1.2.4.0
, text ^>=1.2.4.0
, uuid

hs-source-dirs: test
3 changes: 2 additions & 1 deletion src/BotPlutusInterface/CardanoCLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Data.ByteString.Lazy qualified as LazyByteString
import Data.ByteString.Short qualified as ShortByteString
import Data.Either (fromRight)
import Data.Either.Combinators (mapLeft, maybeToRight)
import Data.Hex (hex)
import Data.Kind (Type)
import Data.List (sort)
import Data.Map (Map)
Expand Down Expand Up @@ -371,7 +372,7 @@ flatValueToCliArg (curSymbol, name, amount)
where
amountStr = showText amount
curSymbolStr = encodeByteString $ fromBuiltin $ unCurrencySymbol curSymbol
tokenNameStr = decodeUtf8 $ fromBuiltin $ unTokenName name
tokenNameStr = decodeUtf8 $ hex $ fromBuiltin $ unTokenName name

valueToCliArg :: Value -> Text
valueToCliArg val =
Expand Down
9 changes: 7 additions & 2 deletions src/BotPlutusInterface/UtxoParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import Data.Attoparsec.Text (
takeWhile,
(<?>),
)
import Data.Hex (unhex)
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Ledger (Address (addressCredential))
import Ledger.Ada qualified as Ada
import Ledger.Scripts (DatumHash (..))
Expand Down Expand Up @@ -105,7 +106,7 @@ tokenNameParser = do
where
tokenName = do
void $ char '.'
Value.tokenName . encodeUtf8 <$> takeWhile (/= ' ')
Value.tokenName . encodeUtf8 <$> decodeHex (takeWhile (/= ' '))

datumHashNoneParser :: Parser ()
datumHashNoneParser = "TxOutDatumNone" >> pure ()
Expand All @@ -122,6 +123,10 @@ decodeHash :: Parser Text -> Parser BuiltinByteString
decodeHash rawParser =
rawParser >>= \parsed -> either (const mzero) (pure . toBuiltin) (tryDecode parsed)

decodeHex :: Parser Text -> Parser Text
decodeHex rawParser =
rawParser >>= \parsed -> either (const mzero) (pure . decodeUtf8) ((unhex . encodeUtf8) parsed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upsetting that theres no Hex instance for Text, or at least none that I can find


feeParser :: Parser Integer
feeParser =
choice [prefixed, suffixed]
Expand Down
12 changes: 6 additions & 6 deletions test/Spec/BotPlutusInterface/Contract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ sendTokens = do
cardano-cli transaction build --alonzo-era
--tx-in ${inTxId1}#0
--tx-in-collateral ${inTxId2}#1
--tx-out ${addr1}+50 + 95 abcd1234.testToken
--tx-out ${addr2}+1000 + 5 abcd1234.testToken
--tx-out ${addr1}+50 + 95 abcd1234.74657374546F6B656E
--tx-out ${addr2}+1000 + 5 abcd1234.74657374546F6B656E
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
--change-address ${addr1}
--mainnet --protocol-params-file ./protocol.json --out-file ./txs/tx-${outTxId}.raw
Expand Down Expand Up @@ -416,11 +416,11 @@ mintTokens = do
cardano-cli transaction build-raw --alonzo-era
--tx-in ${inTxId}#0
--tx-in-collateral ${inTxId}#0
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.testToken
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
--mint-script-file ./result-scripts/policy-${curSymbol'}.plutus
--mint-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
--mint-execution-units (297830,1100)
--mint 5 ${curSymbol'}.testToken
--mint 5 ${curSymbol'}.74657374546F6B656E
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
--fee 0
--protocol-params-file ./protocol.json --out-file ./txs/tx-${outTxId}.raw
Expand All @@ -432,10 +432,10 @@ mintTokens = do
cardano-cli transaction build --alonzo-era
--tx-in ${inTxId}#0
--tx-in-collateral ${inTxId}#0
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.testToken
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
--mint-script-file ./result-scripts/policy-${curSymbol'}.plutus
--mint-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
--mint 5 ${curSymbol'}.testToken
--mint 5 ${curSymbol'}.74657374546F6B656E
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
--change-address ${addr1}
--mainnet --protocol-params-file ./protocol.json --out-file ./txs/tx-${outTxId}.raw
Expand Down
2 changes: 1 addition & 1 deletion test/Spec/BotPlutusInterface/UtxoParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ singleWithNativeTokens = do
addr
[text| TxHash TxIx Amount
--------------------------------------------------------------------------------------
384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51 0 1234 lovelace + 2345 057910a2c93551443cb2c0544d1d65da3fb033deaa79452bd431ee08.testToken + 3456 7c6de14062b27c3dc3ba9f232ade32efe22fb8e2ae76b24f33212fdb.testToken2 + 4567 98a759ed2e20f6d83aa4d37d028d4bbb547a696fc345d54126188614 + TxOutDatumNone
384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51 0 1234 lovelace + 2345 057910a2c93551443cb2c0544d1d65da3fb033deaa79452bd431ee08.74657374546f6b656e + 3456 7c6de14062b27c3dc3ba9f232ade32efe22fb8e2ae76b24f33212fdb.74657374546f6b656e32 + 4567 98a759ed2e20f6d83aa4d37d028d4bbb547a696fc345d54126188614 + TxOutDatumNone
|]
[
( TxOutRef "384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51" 0
Expand Down
4 changes: 3 additions & 1 deletion test/Spec/MockContract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import Data.Aeson.Extras (encodeByteString)
import Data.ByteString qualified as ByteString
import Data.Default (Default (def))
import Data.Either.Combinators (fromRight, mapLeft)
import Data.Hex (hex)
import Data.Kind (Type)
import Data.List (isPrefixOf)
import Data.Map (Map)
Expand Down Expand Up @@ -342,7 +343,8 @@ valueToUtxoOut =
fromBuiltin $ Value.unCurrencySymbol curSymbol
tokenName' =
decodeUtf8 $
fromBuiltin $ Value.unTokenName tokenName
hex $
fromBuiltin $ Value.unTokenName tokenName
in if Text.null tokenName'
then curSymbol'
else [text|${curSymbol'}.${tokenName'}|]
Expand Down