Skip to content

Commit

Permalink
Refactor (#80)
Browse files Browse the repository at this point in the history
* refactor

* CI

* formatting
  • Loading branch information
lukaszcz authored Jan 23, 2025
1 parent ef185f0 commit 08a1c6f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
repo: anoma/juvix-nightly-builds
cache: enable
- name: Clean
run: juvix clean --global && juvix dependencies update
run: juvix clean --global && juvix dependencies update
- name: Type Check
run: juvix typecheck
- name: Format Check
Expand Down
7 changes: 1 addition & 6 deletions Anoma/Builtin/ByteArray.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@ ByteArray-Ord : Ord ByteArray :=
instance
ByteArray-Eq : Eq ByteArray := fromOrdToEq;

zero (length : Nat) : ByteArray :=
mkByteArray
replicate@{
resultLength := length;
value := 0x0;
};
zero (length : Nat) : ByteArray := mkByteArray (replicate length 0x0);
22 changes: 4 additions & 18 deletions Anoma/Random.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ pseudoRandomNumberGeneratorNextNBytes
let
update (acc : Pair (List ByteArray) PRNG) : Pair (List ByteArray) PRNG :=
let
next :=
prngNextBytes@{
bytesSize;
generator := snd acc;
};
next := prngNextBytes bytesSize (snd acc);
in fst next :: fst acc, snd next;
in iterate n update ([], generator);

Expand Down Expand Up @@ -91,10 +87,7 @@ generateNextNonces (n : Nat) (generator : PRNG) : Pair (List Nonce) PRNG :=
--- @param randSeed The randomness seed for the PRNG.
--- @return The nonce.
generateNonce (randSeed : RandSeed) : Nonce :=
fst
generateNextNonce@{
generator := prngInit randSeed;
};
fst (generateNextNonce (prngInit randSeed));

--- Generates a pair of pseudo-random nonces from a randomness seed.
--- @param randSeed The randomness seed for the PRNG.
Expand All @@ -111,14 +104,7 @@ generateNoncePair (randSeed : RandSeed) : Pair Nonce Nonce :=
--- @param randSeed The randomness seed for the PRNG.
--- @return The list of nonces.
generateNonces (n : Nat) (randSeed : RandSeed) : List Nonce :=
fst
generateNextNonces@{
n;
generator := prngInit randSeed;
};
fst (generateNextNonces n (prngInit randSeed));

UnusedRandSeed : RandSeed :=
mkRandSeed
ByteArray.zero@{
length := FixedSize.byteSize {RandSeed};
};
mkRandSeed (ByteArray.zero (FixedSize.byteSize {RandSeed}));
6 changes: 1 addition & 5 deletions Applib/Authorization/Message.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ mkResourceRelationshipAppDataEntry
mustBeConsumed;
mustBeCreated;
};
signature : Signature :=
sign@{
message;
signer;
};
signature : Signature := sign message signer;
in case origin of
| Created commitment :=
toAppDataEntry@{
Expand Down
11 changes: 4 additions & 7 deletions Applib/Helpers.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ isNullifierPresent
Set.isMember nullifier nullifierSet;

lookupResource {A} (key : A) (customInputs : CustomInputs) : Maybe Resource :=
lookupCustomInputs@{
key;
customInputs;
};
lookupCustomInputs key customInputs;

toAppDataEntry
{Key Data : Type}
Expand Down Expand Up @@ -106,10 +103,10 @@ type TagsAndCustomInputs :=
};

tagsToPair (tags : List Tag) : Pair (List Nullifier) (List Commitment) :=
for (nfs, cms := [], []) (tag in tags) {
rfor (nfs, cms := [], []) (tag in tags) {
case tag of
| Consumed nf := nfs ++ [nf], cms
| Created cm := nfs, cms ++ [cm]
| Consumed nf := nf :: nfs, cms
| Created cm := nfs, cm :: cms
};

pairtoTags
Expand Down
2 changes: 1 addition & 1 deletion Applib/Projection/TotalQuantity.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import Applib.Resource.Traits.Quantity open;

totalQuantity {T} {{HasQuantity T}} (resources : List T) : Quantity :=
for (sum := mkQuantity 0) (r in resources) {
sum + HasQuantity.get {T} r
sum + HasQuantity.get r
};
6 changes: 1 addition & 5 deletions Applib/Resource/Standards/Ownership.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ import Applib.Resource.Standards.ValueMap open;
ownershipStandardKey : ValueMapKey := toValueMapKey "owner";

ownershipValueMapEntry (owner : ExternalIdentity) : ValueMap :=
Map.insert@{
key := ownershipStandardKey;
elem := toValueMapValue owner;
map := Map.empty;
};
Map.insert ownershipStandardKey (toValueMapValue owner) Map.empty;
4 changes: 2 additions & 2 deletions juvix.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file was autogenerated by Juvix version 0.6.8.
# This file was autogenerated by Juvix version 0.6.9.
# Do not edit this file manually.

version: 2
checksum: e9d510f29d070badc15f3b0009e471b4c9f433d8bc0f82324c011d00b5d21d11
dependencies:
- path: .juvix-build/0.6.8/stdlib/
- path: .juvix-build/0.6.9/stdlib/
dependencies: []

0 comments on commit 08a1c6f

Please sign in to comment.