Contract con_uw_auction_season1


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
8 @construct
9 def seed():
10 metadata['operator'] = ctx.caller
11 metadata['fees'] = decimal('0.15')
12
13 @export
14 def change_metadata(key: str, value: Any):
15 assert ctx.caller == metadata['operator'], 'Only auction operator can set metadata!'
16 metadata[key] = value
17
18 @export
19 def operator_transfer_thing(uid: str, new_owner: str, contract: str, item_contract: str):
20 assert ctx.caller == metadata['operator'], 'Only auction operator can transfer things from contract.'
21 thing_master_contract = I.import_module(contract)
22 thing_master_contract.transfer(uid=uid, new_owner=new_owner, contract=item_contract)
23 S[uid] = False
24
25 @export
26 def operator_transfer_currency(amount: str, to: float):
27 assert ctx.caller == metadata['operator'], 'Only auction operator can transfer currency from contract.'
28 con_uwarriors_lst001.transfer(amount=amount, to=to)
29
30 def get_listing_info(uid: str):
31
32 listing_info = S[uid]
33 assert listing_info is not None, "Listing doesn't exist!"
34 return {
35 'start_date': S[uid, 'start_date'],
36 'end_date': S[uid, 'end_date'],
37 'current_owner': S[uid, 'current_owner'],
38 'uid': S[uid, 'uid'],
39 'reserve_price': S[uid, 'reserve_price'],
40 'current_bid': S[uid, 'current_bid'],
41 'current_winner': S[uid, 'current_winner'],
42 }
43
44 @export
45 def auction_thing(contract: str, item_contract: str, uid: str, reserve_price: float, start_date: datetime.datetime, end_date: datetime.datetime):
46
47 thing_master_contract = I.import_module(contract)
48 thing_master_contract.transfer_from(
49 uid=uid,
50 to=ctx.this,
51 main_account=ctx.caller,
52 contract=item_contract
53 )
54
55 assert not S[uid], 'Auction has already started!'
56 assert end_date > now, "end_date is in the past"
57 assert reserve_price >= 0, "reserve_price cannot be less than 0"
58
59 S[uid, 'start_date'] = start_date
60 S[uid, 'end_date'] = end_date
61 S[uid, 'current_owner'] = ctx.caller
62 S[uid, 'uid'] = uid
63 S[uid, 'reserve_price'] = reserve_price
64 S[uid, 'current_bid'] = None
65 S[uid, 'current_winner'] = ""
66
67 S[uid] = True
68
69 @export
70 def end_auction(uid: str, contract: str, item_contract: str):
71 listing_info = get_listing_info(uid=uid)
72
73 assert now > listing_info['end_date'], 'Auction is still pending!'
74 if listing_info['current_bid'] == None or listing_info['current_bid'] < listing_info['reserve_price']:
75 process_auction_result_no_winner(listing_info, contract, item_contract)
76 return listing_info['current_owner']
77 else:
78 process_auction_result(listing_info, contract, item_contract)
79 return listing_info['current_winner']
80
81 def process_auction_result_no_winner(listing_info, contract, item_contract):
82 thing_master_contract = I.import_module(contract)
83
84 # Send thing back to owner
85 thing_master_contract.transfer(
86 uid=listing_info['uid'],
87 new_owner=listing_info['current_owner'],
88 contract=item_contract
89 )
90
91 if listing_info['current_winner'] != "":
92 con_uwarriors_lst001.transfer(
93 to=listing_info['current_winner'],
94 amount=listing_info['current_bid']
95 )
96
97 S[listing_info['uid']] = False
98
99 def process_auction_result(listing_info, contract, item_contract):
100 thing_master_contract = I.import_module(contract)
101
102
103 thing_master_contract.transfer(
104 uid=listing_info['uid'],
105 new_owner=listing_info['current_winner'],
106 contract=item_contract
107 )
108
109 net_amount = listing_info['current_bid'] - (listing_info['current_bid'] * metadata['fees'])
110
111 con_uwarriors_lst001.transfer(
112 to=listing_info['current_owner'],
113 amount=net_amount
114 )
115
116 S[listing_info['uid']] = False
117
118 @export
119 def bid(uid: str, bid_amount: float):
120 listing_info = get_listing_info(uid=uid)
121
122 current_bid = listing_info['current_bid'] or 0
123
124 assert now < listing_info['end_date'], "Auction has ended."
125 assert now > listing_info['start_date'], "Auction has not stared."
126 assert bid_amount > 0 , "Bid must be greater than zero."
127 assert bid_amount >= listing_info['reserve_price'], "Initial reserve is higher!"
128 assert bid_amount > current_bid, f"Current bid of {current_bid} is higher!"
129
130 con_uwarriors_lst001.transfer_from(
131 main_account=ctx.caller,
132 to=ctx.this,
133 amount=bid_amount,
134 )
135
136 if listing_info['current_winner'] != "":
137 con_uwarriors_lst001.transfer(
138 to=listing_info['current_winner'],
139 amount=listing_info['current_bid']
140 )
141
142 S[uid, 'current_bid'] = bid_amount
143 S[uid, 'current_winner'] = ctx.caller

Byte Code

e3000000000000000000000000080000004000000073fc000000640064016c005a00640064016c015a0165025a03650464016402640364048d035a05650464006402640564048d035a066406640784005a076508640283016509650a64089c026409640a840483015a0b6508640283016509650965096509640b9c04640c640d840483015a0c6508640283016509650d640e9c02640f6410840483015a0e650964119c016412641384045a0f650864028301650965096509650d65106a1065106a1064149c0664156416840483015a1165086402830165096509650964179c0364186419840483015a12641a641b84005a13641c641d84005a146508640283016509650d641e9c02641f6420840483015a15640153002921e9000000004eda16636f6e5f75775f61756374696f6e5f736561736f6e31da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da086d65746164617461630000000000000000000000000300000043000000731a00000074006a01740264013c00740364028301740264033c006400530029044eda086f70657261746f727a04302e3135da04666565732904da03637478da0663616c6c6572da0a5f5f6d65746164617461da07646563696d616ca900720e000000720e000000da00da045f5f5f5f09000000730400000000010a0172100000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e72080000007a274f6e6c792061756374696f6e206f70657261746f722063616e20736574206d65746164617461212904720a000000720b000000720c000000da0e417373657274696f6e4572726f72290272110000007212000000720e000000720e000000720f000000da0f6368616e67655f6d657461646174610e000000730600000000021001060172140000002904da03756964da096e65775f6f776e65727205000000da0d6974656d5f636f6e7472616374630400000000000000050000000500000043000000733c00000074006a017402640119006b027316740364028301820174046a057c0283017d047c046a067c007c017c0364038d030100640474077c003c006400530029054e72080000007a384f6e6c792061756374696f6e206f70657261746f722063616e207472616e73666572207468696e67732066726f6d20636f6e74726163742e2903721500000072160000007205000000462908720a000000720b000000720c0000007213000000da0149da0d696d706f72745f6d6f64756c65da087472616e73666572da035f5f5329057215000000721600000072050000007217000000da157468696e675f6d61737465725f636f6e7472616374720e000000720e000000720f000000da176f70657261746f725f7472616e736665725f7468696e6715000000730c0000000003100106010a0108010801721d0000002902da06616d6f756e74da02746f630200000000000000020000000400000043000000732800000074006a017402640119006b027316740364028301820174046a057c007c0164038d0201006400530029044e72080000007a3a4f6e6c792061756374696f6e206f70657261746f722063616e207472616e736665722063757272656e63792066726f6d20636f6e74726163742e2902721e000000721f0000002906720a000000720b000000720c0000007213000000da14636f6e5f7577617272696f72735f6c7374303031721a0000002902721e000000721f000000720e000000720e000000720f000000da1a6f70657261746f725f7472616e736665725f63757272656e6379200000007306000000000210010601722100000029017215000000630100000000000000020000000900000043000000736400000074007c0019007d017c0164006b097318740164018301820174007c0064026602190074007c0064036602190074007c0064046602190074007c0064056602190074007c0064066602190074007c0064076602190074007c0064086602190064099c075300290a4e7a164c697374696e6720646f65736e277420657869737421da0a73746172745f64617465da08656e645f64617465da0d63757272656e745f6f776e65727215000000da0d726573657276655f7072696365da0b63757272656e745f626964da0e63757272656e745f77696e6e6572290772220000007223000000722400000072150000007225000000722600000072270000002902721b000000721300000029027215000000da0c6c697374696e675f696e666f720e000000720e000000720f000000da125f5f6765745f6c697374696e675f696e666f27000000730e0000000001080110010e01120112010e017229000000290672050000007217000000721500000072250000007222000000722300000063060000000000000007000000060000004300000073b400000074006a017c0083017d067c066a027c0274036a0474036a057c0164018d04010074067c0219000c00733274076402830182017c0574086b04734274076403830182017c0364046b05735274076405830182017c0474067c02640666023c007c0574067c02640766023c0074036a0574067c02640866023c007c0274067c02640966023c007c0374067c02640a66023c00640074067c02640b66023c00640c74067c02640d66023c00640e74067c023c0064005300290f4e29047215000000721f000000da0c6d61696e5f6163636f756e7472050000007a1c41756374696f6e2068617320616c72656164792073746172746564217a17656e645f6461746520697320696e20746865207061737472010000007a23726573657276655f70726963652063616e6e6f74206265206c657373207468616e2030722200000072230000007224000000721500000072250000007226000000720f000000722700000054290972180000007219000000da0d7472616e736665725f66726f6d720a000000da0474686973720b000000721b0000007213000000da036e6f772907720500000072170000007215000000722500000072220000007223000000721c000000720e000000720e000000720f000000da0d61756374696f6e5f7468696e6731000000731c00000000040a010a010c011201100110010c010c010e010c010c010c010c01722e0000002903721500000072050000007217000000630300000000000000040000000400000043000000736600000074007c0064018d017d0374017c03640219006b04731e74026403830182017c036404190064006b02733a7c03640419007c03640519006b00724e74037c037c017c02830301007c0364061900530074047c037c017c02830301007c036407190053006400530029084e2901721500000072230000007a1941756374696f6e206973207374696c6c2070656e64696e6721722600000072250000007224000000722700000029057229000000722d0000007213000000da225f5f70726f636573735f61756374696f6e5f726573756c745f6e6f5f77696e6e6572da185f5f70726f636573735f61756374696f6e5f726573756c7429047215000000720500000072170000007228000000720e000000720e000000720f000000da0b656e645f61756374696f6e45000000731200000000020a01140112010a010601060108020c017231000000630300000000000000040000000500000043000000735400000074006a017c0183017d037c036a027c00640119007c00640219007c0264038d0301007c006404190064056b03724474036a027c00640419007c006406190064078d020100640874047c00640119003c006400530029094e7215000000722400000029037215000000721600000072050000007227000000720f00000072260000002902721f000000721e00000046290572180000007219000000721a0000007220000000721b0000002904722800000072050000007217000000721c000000720e000000720e000000720f000000722f00000053000000730e00000000010a010a010e010c010a010c01722f000000630300000000000000050000000500000043000000735c00000074006a017c0183017d037c036a027c00640119007c00640219007c0264038d0301007c00640419007c0064041900740364051900140018007d0474046a027c00640619007c0464078d020100640874057c00640119003c006400530029094e7215000000722700000029037215000000721600000072050000007226000000720900000072240000002902721f000000721e00000046290672180000007219000000721a000000720c0000007220000000721b0000002905722800000072050000007217000000721c000000da0a6e65745f616d6f756e74720e000000720e000000720f00000072300000005d000000731000000000010a010a010e010c010c010a010801723000000029027215000000da0a6269645f616d6f756e7463020000000000000004000000050000004300000073ce00000074007c0064018d017d027c0264021900701464037d0374017c02640419006b00732a740264058301820174017c02640619006b04733e74026407830182017c0164036b04734e74026408830182017c017c02640919006b0573627402640a830182017c017c036b04737a7402640b7c039b00640c9d038301820174036a0474056a0674056a077c01640d8d0301007c02640e1900640f6b0372b074036a087c02640e19007c026402190064108d0201007c0174097c00640266023c0074056a0674097c00640e66023c006400530029114e290172150000007226000000720100000072230000007a1241756374696f6e2068617320656e6465642e72220000007a1741756374696f6e20686173206e6f74207374617265642e7a1e426964206d7573742062652067726561746572207468616e207a65726f2e72250000007a1a496e697469616c207265736572766520697320686967686572217a0f43757272656e7420626964206f66207a0b20697320686967686572212903722a000000721f000000721e0000007227000000720f0000002902721f000000721e000000290a7229000000722d00000072130000007220000000722b000000720a000000720b000000722c000000721a000000721b00000029047215000000723300000072280000007226000000720e000000720e000000720f000000da0362696468000000731e00000000020a010c011401140110010e01060118010c0108010c010a010c010c0172340000002916da0863757272656e63797220000000da09696d706f72746c69627218000000da0448617368721b000000720c0000007210000000da085f5f6578706f7274da03737472da03416e797214000000721d000000da05666c6f617472210000007229000000da086461746574696d65722e0000007231000000722f00000072300000007234000000720e000000720e000000720e000000720f000000da083c6d6f64756c653e01000000732e0000000801080104010e0106010803080506011206060106011009060112060e0a0601060118120601140d080a080b0601