I am trying to find a way to inspect the base16 hash from a Tx on-chain using plutus.
I get a BuiltinByteString from the txInputs here:
getTxIdBBS :: TxInInfo -> BuiltinByteString
getTxIdBBS txInfo' = getTxId(txOutRefId (txInInfoOutRef txInfo'))
but then I need to get the base16 representation so I can compare and inspect the hex digits. Ideally, I would like to use a function similar to below, but this only works off-chain (due to conversion to non-builtin).
import qualified Data.ByteString.Base16 as B16 (encode)
txId = getTxIdBBS (txInfo)
txId' = fromBuiltin(txId)
txIdHex = toBuiltin(B16.encode txId')
I've also tried the following, but this does not work either.
import Data.Text.Encoding qualified as E
import PlutusTx.Builtins.Internal qualified as BI
{-# INLINABLE txEncodeUtf16 #-}
txEncodeUtf16 :: BI.BuiltinString -> BI.BuiltinByteString
txEncodeUtf16 (BI.BuiltinString s) = BI.BuiltinByteString $ E.encodeUtf16BE s
txHash = txEncodeUtf16(decodeUtf8(txId))
I am not able to use decodeUtf8 on a BuiltinByteString generated by sha2_256 and get the following error:
decodeUtf8*** Exception: Cannot decode byte '\xc6': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream
I also can’t use encodeUtf16BE due to the following compiler error:
GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.ByteArray#
Any help or suggestions on how to convert the BuiltinByteString from getTxId into a BuiltinString "on-chain" where I can inspect the hex digits would be awesome.
Thanks,
Lawrence
BuiltinByteString
?