Skip to content

Commit 490e9b6

Browse files
Merge pull request #40 from mlabs-haskell/gergely/update-asset-name-handling
Update asset name handling (for cardano-cli 1.32)
2 parents 8605b4f + f0ff153 commit 490e9b6

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

bot-plutus-interface.cabal

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ library
8787

8888
other-modules: BotPlutusInterface.Server
8989
build-depends:
90-
, aeson ^>=1.5.0.0
91-
, attoparsec >=0.13.2.2
92-
, bytestring ^>=0.10.12.0
90+
, aeson ^>=1.5.0.0
91+
, attoparsec >=0.13.2.2
92+
, bytestring ^>=0.10.12.0
9393
, cardano-api
9494
, cardano-crypto
9595
, cardano-ledger-alonzo
@@ -101,6 +101,7 @@ library
101101
, filepath
102102
, freer-extras
103103
, freer-simple
104+
, hex
104105
, http-client
105106
, http-types
106107
, lens
@@ -125,7 +126,7 @@ library
125126
, servant-websockets
126127
, split
127128
, stm
128-
, text ^>=1.2.4.0
129+
, text ^>=1.2.4.0
129130
, transformers
130131
, transformers-either
131132
, uuid
@@ -147,12 +148,12 @@ test-suite bot-plutus-interface-test
147148
Spec.MockContract
148149

149150
build-depends:
150-
, aeson ^>=1.5.0.0
151+
, aeson ^>=1.5.0.0
151152
, attoparsec
152153
, base
153154
, base-compat
154155
, bot-plutus-interface
155-
, bytestring ^>=0.10.12.0
156+
, bytestring ^>=0.10.12.0
156157
, cardano-api
157158
, cardano-crypto-class
158159
, containers
@@ -163,6 +164,7 @@ test-suite bot-plutus-interface-test
163164
, freer-extras
164165
, freer-simple
165166
, generic-arbitrary
167+
, hex
166168
, lens
167169
, neat-interpolation
168170
, plutus-chain-index
@@ -183,7 +185,7 @@ test-suite bot-plutus-interface-test
183185
, tasty
184186
, tasty-hunit
185187
, tasty-quickcheck
186-
, text ^>=1.2.4.0
188+
, text ^>=1.2.4.0
187189
, uuid
188190

189191
hs-source-dirs: test

src/BotPlutusInterface/CardanoCLI.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Data.ByteString.Lazy qualified as LazyByteString
3535
import Data.ByteString.Short qualified as ShortByteString
3636
import Data.Either (fromRight)
3737
import Data.Either.Combinators (mapLeft, maybeToRight)
38+
import Data.Hex (hex)
3839
import Data.Kind (Type)
3940
import Data.List (sort)
4041
import Data.Map (Map)
@@ -371,7 +372,7 @@ flatValueToCliArg (curSymbol, name, amount)
371372
where
372373
amountStr = showText amount
373374
curSymbolStr = encodeByteString $ fromBuiltin $ unCurrencySymbol curSymbol
374-
tokenNameStr = decodeUtf8 $ fromBuiltin $ unTokenName name
375+
tokenNameStr = decodeUtf8 $ hex $ fromBuiltin $ unTokenName name
375376

376377
valueToCliArg :: Value -> Text
377378
valueToCliArg val =

src/BotPlutusInterface/UtxoParser.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import Data.Attoparsec.Text (
2424
takeWhile,
2525
(<?>),
2626
)
27+
import Data.Hex (unhex)
2728
import Data.Text (Text)
28-
import Data.Text.Encoding (encodeUtf8)
29+
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
2930
import Ledger (Address (addressCredential))
3031
import Ledger.Ada qualified as Ada
3132
import Ledger.Scripts (DatumHash (..))
@@ -105,7 +106,7 @@ tokenNameParser = do
105106
where
106107
tokenName = do
107108
void $ char '.'
108-
Value.tokenName . encodeUtf8 <$> takeWhile (/= ' ')
109+
Value.tokenName . encodeUtf8 <$> decodeHex (takeWhile (/= ' '))
109110

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

126+
decodeHex :: Parser Text -> Parser Text
127+
decodeHex rawParser =
128+
rawParser >>= \parsed -> either (const mzero) (pure . decodeUtf8) ((unhex . encodeUtf8) parsed)
129+
125130
feeParser :: Parser Integer
126131
feeParser =
127132
choice [prefixed, suffixed]

test/Spec/BotPlutusInterface/Contract.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ sendTokens = do
321321
cardano-cli transaction build --alonzo-era
322322
--tx-in ${inTxId1}#0
323323
--tx-in-collateral ${inTxId2}#1
324-
--tx-out ${addr1}+50 + 95 abcd1234.testToken
325-
--tx-out ${addr2}+1000 + 5 abcd1234.testToken
324+
--tx-out ${addr1}+50 + 95 abcd1234.74657374546F6B656E
325+
--tx-out ${addr2}+1000 + 5 abcd1234.74657374546F6B656E
326326
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
327327
--change-address ${addr1}
328328
--mainnet --protocol-params-file ./protocol.json --out-file ./txs/tx-${outTxId}.raw
@@ -416,11 +416,11 @@ mintTokens = do
416416
cardano-cli transaction build-raw --alonzo-era
417417
--tx-in ${inTxId}#0
418418
--tx-in-collateral ${inTxId}#0
419-
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.testToken
419+
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
420420
--mint-script-file ./result-scripts/policy-${curSymbol'}.plutus
421421
--mint-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
422422
--mint-execution-units (297830,1100)
423-
--mint 5 ${curSymbol'}.testToken
423+
--mint 5 ${curSymbol'}.74657374546F6B656E
424424
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
425425
--fee 0
426426
--protocol-params-file ./protocol.json --out-file ./txs/tx-${outTxId}.raw
@@ -432,10 +432,10 @@ mintTokens = do
432432
cardano-cli transaction build --alonzo-era
433433
--tx-in ${inTxId}#0
434434
--tx-in-collateral ${inTxId}#0
435-
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.testToken
435+
--tx-out ${addr2}+1000 + 5 ${curSymbol'}.74657374546F6B656E
436436
--mint-script-file ./result-scripts/policy-${curSymbol'}.plutus
437437
--mint-redeemer-file ./result-scripts/redeemer-${redeemerHash}.json
438-
--mint 5 ${curSymbol'}.testToken
438+
--mint 5 ${curSymbol'}.74657374546F6B656E
439439
--required-signer ./signing-keys/signing-key-${pkh1'}.skey
440440
--change-address ${addr1}
441441
--mainnet --protocol-params-file ./protocol.json --out-file ./txs/tx-${outTxId}.raw

test/Spec/BotPlutusInterface/UtxoParser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ singleWithNativeTokens = do
9595
addr
9696
[text| TxHash TxIx Amount
9797
--------------------------------------------------------------------------------------
98-
384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51 0 1234 lovelace + 2345 057910a2c93551443cb2c0544d1d65da3fb033deaa79452bd431ee08.testToken + 3456 7c6de14062b27c3dc3ba9f232ade32efe22fb8e2ae76b24f33212fdb.testToken2 + 4567 98a759ed2e20f6d83aa4d37d028d4bbb547a696fc345d54126188614 + TxOutDatumNone
98+
384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51 0 1234 lovelace + 2345 057910a2c93551443cb2c0544d1d65da3fb033deaa79452bd431ee08.74657374546f6b656e + 3456 7c6de14062b27c3dc3ba9f232ade32efe22fb8e2ae76b24f33212fdb.74657374546f6b656e32 + 4567 98a759ed2e20f6d83aa4d37d028d4bbb547a696fc345d54126188614 + TxOutDatumNone
9999
|]
100100
[
101101
( TxOutRef "384de3f29396fdf687551e3f9e05bd400adcd277720c71f1d2b61f17f5183e51" 0

test/Spec/MockContract.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import Data.Aeson.Extras (encodeByteString)
7777
import Data.ByteString qualified as ByteString
7878
import Data.Default (Default (def))
7979
import Data.Either.Combinators (fromRight, mapLeft)
80+
import Data.Hex (hex)
8081
import Data.Kind (Type)
8182
import Data.List (isPrefixOf)
8283
import Data.Map (Map)
@@ -342,7 +343,8 @@ valueToUtxoOut =
342343
fromBuiltin $ Value.unCurrencySymbol curSymbol
343344
tokenName' =
344345
decodeUtf8 $
345-
fromBuiltin $ Value.unTokenName tokenName
346+
hex $
347+
fromBuiltin $ Value.unTokenName tokenName
346348
in if Text.null tokenName'
347349
then curSymbol'
348350
else [text|${curSymbol'}.${tokenName'}|]

0 commit comments

Comments
 (0)