Skip to content

Conversation

@szg251
Copy link
Collaborator

@szg251 szg251 commented Feb 15, 2022

In a project where we use bot-plutus-interface, we use a non utf8 tokenname (it is a hash of a few things), so the current implementation would fail.

It turned out that we don't need to explicitly decode the tokenname from hex to a utf8 ByteString, it can be decoded straight into bs and it would still be interpreted the same way inside the Plutus code.
The cli adds a 0x prefix for raw bytestring tokennames, but we can simply skip over that.

@szg251 szg251 requested a review from t4ccer February 15, 2022 16:59
@samuelWilliams99
Copy link
Contributor

Bit confused over the cli logic here - does it just add a 0x if the hex after it doesn't decode to utf8?
does the existance of the 0x actually change the way the name is encoded? I assume that - given we decode to bytestring, hex would always be enough to encode the name

szg251 and others added 2 commits February 16, 2022 12:46
Co-authored-by: Samuel Williams <33094920+samuelWilliams99@users.noreply.github.com>
@szg251
Copy link
Collaborator Author

szg251 commented Feb 16, 2022

@samuelWilliams99 Couldn't find any documentation about this, but it seems like that is the case: if the token name is not a utf8 encoded string, then an 0x will be added to it. But maybe @t4ccer knows more about it, he bumped into this issue.

I spent some time to track down where the 0x is added in the cardano-cli source code, but couldn't find it TBH. This is where I ended up:
https://github.com/input-output-hk/cardano-node/blob/814df2c146f5d56f8c35a681fe75e85b905aed5d/cardano-api/src/Cardano/Api/Value.hs#L404
https://github.com/input-output-hk/cardano-node/blob/814df2c146f5d56f8c35a681fe75e85b905aed5d/cardano-api/src/Cardano/Api/SerialiseRaw.hs#L28-L32

@samuelWilliams99
Copy link
Contributor

How odd, yeah there doesn't appear to be any logic adding that - even the serialisation instance for AssetName is just id
Either way - if this fixes the issue - fine by me. Any usual hex string couldn't have a 0x prefix anyway, so its not a breaking change

@szg251 szg251 merged commit 9315a82 into master Feb 16, 2022
@szg251 szg251 deleted the gergely/raw-bytestring-tokennames branch February 16, 2022 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants