Created
June 11, 2019 09:31
-
-
Save corck/43d98ef7563644dd20177c84d877c523 to your computer and use it in GitHub Desktop.
neo verfication example
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
from boa.interop.Neo.Runtime import GetTrigger,CheckWitness | |
from boa.interop.Neo.Storage import Get,Put,Delete,GetContext | |
from boa.interop.Neo.TriggerType import Application, Verification | |
def Main(operation, addr, value): | |
print("Running Sample v4") | |
trigger = GetTrigger() | |
# This determines that the SC is running in Verification mode | |
# This determines whether the TX will be relayed to the rest of the network | |
# The `Verification` portion of SC is *read-only*, so calls to `Storage.Put` will fail. | |
# You can, however, use `Storage.Get` | |
if trigger == Verification(): | |
print("Running Verification!") | |
# This routine is: if the invoker ( or the Address that signed the contract ) is not OWNER, | |
# Then we return False, and the TX will not be relayed to the network | |
# Otherwise, we know the owner address signed the TX and return True | |
return True | |
elif trigger == Application(): | |
print("Running Application!") | |
if not is_valid_addr(addr): | |
print("Not Valid Address") | |
return False | |
ctx = GetContext() | |
if operation == 'add': | |
balance = Get(ctx, addr) | |
new_balance = balance + value | |
Put(ctx, addr, new_balance) | |
return new_balance | |
elif operation == 'remove': | |
balance = Get(ctx, addr) | |
Put(ctx, addr, balance - value) | |
return balance - value | |
elif operation == 'balance': | |
return Get(ctx, addr) | |
return False | |
return False | |
def is_valid_addr(addr): | |
if len(addr) == 20: | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment