From f5980d1594122a65872980bf92d7295c32997116 Mon Sep 17 00:00:00 2001 From: Jose C Date: Fri, 9 Aug 2024 14:56:01 -0400 Subject: [PATCH] patch docs (#1373) --- docs/en/pact-functions.md | 2 +- src/Pact/Native.hs | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/docs/en/pact-functions.md b/docs/en/pact-functions.md index ec8184d6d..6efebdad0 100644 --- a/docs/en/pact-functions.md +++ b/docs/en/pact-functions.md @@ -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. diff --git a/src/Pact/Native.hs b/src/Pact/Native.hs index 34abbda5b..f5482045a 100644 --- a/src/Pact/Native.hs +++ b/src/Pact/Native.hs @@ -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." ] @@ -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 @@ -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 = @@ -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