Created
December 10, 2021 16:03
-
-
Save bibekblockchain/4ee22ea4804a1fe46d467f61e1d966ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scilla_version 0 | |
library REDC | |
(* Error events *) | |
type Error = | |
| CodeNotAdmin | |
| CodeNotStagingAdmin | |
let make_error = | |
fun (result : Error) => | |
let result_code = | |
match result with | |
| CodeNotAdmin => Int32 -1 | |
| CodeNotStagingAdmin => Int32 -2 | |
end | |
in | |
{ _exception : "Error"; code : result_code; from: result } | |
contract REDC( | |
init_admin: ByStr20 | |
) | |
field admin: ByStr20 = init_admin | |
field stagingadmin: Option ByStr20 = None {ByStr20} | |
(* Emit Errors *) | |
procedure ThrowError(err : Error) | |
e = make_error err; | |
throw e | |
end | |
transition ChangeAdmin(newAdmin: ByStr20) | |
currentAdmin <- admin; | |
isAdmin = builtin eq currentAdmin _sender; | |
match isAdmin with | |
| True => | |
new_staging_admin = Some {ByStr20} newAdmin; | |
stagingadmin := new_staging_admin; | |
e = {_eventname: "ChangeAdmin"; oldAdmin: currentAdmin; newAdmin: newAdmin}; | |
event e | |
| False => | |
err = CodeNotAdmin; | |
ThrowError err | |
end | |
end | |
transition ClaimAdmin() | |
staging_admin_o <- stagingadmin; | |
match staging_admin_o with | |
| Some staging_admin => | |
is_stagingadmin = builtin eq staging_admin _sender; | |
match is_stagingadmin with | |
| True => | |
admin := _sender; | |
tmp_staging_admin = None {ByStr20}; | |
stagingadmin := tmp_staging_admin; | |
e = {_eventname: "ClaimAdmin"; newAdmin: _sender}; | |
event e | |
| False => | |
err = CodeNotStagingAdmin; | |
ThrowError err | |
end | |
| None => | |
err = CodeNotStagingAdmin; | |
ThrowError err | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment