Last active
May 15, 2024 15:19
-
-
Save leonardoalt/86b2ae10cb453ea327915f63f010bfdd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
owner(owner). | |
tx(id, calldata, addr). | |
approved(owner, tx). | |
executed(tx). | |
quorum(quorum). | |
public(add_tx). | |
public(approve). | |
public(execute). | |
add_owners([]). | |
add_owners([Owner|Others]) :- | |
assert owner(Owner), | |
add_owners(Others). | |
constructor(Owners, Quorum) :- | |
add_owners(Owners), | |
assert quorum(Quorum). | |
add_tx(Id, Calldata, Addr) :- | |
owner(msg.sender), | |
not tx(Id, _, _), | |
assert tx(Id, Calldata, Addr). | |
len([], 0). | |
len([_|T], N) :- | |
len(T, N1), | |
N is N1 + 1. | |
all_approved([], _). | |
all_approved([H|T], Id) :- | |
approved(H, Id), | |
all_approved(T, Id). | |
is_approved(Id, Q, Approvers) :- | |
tx(Id, _, _), | |
quorum(Q), | |
len(Approvers) >= Q, | |
all_approved(Approvers, Id). | |
approve(Id) :- | |
owner(msg.sender), | |
tx(Id, _, _), | |
not approved(msg.sender, Id), | |
assert approved(msg.sender, Id). | |
execute(Id, Q, Approvers) :- | |
tx(Id, Calldata, Addr), | |
is_approved(Id, Q, Approvers), | |
not executed(Id), | |
evm_exec(Addr, Calldata), | |
assert executed(Id). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment