Alpha: simplify the metadata encoding for balance update
This commit is contained in:
parent
025187da2f
commit
1d75ff1871
@ -69,15 +69,23 @@ type balance_update =
|
|||||||
|
|
||||||
let balance_update_encoding =
|
let balance_update_encoding =
|
||||||
def "operation_metadata.alpha.balance_update" @@
|
def "operation_metadata.alpha.balance_update" @@
|
||||||
union
|
obj1
|
||||||
[ case (Tag 0)
|
(req "change"
|
||||||
(obj1 (req "credited" Tez.encoding))
|
(conv
|
||||||
(function Credited v -> Some v | Debited _ -> None)
|
(function
|
||||||
(fun v -> Credited v) ;
|
| Credited v -> Tez.to_mutez v
|
||||||
case (Tag 1)
|
| Debited v -> Int64.neg (Tez.to_mutez v))
|
||||||
(obj1 (req "debited" Tez.encoding))
|
(Json.wrap_error @@
|
||||||
(function Debited v -> Some v | Credited _ -> None)
|
fun v ->
|
||||||
(fun v -> Debited v) ]
|
if Compare.Int64.(v < 0L) then
|
||||||
|
match Tez.of_mutez (Int64.neg v) with
|
||||||
|
| Some v -> Debited v
|
||||||
|
| None -> failwith "Qty.of_mutez"
|
||||||
|
else
|
||||||
|
match Tez.of_mutez v with
|
||||||
|
| Some v -> Credited v
|
||||||
|
| None -> failwith "Qty.of_mutez")
|
||||||
|
int64))
|
||||||
|
|
||||||
type balance_updates = (balance * balance_update) list
|
type balance_updates = (balance * balance_update) list
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user