@@ -95,6 +95,7 @@ transfer (self : KeyPair) (token : Resource) (receiver : PublicKey)
95
95
mustBeCreated := createdRs
96
96
};
97
97
in if
98
+ | not (isTransferable token) := throw mkNonTransferableError
98
99
| owner /= myself := throw mkUnauthorizedError@{expected := myself; actual := owner}
99
100
| else := ok (mkTransaction mySecret consumedRs createdRs extraData);
100
101
@@ -123,6 +124,7 @@ split (self : KeyPair) (token : Resource) (amountsAndReceivers : List (Pair Nat
123
124
mustBeCreated := createdRs
124
125
};
125
126
in if
127
+ | not (isTransferable token) := throw mkNonTransferableError
126
128
| owner /= myself := throw mkUnauthorizedError@{expected := myself; actual := owner}
127
129
| balance /= sum := throw mkInsufficientQuantityError@{limit := balance; actual := sum}
128
130
| else := ok (mkTransaction mySecret consumedRs createdRs extraData);
@@ -139,15 +141,14 @@ send (self : KeyPair) (token : Resource) (amount : Nat) (receiver : PublicKey)
139
141
let
140
142
myself : PublicKey := KeyPair.pubKey self;
141
143
availableAmount : Nat := Resource.quantity token;
142
- in
143
- case (compare availableAmount amount) of
144
- | LT := throw mkInsufficientQuantityError@{limit := availableAmount; actual := amount}
145
- | EQ := transfer self token receiver
146
- | GT :=
147
- let
148
- remainder : Nat := toNat (intSubNat availableAmount amount);
149
- in
150
- split self token [(amount, receiver); (remainder, myself)];
144
+ in case (compare availableAmount amount) of
145
+ | LT := throw mkInsufficientQuantityError@{limit := availableAmount; actual := amount}
146
+ | EQ := transfer self token receiver
147
+ | GT :=
148
+ let
149
+ remainder : Nat := toNat (intSubNat availableAmount amount);
150
+ in
151
+ split self token [(amount, receiver); (remainder, myself)];
151
152
152
153
--- Merges token ;Resource;s, if the calling ;KeyPair; is the owner of all
153
154
--- of them and the ;Label;s match.
@@ -178,12 +179,15 @@ merge (self : KeyPair) (tokens : List Resource) (receiver : PublicKey)
178
179
mustBeConsumed := [];
179
180
mustBeCreated := createdRs
180
181
};
181
- in case find ((/=) owner) (map getOwner tokens) of
182
- | just wrongOwner := throw mkUnauthorizedError@{expected := myself; actual := wrongOwner}
183
- | nothing :=
184
- case find ((/=) label) (map getLabel tokens) of
185
- | just wrongLabel := throw mkInvalidLabelError@{expected := label; actual := wrongLabel}
186
- | nothing :=
187
- case find ((/=) logic) (map getLogic tokens) of
188
- | just wrongLogic := throw mkInvalidLogicError@{expected := logic; actual := wrongLogic}
189
- | nothing := ok (mkTransaction mySecret consumedRs createdRs extraData);
182
+ in if
183
+ | not (isTransferable t) := throw mkNonTransferableError
184
+ | else :=
185
+ case find ((/=) owner) (map getOwner tokens) of
186
+ | just wrongOwner := throw mkUnauthorizedError@{expected := myself; actual := wrongOwner}
187
+ | nothing :=
188
+ case find ((/=) label) (map getLabel tokens) of
189
+ | just wrongLabel := throw mkInvalidLabelError@{expected := label; actual := wrongLabel}
190
+ | nothing :=
191
+ case find ((/=) logic) (map getLogic tokens) of
192
+ | just wrongLogic := throw mkInvalidLogicError@{expected := logic; actual := wrongLogic}
193
+ | nothing := ok (mkTransaction mySecret consumedRs createdRs extraData);
0 commit comments