Skip to content

Commit

Permalink
patch docs (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon authored Aug 9, 2024
1 parent 2bbedea commit f5980d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/en/pact-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Return ID if called during current pact execution, failing if not.
Obtain current pact build version.
```lisp
pact> (pact-version)
"4.12"
"4.13"
```

Top level only: this function will fail if used in module code.
Expand Down
30 changes: 16 additions & 14 deletions src/Pact/Native.hs
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ isCharsetDef =
, "(is-charset CHARSET_LATIN1 \"I am nÖt ascii, but I am latin1!\")"
]
$ T.unwords
[ "Check that a string INPUT conforms to the a supported character set CHARSET."
, "Character sets currently supported are: 'CHARSET_LATIN1' (ISO-8859-1), and"
[ "Check that a string INPUT conforms to the a supported character set CHARSET. "
, "Character sets currently supported are: 'CHARSET_LATIN1' (ISO-8859-1), and "
, "'CHARSET_ASCII' (ASCII). Support for sets up through ISO 8859-5 supplement will be"
, "added in the future."
]
Expand Down Expand Up @@ -1692,8 +1692,9 @@ hyperlaneMessageIdDef = defGasRNative
where
hyperlaneMessageId' :: RNativeFun e
hyperlaneMessageId' i args = case args of
[TObject o _] ->
computeGas' i (GHyperlaneMessageId (BS.length (getMessageBody o))) $ do
[TObject o _] -> do
msgBody <- getMessageBody i o
computeGas' i (GHyperlaneMessageId (BS.length msgBody)) $ do
disable413 <- isExecutionFlagSet FlagDisablePact413
let native = if disable413
then HyperlaneBefore413.hyperlaneMessageId
Expand All @@ -1703,15 +1704,15 @@ hyperlaneMessageIdDef = defGasRNative
Right msgId -> return $ toTerm msgId
_ -> argsError i args

getMessageBody :: Object n -> BS.ByteString
getMessageBody o =
getMessageBody :: HasInfo i => i -> Object n -> Eval e BS.ByteString
getMessageBody i o =
let mBody = do
let om = _objectMap (_oObject o)
om ^? at "messageBody" . _Just . _TLiteral . _1 . _LString
in
case mBody of
Nothing -> error "couldn't find message body"
Just t -> T.encodeUtf8 t
Nothing -> evalError' i "couldn't find message body"
Just t -> pure $ T.encodeUtf8 t

hyperlaneDecodeTokenMessageDef :: NativeDef
hyperlaneDecodeTokenMessageDef =
Expand Down Expand Up @@ -1747,19 +1748,20 @@ hyperlaneEncodeTokenMessageDef =
hyperlaneEncodeTokenMessageDef' :: RNativeFun e
hyperlaneEncodeTokenMessageDef' i args = do
case args of
[TObject o _] ->
computeGas' i (GHyperlaneEncodeDecodeTokenMessage (BS.length (getRecipient o))) $
[TObject o _] -> do
recipient <- getRecipient i o
computeGas' i (GHyperlaneEncodeDecodeTokenMessage (BS.length recipient)) $
case HyperlaneAfter413.hyperlaneEncodeTokenMessage o of
Left err -> evalError' i err
Right msg -> pure $ toTerm $ msg
_ -> argsError i args

getRecipient :: Object n -> BS.ByteString
getRecipient o =
getRecipient :: HasInfo i => i -> Object n -> Eval e BS.ByteString
getRecipient i o =
let mRecipient = do
let om = _objectMap (_oObject o)
om ^? at "recipient" . _Just . _TLiteral . _1 . _LString
in
case mRecipient of
Nothing -> error "couldn't find recipient"
Just t -> T.encodeUtf8 t
Nothing -> evalError' i "couldn't find recipient"
Just t -> pure $ T.encodeUtf8 t

0 comments on commit f5980d1

Please sign in to comment.