Skip to content

Commit

Permalink
refactor: use map type for AppData and defined key and value as ByteA…
Browse files Browse the repository at this point in the history
…rray
  • Loading branch information
heueristik committed Nov 8, 2024
1 parent 472fd2f commit a30490b
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions Anoma/Transaction/AppData.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ module Anoma.Transaction.AppData;

import Stdlib.Prelude open;
import Stdlib.Trait.Ord.Eq open using {fromOrdToEq};
import Stdlib.Data.Set as Set open using {Set};
import Stdlib.Data.Map as Map open using {Map};
import Anoma.Builtin.ByteArray open using {ByteArray};
import Anoma.Utils open;

--- A fixed-size data type encoding the lookup key of application.
type AppDataKey := mkAppDataKey@{unAppDataKey : MISSING_DEFINITION};
--- A data type encoding the lookup key of application.
type AppDataKey := mkAppDataKey@{unAppDataKey : ByteArray};

--- A fixed-size data type encoding the lookup value of application data.
type AppDataValue := mkAppDataValue@{unAppDataValue : MISSING_DEFINITION};

--- A type describing an app data map entry.
type AppDataEntry :=
mkAppDataEntry@{
key : AppDataKey;
value : AppDataValue;
};
--- A data type encoding the lookup value of application data.
type AppDataValue := mkAppDataValue@{unAppDataValue : ByteArray};

--- A type describing an app data map.
AppData : Type := Set AppDataEntry;
AppData : Type := Map AppDataKey AppDataValue;

--- A module implementing traits for ;AppDataKey;.
module AppDataKeyInternal;
Expand Down Expand Up @@ -50,21 +44,3 @@ module AppDataValueInternal;
instance
AppDataValue-Eq : Eq AppDataValue := fromOrdToEq;
end;

--- A module implementing traits for ;AppDataEntry;.
module AppDataEntryInternal;
--- Compares two ;AppDataEntry;s.
compare (lhs rhs : AppDataEntry) : Ordering :=
let
prod (entry : AppDataEntry) : _ :=
AppDataEntry.key entry, AppDataEntry.value entry;
in Ord.cmp (prod lhs) (prod rhs);

--- Implements the ;Ord; trait for ;AppDataEntry;.
instance
AppDataEntry-Ord : Ord AppDataEntry := mkOrd compare;

--- Implements the ;Eq; trait for ;AppDataEntry;.
instance
AppDataEntry-Eq : Eq AppDataEntry := fromOrdToEq;
end;

0 comments on commit a30490b

Please sign in to comment.