-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add encodeUtf8/decodeUtf8 for bytestrings and strings. #3288
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
plutus-core/plutus-core/test/TypeSynthesis/Golden/DecodeUtf8.plc.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(fun (con bytestring) (con string)) |
1 change: 1 addition & 0 deletions
1
plutus-core/plutus-core/test/TypeSynthesis/Golden/EncodeUtf8.plc.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(fun (con string) (con bytestring)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(con string "hello") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program [ (builtin encodeUtf8) (con string "abc") ]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ module PlutusTx.Builtins ( | |
, sha2_256 | ||
, sha3_256 | ||
, verifySignature | ||
, decodeUtf8 | ||
-- * Integer builtins | ||
, addInteger | ||
, subtractInteger | ||
|
@@ -41,6 +42,7 @@ module PlutusTx.Builtins ( | |
, emptyString | ||
, charToString | ||
, equalsString | ||
, encodeUtf8 | ||
-- * Tracing | ||
, trace | ||
) where | ||
|
@@ -113,6 +115,11 @@ lessThanByteString = (<) | |
greaterThanByteString :: ByteString -> ByteString -> Bool | ||
greaterThanByteString = (>) | ||
|
||
{-# NOINLINE decodeUtf8 #-} | ||
-- | Converts a ByteString to a String. | ||
decodeUtf8 :: ByteString -> String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haddock for these. Yes, it's somewhat obvious, but it never hurts. |
||
decodeUtf8 = mustBeReplaced "decodeUtf8" | ||
|
||
{-# NOINLINE addInteger #-} | ||
-- | Add two 'Integer's. | ||
addInteger :: Integer -> Integer -> Integer | ||
|
@@ -225,3 +232,8 @@ equalsString = mustBeReplaced "equalsString" | |
-- | Logs the given 'String' to the evaluation log. | ||
trace :: String -> () | ||
trace _ = () --mustBeReplaced "trace" | ||
|
||
{-# NOINLINE encodeUtf8 #-} | ||
-- | Convert a String into a ByteString. | ||
encodeUtf8 :: String -> ByteString | ||
encodeUtf8 = mustBeReplaced "encodeUtf8" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tangential: @michaelpj I'm so annoyed that we don't derive
Pretty
in terms ofShow
forDefaultFun
, because of stuff likeAdding that
pretty EncodeUtf8 = "encodeUtf8"
line (and the other one) manually is stupid redundant work. Should we rename the constructors ofDefaultFun
to match with thePretty
instance or should we change thePretty
instance to be derived in terms ofShow
(with the first letter lowered) even if that breaks backwards compatibility?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backwards compatibility for whom? Nobody uses the parser. I say change it. Not in this PR, though.