Contract con_node_test4


Contract Code


  
1 metadata = Hash()
2
3 balances = Hash(default_value=0)
4 allowances = Hash(default_value=0)
5
6 @construct
7 def seed():
8 balances[ctx.caller] = 1
9
10 metadata['token_name'] = "TNODE4"
11 metadata['token_symbol'] = "TNODE4"
12 metadata['operator'] = ctx.caller
13
14 @export
15 def change_metadata(key: str, value: Any):
16 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
17 metadata[key] = value
18
19 @export
20 def transfer(amount: float, to: str):
21 assert amount > 0, 'Cannot send negative balances!'
22 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
23
24 balances[ctx.caller] -= amount
25 balances[to] += amount
26
27 @export
28 def approve(amount: float, to: str):
29 assert amount > 0, 'Cannot send negative balances!'
30 allowances[ctx.caller, to] += amount
31
32 @export
33 def transfer_from(amount: float, to: str, main_account: str):
34 assert amount > 0, 'Cannot send negative balances!'
35 assert allowances[main_account, ctx.caller] >= amount, f'You approved {allowances[main_account, ctx.caller]} but need {amount}'
36 assert balances[main_account] >= amount, 'Not enough coins to send!'
37
38 allowances[main_account, ctx.caller] -= amount
39 balances[main_account] -= amount
40 balances[to] += amount
41
42 @export
43 def balance_of(address: str):
44 return balances[address]
45

Byte Code

e3000000000000000000000000050000004000000073ac00000065006400640164028d025a01650064036400640464058d035a02650064036400640664058d035a036407640884005a046505640083016506650764099c02640a640b840483015a0865056400830165096506640c9c02640d640e840483015a0a65056400830165096506640c9c02640f6410840483015a0b65056400830165096506650664119c0364126413840483015a0c650564008301650664149c0164156416840483015a0d641753002918da0e636f6e5f6e6f64655f7465737434da086d657461646174612902da08636f6e7472616374da046e616d65e900000000da0862616c616e6365732903da0d64656661756c745f76616c756572030000007204000000da0a616c6c6f77616e63657363000000000000000000000000030000004300000073280000006401740074016a023c006402740364033c006402740364043c0074016a02740364053c006400530029064ee901000000da06544e4f444534da0a746f6b656e5f6e616d65da0c746f6b656e5f73796d626f6cda086f70657261746f722904da0a5f5f62616c616e636573da03637478da0663616c6c6572da0a5f5f6d65746164617461a90072120000007212000000da00da045f5f5f5f07000000730800000000010a010801080172140000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720d0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904720f00000072100000007211000000da0e417373657274696f6e4572726f72290272150000007216000000721200000072120000007213000000da0f6368616e67655f6d657461646174610e000000730600000000021001060172180000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000734c0000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029044e72050000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e642129047217000000720e000000720f000000721000000029027219000000721a000000721200000072120000007213000000da087472616e736665721500000073080000000002100116011201721b000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72050000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047217000000da0c5f5f616c6c6f77616e636573720f000000721000000029027219000000721a000000721200000072120000007213000000da07617070726f76651d000000730400000000021001721d00000029037219000000721a000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000738e0000007c0064016b047310740064028301820174017c0274026a03660219007c006b0573407400640374017c0274026a03660219009b0064047c009b009d048301820174047c0219007c006b057354740064058301820174017c0274026a036602050019007c00380003003c0074047c02050019007c00380003003c0074047c01050019007c00370003003c006400530029064e72050000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a0d596f7520617070726f766564207a0a20627574206e656564207a194e6f7420656e6f75676820636f696e7320746f2073656e642129057217000000721c000000720f0000007210000000720e00000029037219000000721a000000721e000000721200000072120000007213000000da0d7472616e736665725f66726f6d23000000730e000000000210010c012401140116011001721f0000002901da0761646472657373630100000000000000010000000200000043000000730800000074007c001900530029014e2901720e00000029017220000000721200000072120000007213000000da0a62616c616e63655f6f662e0000007302000000000272210000004e290eda04486173687211000000720e000000721c0000007214000000da085f5f6578706f7274da03737472da03416e797218000000da05666c6f6174721b000000721d000000721f00000072210000007212000000721200000072120000007213000000da083c6d6f64756c653e01000000731c0000000c010e010601080308070601120606011207060112050601140a0601