Skip to content

Commit

Permalink
feat: add convenience function for the high-level interface
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Nov 10, 2024
1 parent 92e70e3 commit 4daf003
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Anoma/Transaction/AppData.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Stdlib.Prelude open;
import Stdlib.Trait.Ord.Eq open using {fromOrdToEq};
import Stdlib.Data.Map as Map open using {Map};
import Anoma.Builtin.ByteArray open using {ByteArray};
import Anoma.Builtin.System open using {anomaEncode; anomaDecode};
import Anoma.Utils open;

--- A data type encoding the deletion criterion.
Expand Down Expand Up @@ -74,3 +75,14 @@ module AppDataValueInternal;
instance
AppDataValue-Eq : Eq AppDataValue := fromOrdToEq;
end;

lookupAppData
{Key Value : Type} (key : Key) (appData : AppData) : Maybe Value :=
case
Map.lookup@{
key := anomaEncode key |> mkAppDataKey;
map := appData;
}
of
| nothing := nothing
| just value := just (value |> AppDataValue.data |> anomaDecode);
13 changes: 13 additions & 0 deletions Anoma/Transaction/CustomInputs.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Stdlib.Prelude open;
import Stdlib.Trait.Ord.Eq open using {fromOrdToEq};
import Stdlib.Data.Map as Map open using {Map};
import Anoma.Builtin.ByteArray open using {ByteArray};
import Anoma.Builtin.System open using {anomaEncode; anomaDecode};
import Anoma.Utils open;

--- A data type encoding the lookup key of custom inputs .
Expand Down Expand Up @@ -50,3 +51,15 @@ module CustomInputsValueInternal;
instance
CustomInputsValue-Eq : Eq CustomInputsValue := fromOrdToEq;
end;

lookupCustomInputs
{Key Value : Type} (key : Key) (customInputs : CustomInputs) : Maybe Value :=
case
Map.lookup@{
key := anomaEncode key |> mkCustomInputsKey;
map := customInputs;
}
of
| nothing := nothing
| just value :=
just (value |> CustomInputsValue.unCustomInputsValue |> anomaDecode);

0 comments on commit 4daf003

Please sign in to comment.