Contract con_uw_delivery_sys


Contract Code

1 import currency
2 import con_uwarriors_lst001
3 I = importlib
4
5 S = Hash(default_value=None)
6 metadata = Hash(default_value=0)
7 balances = Hash(default_value=0)
8 wp = ForeignHash(foreign_contract='con_uwarriors_lst001', foreign_name='balances')
9
10 @construct
11 def seed():
12 metadata['operator'] = ctx.caller
13 metadata['nitro_cost'] = 100
14 metadata['nitro_cost_pay'] = 50
15 metadata['fees'] = decimal('0.10')
16 metadata['nitro_cost_init'] = 100
17 metadata['nitro_cost_init_pay'] = 50
18 metadata['demand_cost'] = 5
19 metadata['time'] = 120
20 metadata['delivery'] = now
21
22
23 @export
24 def nitro_send_cost(contract: str, item_contract: str, uid: str, to: str, cost:float):
25 sender = ctx.caller
26 thing_master_owner = I.import_module(item_contract)
27 owner = thing_master_owner.get_owner(uid)
28
29 assert wp[sender] >= metadata['nitro_cost_pay'], 'Not enough coins to send!'
30 assert owner == sender , 'Not Owner'
31
32 con_uwarriors_lst001.transfer_from(metadata['nitro_cost_pay'], metadata['operator'], sender)
33 metadata['nitro_cost_pay'] += metadata['demand_cost']
34
35 if (now - metadata['delivery']).minutes >= metadata['time']:
36 metadata['nitro_cost_pay'] = metadata['nitro_cost_init_pay']
37
38 metadata['delivery'] = now
39
40 thing_master_contract = I.import_module(contract)
41 thing_master_contract.transfer_from(
42 uid=uid,
43 to=ctx.this,
44 main_account=ctx.caller,
45 contract=item_contract)
46
47
48 balances[uid] = True
49 balances[uid, 'item'] = {'owner': owner, 'contract': contract, 'item_contract': item_contract, 'uid': uid, 'to': to, 'cost': cost}
50
51
52 @export
53 def nitro_send_cancel(uid: str):
54 sender = ctx.caller
55 item = balances[uid, 'item']
56
57 assert balances[uid] == True , 'Not send' + balances[uid]
58 assert sender == item['owner'] , 'Not Owner' + item['owner'] + sender
59
60 thing_master_contract = I.import_module(item['contract'])
61 thing_master_contract.transfer(uid=uid, new_owner=item['owner'], contract=item['item_contract'])
62
63 balances[uid, 'item'] = ''
64 balances[uid] = False
65
66
67 @export
68 def nitro_send_confirm(uid: str):
69 sender = ctx.caller
70 item = balances[uid, 'item']
71
72 assert wp[sender] >= decimal(item['cost']) , 'Not enough coins to send!'
73 assert balances[uid] == True , 'Not Send'
74 assert item['to'] == sender , 'Not delivery receiver'
75
76 price_amount_pay = decimal(item['cost']) - (decimal(item['cost']) * metadata['fees'])
77
78 con_uwarriors_lst001.transfer_from(price_amount_pay, item[owner], sender)
79 con_uwarriors_lst001.transfer_from((decimal(item['cost']) * metadata['fees']), metadata['operator'], sender)
80
81 thing_master_contract = I.import_module(item['contract'])
82 thing_master_contract.transfer(uid=uid, new_owner=item['to'], contract=item['item_contract'])
83
84 balances[uid, 'item'] = ''
85 balances[uid] == False
86
87
88 @export
89 def nitro_send_free(contract: str, item_contract: str, uid: str, to: str):
90 sender = ctx.caller
91 thing_master_owner = I.import_module(item_contract)
92 owner = thing_master_owner.get_owner(uid)
93
94 assert wp[sender] >= metadata['nitro_cost'] , 'Not enough coins to send!'
95 assert owner == sender , 'Not Owner'
96
97 con_uwarriors_lst001.transfer_from(metadata['nitro_cost'], metadata['operator'], sender)
98 metadata['nitro_cost'] += metadata['demand_cost']
99
100 if (now - metadata['delivery']).minutes >= metadata['time']:
101 metadata['nitro_cost'] = metadata['nitro_cost_init']
102
103 metadata['delivery'] = now
104
105 thing_master_contract = I.import_module(contract)
106 thing_master_contract.transfer_from(
107 uid=uid,
108 to=to,
109 main_account=ctx.caller,
110 contract=item_contract)
111
112 @export
113 def change_metadata(key: str, value: float):
114 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
115 metadata[key] = value
116
117
118 @export
119 def operator_transfer_thing(uid: str, new_owner: str, contract: str, item_contract: str):
120 assert ctx.caller == metadata['operator'], 'Only auction operator can transfer things from contract.'
121 thing_master_contract = I.import_module(contract)
122 thing_master_contract.transfer(uid=uid, new_owner=new_owner, contract=item_contract)
123 S[uid] = False
124
125
126 @export
127 def operator_transfer_currency(amount: str, to: float):
128 assert ctx.caller == metadata['operator'], 'Only auction operator can transfer currency from contract.'
129 con_uwarriors_lst001.transfer(amount=amount, to=to)
130

Byte Code

e30000000000000000000000000700000040000000730c010000640064016c005a00640064016c015a0165025a03650464016402640364048d035a05650464006402640564048d035a06650464006402640664048d035a076508640764066402640864098d045a09640a640b84005a0a650b64028301650c650c650c650c650d640c9c05640d640e840483015a0e650b64028301650c640f9c0164106411840483015a0f650b64028301650c640f9c0164126413840483015a10650b64028301650c650c650c650c64149c0464156416840483015a11650b64028301650c650d64179c0264186419840483015a12650b64028301650c650c650c650c641a9c04641b641c840483015a13650b64028301650c650d641d9c02641e641f840483015a14640153002920e9000000004eda13636f6e5f75775f64656c69766572795f737973da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461da0862616c616e636573da14636f6e5f7577617272696f72735f6c7374303031da0277702904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572050000007206000000630000000000000000000000000300000043000000735200000074006a01740264013c006402740264033c006404740264053c00740364068301740264073c006402740264083c006404740264093c00640a7402640b3c00640c7402640d3c0074047402640e3c0064005300290f4eda086f70657261746f72e964000000da0a6e6974726f5f636f7374e932000000da0e6e6974726f5f636f73745f7061797a04302e3130da0466656573da0f6e6974726f5f636f73745f696e6974da136e6974726f5f636f73745f696e69745f706179e905000000da0b64656d616e645f636f7374e978000000da0474696d65da0864656c69766572792905da03637478da0663616c6c6572da0a5f5f6d65746164617461da07646563696d616cda036e6f77a900721f000000721f000000da00da045f5f5f5f0d000000731200000000010a01080108010c010801080108010801722100000029057205000000da0d6974656d5f636f6e7472616374da03756964da02746fda04636f737463050000000000000009000000070000004300000073dc00000074006a017d0574026a037c0183017d067c066a047c0283017d0774057c0519007406640119006b05733274076402830182017c077c056b027342740764038301820174086a097406640119007406640419007c05830301007406640105001900740664051900370003003c00740a74066406190018006a0b7406640719006b05728e740664081900740664013c00740a740664063c0074026a037c0083017d087c086a097c0274006a0c74006a017c0164098d040100640a740d7c023c007c077c007c017c027c037c04640b9c06740d7c02640c66023c0064005300290d4e72110000007a194e6f7420656e6f75676820636f696e7320746f2073656e64217a094e6f74204f776e6572720d0000007216000000721900000072180000007214000000290472230000007224000000da0c6d61696e5f6163636f756e747205000000542906da056f776e657272050000007222000000722300000072240000007225000000da046974656d290e721a000000721b000000da0149da0d696d706f72745f6d6f64756c65da096765745f6f776e6572da045f5f7770721c000000da0e417373657274696f6e4572726f727209000000da0d7472616e736665725f66726f6d721e000000da076d696e75746573da0474686973da0a5f5f62616c616e636573290972050000007222000000722300000072240000007225000000da0673656e646572da127468696e675f6d61737465725f6f776e65727227000000da157468696e675f6d61737465725f636f6e7472616374721f000000721f0000007220000000da0f6e6974726f5f73656e645f636f7374190000007324000000000306010a010a011201060110010a010c01140116010c0108010a010a010c0108010401723500000029017223000000630100000000000000040000000500000043000000738c00000074006a017d0174027c006401660219007d0274027c00190064026b02732e7403640374027c0019001700830182017c017c02640419006b02734e740364057c026404190017007c0117008301820174046a057c026406190083017d037c036a067c007c02640419007c026407190064088d030100640974027c00640166023c00640a74027c003c0064005300290b4e7228000000547a084e6f742073656e6472270000007a094e6f74204f776e65727205000000722200000029037223000000da096e65775f6f776e657272050000007220000000462907721a000000721b0000007231000000722d0000007229000000722a000000da087472616e7366657229047223000000723200000072280000007234000000721f000000721f0000007220000000da116e6974726f5f73656e645f63616e63656c300000007312000000000206010c011c0120010e010c010c010c01723800000063010000000000000005000000050000004300000073ec00000074006a017d0174027c006401660219007d0274037c01190074047c026402190083016b05732e740564038301820174027c00190064046b02734274056405830182017c02640619007c016b027356740564078301820174047c0264021900830174047c02640219008301740664081900140018007d0374076a087c037c02740919007c018303010074076a0874047c0264021900830174066408190014007406640919007c0183030100740a6a0b7c02640a190083017d047c046a0c7c007c02640619007c02640b1900640c8d030100640d74027c00640166023c0074027c001900640e6b02010064005300290f4e722800000072250000007a194e6f7420656e6f75676820636f696e7320746f2073656e6421547a084e6f742053656e6472240000007a154e6f742064656c69766572792072656365697665727212000000720d000000720500000072220000002903722300000072360000007205000000722000000046290d721a000000721b0000007231000000722c000000721d000000722d000000721c0000007209000000722e00000072270000007229000000722a00000072370000002905722300000072320000007228000000da1070726963655f616d6f756e745f7061797234000000721f000000721f0000007220000000da126e6974726f5f73656e645f636f6e6669726d3d000000731e000000000206010c011c011401140114010c011201100112010e010c010c010c01723a0000002904720500000072220000007223000000722400000063040000000000000008000000060000004300000073b800000074006a017d0474026a037c0183017d057c056a047c0283017d0674057c0419007406640119006b05733274076402830182017c067c046b027342740764038301820174086a097406640119007406640419007c04830301007406640105001900740664051900370003003c00740a74066406190018006a0b7406640719006b05728e740664081900740664013c00740a740664063c0074026a037c0083017d077c076a097c027c0374006a017c0164098d04010064005300290a4e720f0000007a194e6f7420656e6f75676820636f696e7320746f2073656e64217a094e6f74204f776e6572720d000000721600000072190000007218000000721300000029047223000000722400000072260000007205000000290c721a000000721b0000007229000000722a000000722b000000722c000000721c000000722d0000007209000000722e000000721e000000722f000000290872050000007222000000722300000072240000007232000000723300000072270000007234000000721f000000721f0000007220000000da0f6e6974726f5f73656e645f6672656550000000731e000000000206010a010a011201060110010c010a01140116010c0108010a010c01723b0000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720d0000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721a000000721b000000721c000000722d0000002902723c000000723d000000721f000000721f0000007220000000da0f6368616e67655f6d65746164617461630000007306000000000210010601723e00000029047223000000723600000072050000007222000000630400000000000000050000000500000043000000733c00000074006a017402640119006b027316740364028301820174046a057c0283017d047c046a067c007c017c0364038d030100640474077c003c006400530029054e720d0000007a384f6e6c792061756374696f6e206f70657261746f722063616e207472616e73666572207468696e67732066726f6d20636f6e74726163742e2903722300000072360000007205000000462908721a000000721b000000721c000000722d0000007229000000722a0000007237000000da035f5f53290572230000007236000000720500000072220000007234000000721f000000721f0000007220000000da176f70657261746f725f7472616e736665725f7468696e676a000000730c0000000003100106010a010801080172400000002902da06616d6f756e747224000000630200000000000000020000000400000043000000732800000074006a017402640119006b027316740364028301820174046a057c007c0164038d0201006400530029044e720d0000007a3a4f6e6c792061756374696f6e206f70657261746f722063616e207472616e736665722063757272656e63792066726f6d20636f6e74726163742e2902724100000072240000002906721a000000721b000000721c000000722d00000072090000007237000000290272410000007224000000721f000000721f0000007220000000da1a6f70657261746f725f7472616e736665725f63757272656e637975000000730600000000021001060172420000002915da0863757272656e63797209000000da09696d706f72746c69627229000000da0448617368723f000000721c0000007231000000da0b466f726569676e48617368722c0000007221000000da085f5f6578706f7274da03737472da05666c6f617472350000007238000000723a000000723b000000723e00000072400000007242000000721f000000721f000000721f0000007220000000da083c6d6f64756c653e0100000073340000000801080104010e01060108010601080104010c03080c0601080110150601100c0601101206011612060112060601060110090601