Skip to content

Commit 16f5151

Browse files
authored
chore(motoko): migrate cert-var to mo:core 2.4.0 (#1340)
- Add mops.toml: moc 1.5.1, core 2.4.0, -W=M0236,M0237,M0223 - Update dfx.json packtool to "mops sources" - Replace mo:base imports with mo:core equivalents - Drop unused Debug import - Use x.toNat8() context dot instead of Nat8.fromNat(Nat32.toNat(x)), dropping Nat8 import - Fix M0194: blobOfNat32 was using captured `value` instead of parameter `n`
1 parent 813bf04 commit 16f5151

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

motoko/cert-var/dfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"defaults": {
2222
"build": {
23-
"packtool": ""
23+
"packtool": "mops sources"
2424
}
2525
},
2626
"version": 1

motoko/cert-var/mops.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[toolchain]
2+
moc = "1.5.1"
3+
4+
[dependencies]
5+
core = "2.4.0"
6+
7+
[moc]
8+
# M0236: use context dot notation
9+
# M0237: redundant explicit implicit arguments
10+
# M0223: redundant type instantiation
11+
args = ["-W=M0236,M0237,M0223"]

motoko/cert-var/src/cert_var/main.mo

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
/// Simple counter (see `Counter.mo`), but uses `mo:base/CertifiedData` to
1+
/// Simple counter (see `Counter.mo`), but uses `mo:core/CertifiedData` to
22
/// implement the counter value as a certified variable.
3-
import CD "mo:base/CertifiedData";
4-
import Blob "mo:base/Blob";
5-
import Nat8 "mo:base/Nat8";
6-
import Nat32 "mo:base/Nat32";
7-
import Debug "mo:base/Debug";
3+
import CD "mo:core/CertifiedData";
4+
import Blob "mo:core/Blob";
5+
import Nat32 "mo:core/Nat32";
86

97
persistent actor Variable {
108

@@ -14,14 +12,12 @@ persistent actor Variable {
1412
/// LE encoding matches Candid encoding of Nat32, for consistency and convenience.
1513
func blobOfNat32(n : Nat32) : Blob {
1614
let byteMask : Nat32 = 0xff;
17-
func byte(x : Nat32) : Nat8 {
18-
Nat8.fromNat(Nat32.toNat(x));
19-
};
15+
func byte(x : Nat32) : Nat8 = x.toNat8();
2016
Blob.fromArray([
21-
byte(((byteMask << 0) & value) >> 0),
22-
byte(((byteMask << 8) & value) >> 8),
23-
byte(((byteMask << 16) & value) >> 16),
24-
byte(((byteMask << 24) & value) >> 24),
17+
byte(((byteMask << 0) & n) >> 0),
18+
byte(((byteMask << 8) & n) >> 8),
19+
byte(((byteMask << 16) & n) >> 16),
20+
byte(((byteMask << 24) & n) >> 24),
2521
]);
2622
};
2723

0 commit comments

Comments
 (0)