Contract con_mineit


Contract Code


  
1 # Initial Total Supply starts at 0.
2 # You can mine this token using the mine() function
3 # It generates 2 random numbers and if they match, you will get one token and the supply is upped by 1.
4 # The range of the numbers that get generated by the random function is increasing as more supply is minted, which results in higher difficulty to mine
5 # There is a burn of 2% on any transaction to fight inflation
6 # Lets get that node hot by mining!
7
8 # LST001
9 balances = Hash(default_value=0)
10 # LST002
11 metadata = Hash()
12 random.seed()
13
14 total_supply = Variable()
15
16 @construct
17 def seed():
18 # LST002
19 metadata['token_name'] = "MineIT"
20 metadata['token_symbol'] = "MIT"
21 metadata['operator'] = ctx.caller
22 metadata['burn_address'] = '000000000000000000000000000000000000000000000000000000000000dead'
23
24 total_supply.set(0)
25
26 # LST002
27 @export
28 def change_metadata(key: str, value: Any):
29 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
30 metadata[key] = value
31
32 # LST001
33 @export
34 def transfer(amount: float, to: str):
35 assert amount > 0, 'Cannot send negative balances!'
36 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
37 balances[ctx.caller] -= amount
38 balances[to] += (amount * 0.98)
39 balances[metadata['burn_address']] += (amount * 0.02)
40
41 # LST001
42 @export
43 def approve(amount: float, to: str):
44 assert amount > 0, 'Cannot send negative balances!'
45 balances[ctx.caller, to] += amount
46
47 # LST001
48 @export
49 def transfer_from(amount: float, to: str, main_account: str):
50 assert amount > 0, 'Cannot send negative balances!'
51 assert balances[main_account, ctx.caller] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'\
52 .format(balances[main_account, ctx.caller], amount)
53 assert balances[main_account] >= amount, 'Not enough coins to send!'
54 balances[main_account, ctx.caller] -= amount
55 balances[main_account] -= amount
56 balances[to] += (amount * 0.98)
57 balances[metadata['burn_address']] += (amount * 0.02)
58
59 @export
60 def mine():
61 first_random_number_outcome = random.randint(0, total_supply.get())
62 second_random_number_outcome = random.randint(0, total_supply.get())
63 if first_random_number_outcome == second_random_number_outcome:
64 balances[ctx.caller] += 1
65 total_supply.set(total_supply.get() + 1)
66 return f"You mined one token. The outcome was {first_random_number_outcome}=={second_random_number_outcome}"
67 else:
68 return "Better luck next time!"

Byte Code

e3000000000000000000000000050000004000000073ac000000650064006401640264038d035a0165006401640464058d025a0265036a048300010065056401640664058d025a066407640884005a076508640183016509650a64099c02640a640b840483015a0b650864018301650c6509640c9c02640d640e840483015a0d650864018301650c6509640c9c02640f6410840483015a0e650864018301650c6509650964119c0364126413840483015a0f65086401830164146415840083015a10641653002917e900000000da0a636f6e5f6d696e656974da0862616c616e6365732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461290272050000007206000000da0c746f74616c5f737570706c7963000000000000000000000000030000004300000073300000006401740064023c006403740064043c0074016a02740064053c006406740064073c0074036a046408830101006400530029094eda064d696e654954da0a746f6b656e5f6e616d65da034d4954da0c746f6b656e5f73796d626f6cda086f70657261746f72da4030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303064656164da0c6275726e5f6164647265737372010000002905da0a5f5f6d65746164617461da03637478da0663616c6c6572da0e5f5f746f74616c5f737570706c79da03736574a90072150000007215000000da00da045f5f5f5f07000000730a0000000001080108010a02080172170000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720d0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721100000072120000007210000000da0e417373657274696f6e4572726f72290272180000007219000000721500000072150000007216000000da0f6368616e67655f6d65746164617461100000007306000000000210010601721b0000002902da06616d6f756e74da02746f63020000000000000002000000060000004300000073700000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c007404640483011400370003003c007401740564051900050019007c007404640683011400370003003c006400530029074e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e64217a04302e3938720f0000007a04302e30322906721a000000da0a5f5f62616c616e63657372110000007212000000da07646563696d616c72100000002902721c000000721d000000721500000072150000007216000000da087472616e7366657217000000730a000000000210011601120118017220000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573212904721a000000721e000000721100000072120000002902721c000000721d000000721500000072150000007216000000da07617070726f76652000000073040000000002100172210000002903721c000000721d000000da0c6d61696e5f6163636f756e7463030000000000000003000000060000004300000073ae0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b057350740064048301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c007405640583011400370003003c007401740664061900050019007c007405640783011400370003003c006400530029084e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e64217a04302e3938720f0000007a04302e30322907721a000000721e00000072110000007212000000da06666f726d6174721f00000072100000002903721c000000721d0000007222000000721500000072150000007216000000da0d7472616e736665725f66726f6d260000007312000000000210010c010c01140114011601100118017224000000630000000000000000020000000400000043000000736400000074006a01640174026a03830083027d0074006a01640174026a03830083027d017c007c016b02725c740474056a06050019006402370003003c0074026a0774026a038300640217008301010064037c009b0064047c019b009d045300640553006400530029064e7201000000e9010000007a25596f75206d696e6564206f6e6520746f6b656e2e20546865206f7574636f6d6520776173207a023d3d7a16426574746572206c75636b206e6578742074696d65212908da0672616e646f6dda0772616e64696e747213000000da03676574721e0000007211000000721200000072140000002902da1b66697273745f72616e646f6d5f6e756d6265725f6f7574636f6d65da1c7365636f6e645f72616e646f6d5f6e756d6265725f6f7574636f6d65721500000072150000007216000000da046d696e6533000000730e0000000002100110010801120112021003722b0000004e2911da0448617368721e00000072100000007226000000da0473656564da085661726961626c6572130000007217000000da085f5f6578706f7274da03737472da03416e79721b000000da05666c6f6174722000000072210000007224000000722b0000007215000000721500000072150000007216000000da083c6d6f64756c653e01000000731a0000000e010c0108010c0308090601120606011208060112050601140c