-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontract.py
More file actions
75 lines (60 loc) · 2.16 KB
/
contract.py
File metadata and controls
75 lines (60 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Semi-Centralized nOS Name Service Smart Contract
Created by nOS - https://nos.io
"""
from boa.interop.Neo.Runtime import CheckWitness, Log
from boa.interop.Neo.Storage import GetContext, Put, Delete, Get
from boa.builtins import concat
# Main Operation
def Main(operation, args):
"""
Main definition for the smart contracts
:param operation: the operation to be performed
:type operation: str
:param args: list of arguments.
args[0] is always sender script hash
args[1] is always domain
args[2] (optional) is either target or other address
args[3] (optional) is target (if args[2] is address)
:param type: str
:return:
byterarray: The result of the operation
"""
# Common definitions
user_hash = args[0]
domain = args[1]
domain_owner_key = concat(domain, ".owner")
domain_target_key = concat(domain, ".target")
owner = b'#\xba\'\x03\xc52c\xe8\xd6\xe5"\xdc2 39\xdc\xd8\xee\xe9'
# This doesn't require authentication
if operation == 'GetDomain':
return Get(GetContext(), domain_target_key)
# Everything after this requires authorization
authorized = CheckWitness(user_hash)
if not authorized:
Log("Not Authorized")
return False
Log("Authorized")
if operation == 'RegisterDomain':
if(CheckWitness(owner)):
target = args[2]
Put(GetContext(), domain_target_key, target)
if len(args) == 4:
domain_owner = args[3]
else:
domain_owner = args[0]
Put(GetContext(), domain_owner_key, domain_owner)
return True
if operation == 'SetDomainTarget':
domain_owner = Get(GetContext(), domain_owner_key)
if (CheckWitness(domain_owner)) or (CheckWitness(owner)):
# License the product
target = args[2]
Put(GetContext(), domain_target_key, target)
return True
if operation == 'DeleteDomain':
if(CheckWitness(owner)):
Delete(GetContext(), domain_owner_key)
Delete(GetContext(), domain_target_key)
return True
return False