Contract con_uw_delivery


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'] = 120
14 metadata['nitro_cost_pay'] = 80
15 metadata['fees'] = decimal('0.15')
16 metadata['nitro_cost_init'] = 120
17 metadata['nitro_cost_init_pay'] = 80
18 metadata['demand_cost'] = 10
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'] + cost, '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 Owner'
58
59 thing_master_contract = I.import_module(item['contract'])
60 thing_master_contract.transfer(
61 uid=uid,
62 to=item['owner'],
63 main_account=ctx.this,
64 contract=item['item_contract'])
65
66 balances[uid, 'item'] = ''
67 balances[uid] = False
68
69
70 @export
71 def nitro_send_confirm(uid: str):
72 sender = ctx.caller
73 item = balances[uid, 'item']
74
75 assert wp[sender] >= item['cost'] , 'Not enough coins to send!'
76 assert balances[uid] == True , 'Not Send'
77 assert item[to] == sender , 'Not delivery receiver'
78
79 price_amount_pay = item['cost'] - (item['cost'] * metadata['fees'])
80
81 con_uwarriors_lst001.transfer_from(price_amount_pay, item[owner], sender)
82 con_uwarriors_lst001.transfer_from((item['cost'] * metadata['fees']), metadata['operator'], sender)
83
84 thing_master_contract = I.import_module(item['contract'])
85 thing_master_contract.transfer(
86 uid=uid,
87 to=item[to],
88 main_account=ctx.this,
89 contract=item['item_contract'])
90
91 balances[uid, 'item'] = ''
92 balances[uid] == False
93
94
95 @export
96 def nitro_send_free(contract: str, item_contract: str, uid: str, to: str):
97 sender = ctx.caller
98 thing_master_owner = I.import_module(item_contract)
99 owner = thing_master_owner.get_owner(uid)
100
101 assert wp[sender] >= metadata['nitro_cost'] , 'Not enough coins to send!'
102 assert owner == sender , 'Not Owner'
103
104 con_uwarriors_lst001.transfer_from(metadata['nitro_cost'], metadata['operator'], sender)
105 metadata['nitro_cost'] += metadata['demand_cost']
106
107 if (now - metadata['delivery']).minutes >= metadata['time']:
108 metadata['nitro_cost'] = metadata['nitro_cost_init']
109
110 metadata['delivery'] = now
111
112 thing_master_contract = I.import_module(contract)
113 thing_master_contract.transfer_from(
114 uid=uid,
115 to=to,
116 main_account=ctx.caller,
117 contract=item_contract)
118
119 @export
120 def change_metadata(key: str, value: Any):
121 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
122 metadata[key] = value
123
124
125 @export
126 def operator_transfer_thing(uid: str, new_owner: str, contract: str, item_contract: str):
127 assert ctx.caller == metadata['operator'], 'Only auction operator can transfer things from contract.'
128 thing_master_contract = I.import_module(contract)
129 thing_master_contract.transfer(uid=uid, new_owner=new_owner, contract=item_contract)
130 S[uid] = False
131
132
133 @export
134 def operator_transfer_currency(amount: str, to: float):
135 assert ctx.caller == metadata['operator'], 'Only auction operator can transfer currency from contract.'
136 con_uwarriors_lst001.transfer(amount=amount, to=to)
137

Byte Code

e30000000000000000000000000700000040000000730c010000640064016c005a00640064016c015a0165025a03650464016402640364048d035a05650464006402640564048d035a06650464006402640664048d035a076508640764066402640864098d045a09640a640b84005a0a650b64028301650c650c650c650c650d640c9c05640d640e840483015a0e650b64028301650c640f9c0164106411840483015a0f650b64028301650c640f9c0164126413840483015a10650b64028301650c650c650c650c64149c0464156416840483015a11650b64028301650c651264179c0264186419840483015a13650b64028301650c650c650c650c641a9c04641b641c840483015a14650b64028301650c650d641d9c02641e641f840483015a15640153002920e9000000004eda0f636f6e5f75775f64656c6976657279da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461da0862616c616e636573da14636f6e5f7577617272696f72735f6c7374303031da0277702904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572050000007206000000630000000000000000000000000300000043000000735200000074006a01740264013c006402740264033c006404740264053c00740364068301740264073c006402740264083c006404740264093c00640a7402640b3c0064027402640c3c0074047402640d3c0064005300290e4eda086f70657261746f72e978000000da0a6e6974726f5f636f7374e950000000da0e6e6974726f5f636f73745f7061797a04302e3135da0466656573da0f6e6974726f5f636f73745f696e6974da136e6974726f5f636f73745f696e69745f706179e90a000000da0b64656d616e645f636f7374da0474696d65da0864656c69766572792905da03637478da0663616c6c6572da0a5f5f6d65746164617461da07646563696d616cda036e6f77a900721e000000721e000000da00da045f5f5f5f0b000000731200000000010a01080108010c010801080108010801722000000029057205000000da0d6974656d5f636f6e7472616374da03756964da02746fda04636f7374630500000000000000090000000c0000004300000073ea00000074006a017d0574026a037c0183017d067c066a047c0283017d0774057c0519007406640119007c0417006b05733674076402830182017c077c056b027346740764038301820174086a097406640119007406640419007c05830301007406640105001900740664051900370003003c00740a74066406190018006a0b7406640719006b057292740664081900740664013c00740a740664063c0074026a037c0083017d087c086a097c0274006a0c74006a017c0164098d040100640a740d7c023c007c077c077c007c007c017c017c027c027c037c037c047c046906740d7c02640b66023c0064005300290c4e72110000007a194e6f7420656e6f75676820636f696e7320746f2073656e64217a094e6f74204f776e6572720d0000007216000000721800000072170000007214000000290472220000007223000000da0c6d61696e5f6163636f756e74720500000054da046974656d290e7219000000721a000000da0149da0d696d706f72745f6d6f64756c65da096765745f6f776e6572da045f5f7770721b000000da0e417373657274696f6e4572726f727209000000da0d7472616e736665725f66726f6d721d000000da076d696e75746573da0474686973da0a5f5f62616c616e636573290972050000007221000000722200000072230000007224000000da0673656e646572da127468696e675f6d61737465725f6f776e6572da056f776e6572da157468696e675f6d61737465725f636f6e7472616374721e000000721e000000721f000000da0f6e6974726f5f73656e645f636f7374170000007324000000000306010a010a010c01100110010a010c01140116010c0108010a010a010c0108010801723400000029017222000000630100000000000000040000000600000043000000736800000074006a017d0174027c006401660219007d0274027c00190064026b027326740364038301820174046a057c026404190083017d037c036a067c007c026405190074006a077c026406190064078d040100640874027c00640166023c00640974027c003c0064005300290a4e7226000000547a094e6f74204f776e657272050000007232000000722100000029047222000000722300000072250000007205000000721f0000004629087219000000721a000000722f000000722b00000072270000007228000000da087472616e73666572722e00000029047222000000723000000072260000007233000000721e000000721e000000721f000000da116e6974726f5f73656e645f63616e63656c2e0000007310000000000206010c0114010e010c0110010c01723600000063010000000000000005000000060000004300000073e000000074006a017d0174027c006401660219007d0274037c0119007c02640219006b05732a740464038301820174027c00190064046b02733e74046405830182017c02740519007c016b02735274046406830182017c02640219007c0264021900740664071900140018007d0374076a087c037c02740919007c018303010074076a087c026402190074066407190014007406640819007c0183030100740a6a0b7c026409190083017d047c046a0c7c007c027405190074006a0d7c02640a1900640b8d040100640c74027c00640166023c0074027c001900640d6b02010064005300290e4e722600000072240000007a194e6f7420656e6f75676820636f696e7320746f2073656e6421547a084e6f742053656e647a154e6f742064656c69766572792072656365697665727212000000720d0000007205000000722100000029047222000000722300000072250000007205000000721f00000046290e7219000000721a000000722f000000722a000000722b0000007223000000721b0000007209000000722c0000007232000000722700000072280000007235000000722e0000002905722200000072300000007226000000da1070726963655f616d6f756e745f7061797233000000721e000000721e000000721f000000da126e6974726f5f73656e645f636f6e6669726d3a000000731c000000000206010c011801140114011801120112010c010e0110010c010c0172380000002904720500000072210000007222000000722300000063040000000000000008000000060000004300000073b800000074006a017d0474026a037c0183017d057c056a047c0283017d0674057c0419007406640119006b05733274076402830182017c067c046b027342740764038301820174086a097406640119007406640419007c04830301007406640105001900740664051900370003003c00740a74066406190018006a0b7406640719006b05728e740664081900740664013c00740a740664063c0074026a037c0083017d077c076a097c027c0374006a017c0164098d04010064005300290a4e720f0000007a194e6f7420656e6f75676820636f696e7320746f2073656e64217a094e6f74204f776e6572720d000000721600000072180000007217000000721300000029047222000000722300000072250000007205000000290c7219000000721a000000722700000072280000007229000000722a000000721b000000722b0000007209000000722c000000721d000000722d000000290872050000007221000000722200000072230000007230000000723100000072320000007233000000721e000000721e000000721f000000da0f6e6974726f5f73656e645f667265654c000000731e000000000206010a010a011201060110010c010a01140116010c0108010a010c0172390000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e720d0000007a1f4f6e6c79206f70657261746f722063616e20736574206d657461646174612129047219000000721a000000721b000000722b0000002902723a000000723b000000721e000000721e000000721f000000da0f6368616e67655f6d657461646174615f0000007306000000000210010601723c00000029047222000000da096e65775f6f776e657272050000007221000000630400000000000000050000000500000043000000733c00000074006a017402640119006b027316740364028301820174046a057c0283017d047c046a067c007c017c0364038d030100640474077c003c006400530029054e720d0000007a384f6e6c792061756374696f6e206f70657261746f722063616e207472616e73666572207468696e67732066726f6d20636f6e74726163742e29037222000000723d00000072050000004629087219000000721a000000721b000000722b000000722700000072280000007235000000da035f5f5329057222000000723d000000720500000072210000007233000000721e000000721e000000721f000000da176f70657261746f725f7472616e736665725f7468696e6766000000730c0000000003100106010a0108010801723f0000002902da06616d6f756e747223000000630200000000000000020000000400000043000000732800000074006a017402640119006b027316740364028301820174046a057c007c0164038d0201006400530029044e720d0000007a3a4f6e6c792061756374696f6e206f70657261746f722063616e207472616e736665722063757272656e63792066726f6d20636f6e74726163742e29027240000000722300000029067219000000721a000000721b000000722b00000072090000007235000000290272400000007223000000721e000000721e000000721f000000da1a6f70657261746f725f7472616e736665725f63757272656e637971000000730600000000021001060172410000002916da0863757272656e63797209000000da09696d706f72746c69627227000000da0448617368723e000000721b000000722f000000da0b466f726569676e48617368722a0000007220000000da085f5f6578706f7274da03737472da05666c6f61747234000000723600000072380000007239000000da03416e79723c000000723f0000007241000000721e000000721e000000721e000000721f000000da083c6d6f64756c653e0100000073300000000801080104010e010e010e0104010c03080c0601080110150601100b0601101106011612060112060601060110090601