-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnamecoin.py
56 lines (45 loc) · 1.17 KB
/
namecoin.py
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
import serpent
from pyethereum import tester, utils, abi
serpent_code = '''
def register(key, value):
#If not already registered, register it!
if not self.storage[key]:
self.storage[key] = value
return(1)
else:
return(-1)
def get(key):
#Returns -1 if not registered, returns value if registered
if not self.storage[key]:
return(-1)
else:
return(self.storage[key])
'''
#Create public key
public_k1 = utils.privtoaddr(tester.k1)
#Generate state and add contract to block chain
s = tester.state()
print("Tester state created")
c = s.abi_contract(serpent_code)
print("Code added to block chain")
#Test contract
o = c.get("Bob")
if o == -1:
print("No value has been stored at key \"Bob\"")
else:
print("The value stored with key \"Bob\" is " + str(o))
o = c.register("Bob", 10)
if(o == 1):
print("Key \"Bob\" and value 10 was stored!")
else:
print("Key \"Bob\" has already been assigned")
o = c.register("Bob", 15)
if(o == 1):
print("Key \"Bob\" and value 10 was stored!")
else:
print("Key \"Bob\" has already been assigned")
o = c.get("Bob")
if o == -1:
print("No value has been stored at key \"Bob\"")
else:
print("The value stored with key \"Bob\" is " + str(o))