Contract con_miomi


Contract Code


  
1 # Initial Total Supply starts at 0.
2 # Attempt to mine a token using the mine() function
3 # Random integer between 1 - 33 chosen, match mints a token
4 # Difficulty subject to change
5 # LST001
6 balances = Hash(default_value=0)
7 # LST002
8 metadata = Hash()
9 random.seed()
10 difficulty = Variable()
11 @construct
12 def seed():
13 # LST002
14 metadata['token_name'] = "Mine Or Miss"
15 metadata['token_symbol'] = "MoM"
16 metadata['operator'] = ctx.caller
17
18 # LST002
19 @export
20 def change_metadata(key: str, value: Any):
21 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
22 metadata[key] = value
23
24 # LST001
25 @export
26 def set_diff(new_difficulty: int):
27 assert ctx.caller == metadata['operator'], 'Only operator can set diff!'
28 assert new_difficulty >= 1, 'Value must be >= 1'
29 difficulty.set(new_difficulty)
30
31 # LST001
32 @export
33 def transfer(amount: float, to: str):
34 assert amount > 0, 'Cannot send negative balances!'
35 assert balances[ctx.caller] >= amount, 'Not enough coins to send!'
36 balances[ctx.caller] -= amount
37 balances[to] += amount
38 # LST001
39 @export
40 def approve(amount: float, to: str):
41 assert amount > 0, 'Cannot send negative balances!'
42 balances[ctx.caller, to] += amount
43 # LST001
44 @export
45 def transfer_from(amount: float, to: str, main_account: str):
46 assert amount > 0, 'Cannot send negative balances!'
47 assert balances[main_account, ctx.caller] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'\
48 .format(balances[main_account, ctx.caller], amount)
49 assert balances[main_account] >= amount, 'Not enough coins to send!'
50 balances[main_account, ctx.caller] -= amount
51 balances[main_account] -= amount
52 balances[to] += amount
53 @export
54 def mine():
55
56 random_number = random.randint(0, difficulty.get())
57 if random_number == difficulty.get():
58 balances[ctx.caller] += 1
59 return f"Mined!"
60 else:
61 return "missed."

Byte Code

e3000000000000000000000000050000004000000073c2000000650064006401640264038d035a0165006401640464058d025a0265036a048300010065056401640664058d025a066407640884005a076508640183016509650a64099c02640a640b840483015a0b650864018301650c640c9c01640d640e840483015a0d650864018301650e6509640f9c0264106411840483015a0f650864018301650e6509640f9c0264126413840483015a10650864018301650e6509650964149c0364156416840483015a1165086401830164176418840083015a1264195300291ae900000000da09636f6e5f6d696f6d69da0862616c616e6365732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461290272050000007206000000da0a646966666963756c7479630000000000000000000000000300000043000000731e0000006401740064023c006403740064043c0074016a02740064053c006400530029064e7a0c4d696e65204f72204d697373da0a746f6b656e5f6e616d65da034d6f4dda0c746f6b656e5f73796d626f6cda086f70657261746f722903da0a5f5f6d65746164617461da03637478da0663616c6c6572a90072100000007210000000da00da045f5f5f5f07000000730600000000010801080172120000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720c0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904720e000000720f000000720d000000da0e417373657274696f6e4572726f72290272130000007214000000721000000072100000007211000000da0f6368616e67655f6d657461646174610d000000730600000000021001060172160000002901da0e6e65775f646966666963756c7479630100000000000000010000000300000043000000733400000074006a017402640119006b02731674036402830182017c0064036b057326740364048301820174046a057c00830101006400530029054e720c0000007a1b4f6e6c79206f70657261746f722063616e20736574206469666621e9010000007a1256616c7565206d757374206265203e3d20312906720e000000720f000000720d0000007215000000da0c5f5f646966666963756c7479da0373657429017217000000721000000072100000007211000000da087365745f64696666140000007306000000000216011001721b0000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000734c0000007c0064016b0473107400640283018201740174026a0319007c006b0573267400640383018201740174026a03050019007c00380003003c0074017c01050019007c00370003003c006400530029044e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a194e6f7420656e6f75676820636f696e7320746f2073656e642129047215000000da0a5f5f62616c616e636573720e000000720f0000002902721c000000721d000000721000000072100000007211000000da087472616e736665721b00000073080000000002100116011201721f000000630200000000000000020000000400000043000000732a0000007c0064016b0473107400640283018201740174026a037c016602050019007c00370003003c006400530029034e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047215000000721e000000720e000000720f0000002902721c000000721d000000721000000072100000007211000000da07617070726f76652300000073040000000002100172200000002903721c000000721d000000da0c6d61696e5f6163636f756e74630300000000000000030000000500000043000000738a0000007c0064016b047310740064028301820174017c0274026a03660219007c006b05733c740064036a0474017c0274026a03660219007c0083028301820174017c0219007c006b057350740064048301820174017c0274026a036602050019007c00380003003c0074017c02050019007c00380003003c0074017c01050019007c00370003003c006400530029054e72010000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a494e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a194e6f7420656e6f75676820636f696e7320746f2073656e642129057215000000721e000000720e000000720f000000da06666f726d61742903721c000000721d0000007221000000721000000072100000007211000000da0d7472616e736665725f66726f6d290000007310000000000210010c010c0114011401160110017223000000630000000000000000010000000400000043000000733a00000074006a01640174026a03830083027d007c0074026a0383006b027232740474056a06050019006402370003003c0064035300640453006400530029054e720100000072180000007a064d696e6564217a076d69737365642e2907da0672616e646f6dda0772616e64696e747219000000da03676574721e000000720e000000720f0000002901da0d72616e646f6d5f6e756d626572721000000072100000007211000000da046d696e6535000000730a000000000210010c011201040272280000004e2913da0448617368721e000000720d0000007224000000da0473656564da085661726961626c6572190000007212000000da085f5f6578706f7274da03737472da03416e797216000000da03696e74721b000000da05666c6f6174721f0000007220000000722300000072280000007210000000721000000072100000007211000000da083c6d6f64756c653e01000000731e0000000e010c0108010c030806060112060601100606011207060112050601140b