Contract con_dejury_2403


Contract Code


  
1 """
2 dejury
3 Ask anything, and get paid to answer.
4
5 Summary
6 ----------------
7 1. Ask a question and set a bounty
8 2. Answer
9 3. Asker chose your answer? congras, you get all the TAU.
10
11 Contract design
12 ----------------
13 1. post:
14 a. add to list of questions - poster and bounty
15 b. add bounty to contract balance
16 2. answer:
17 a. add to list of answers - poster and question ID
18 3. award: choose the winning answer based on answer ID
19 a. check if bounty already given?
20 a. send TAU to poster's address
21 b. mark bounty given
22 """
23 import currency
24 __posts = Hash(default_value='', contract='con_dejury_2403', name='posts')
25 __answers = Hash(default_value='', contract='con_dejury_2403', name='answers')
26 __balances = ForeignHash(foreign_contract='currency', foreign_name=
27 'balances', contract='con_dejury_2403', name='balances')
28
29
30 @__export('con_dejury_2403')
31 def post(title: str, content: str, bounty: int, email: str):
32 sender = ctx.caller
33 assert not __posts[sender, title
34 ], 'There is already an existing post with this title'
35 assert content, 'A question must not be empty.'
36 assert email, 'The email must not be empty.'
37 assert bounty > 0, 'Bounty must be bigger than zero.'
38 __transfer(from_=sender, to=ctx.this, amount=bounty)
39 __posts[sender, title, 'content'] = content
40 __posts[sender, title, 'bounty'] = bounty
41 __posts[sender, title, 'email'] = email
42
43
44 @__export('con_dejury_2403')
45 def answer(title: str, content: str, owner: str):
46 sender = ctx.caller
47 assert content, 'An answer must not be empty.'
48 assert __posts[owner, title, 'bounty'
49 ], 'This question does not exist or already answered.'
50 assert not __answers[sender, title
51 ], 'You have already posted an answer for this question.'
52 __answers[sender, title] = content
53
54
55 @__export('con_dejury_2403')
56 def award(title: str, winner: str):
57 answer = __answers[winner, title]
58 bounty = __posts[ctx.caller, title, 'bounty']
59 assert __posts[ctx.caller, title, 'content'], 'Post not found.'
60 assert bounty, 'Bounty has already been given for this post.'
61 assert answer, 'This answer does not exist.'
62 assert winner != ctx.caller, 'You can not award yourself.'
63 __transfer(to=winner, amount=bounty)
64 __posts[ctx.caller, title, 'bounty'] = 0
65
66
67 def __transfer(to: str, amount: int, from_: str=None):
68 if from_:
69 currency.transfer_from(amount, to, from_)
70 else:
71 currency.transfer(amount, to)
72

Byte Code

e30000000000000000000000000600000040000000739e00000064005a00640164026c015a01650264036404640564068d035a03650264036404640764068d035a0465056408640964046409640a8d045a066507640483016508650865096508640b9c04640c640d840483015a0a650764048301650865086508640e9c03640f6410840483015a0b6507640483016508650864119c0264126413840483015a0c641765086509650864149c036415641684055a0d64025300291861100200000a64656a7572790a41736b20616e797468696e672c20616e6420676574207061696420746f20616e737765722e0a0a53756d6d6172790a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0a312e2041736b2061207175657374696f6e20616e6420736574206120626f756e74790a322e20416e737765720a332e2041736b65722063686f736520796f757220616e737765723f20636f6e677261732c20796f752067657420616c6c20746865205441552e0a0a436f6e74726163742064657369676e0a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d0a312e20706f73743a0a20202020612e2061646420746f206c697374206f66207175657374696f6e73202d20706f7374657220616e6420626f756e74790a20202020622e2061646420626f756e747920746f20636f6e74726163742062616c616e63650a322e20616e737765723a0a20202020612e2061646420746f206c697374206f6620616e7377657273202d20706f7374657220616e64207175657374696f6e2049440a332e2061776172643a2063686f6f7365207468652077696e6e696e6720616e73776572206261736564206f6e20616e737765722049440a20202020612e20636865636b20696620626f756e747920616c726561647920676976656e3f0a20202020612e2073656e642054415520746f20706f73746572277320616464726573730a20202020622e206d61726b20626f756e747920676976656e0ae9000000004eda00da0f636f6e5f64656a7572795f32343033da05706f7374732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da07616e7377657273da0863757272656e6379da0862616c616e6365732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65720600000072070000002904da057469746c65da07636f6e74656e74da06626f756e7479da05656d61696c630400000000000000050000000500000043000000738200000074006a017d0474027c047c00660219000c00731c74036401830182017c01732874036402830182017c03733474036403830182017c0264046b047344740364058301820174047c0474006a057c0264068d0301007c0174027c047c00640766033c007c0274027c047c00640866033c007c0374027c047c00640966033c0064005300290a4e7a31546865726520697320616c726561647920616e206578697374696e6720706f737420776974682074686973207469746c657a1d41207175657374696f6e206d757374206e6f7420626520656d7074792e7a1c54686520656d61696c206d757374206e6f7420626520656d7074792e72010000007a20426f756e7479206d75737420626520626967676572207468616e207a65726f2e2903da0566726f6d5fda02746fda06616d6f756e74720e000000720f00000072100000002906da03637478da0663616c6c6572da075f5f706f737473da0e417373657274696f6e4572726f72da0a5f5f7472616e73666572da04746869732905720d000000720e000000720f0000007210000000da0673656e646572a900721b0000007202000000da04706f73741e000000731400000000020601100106010c010c01100110010e010e01721c0000002903720d000000720e000000da056f776e6572630300000000000000040000000400000043000000734e00000074006a017d037c017312740264018301820174037c027c006402660319007328740264038301820174047c037c00660219000c00733e74026404830182017c0174047c037c0066023c006400530029054e7a1c416e20616e73776572206d757374206e6f7420626520656d7074792e720f0000007a3154686973207175657374696f6e20646f6573206e6f74206578697374206f7220616c726561647920616e7377657265642e7a34596f75206861766520616c726561647920706f7374656420616e20616e7377657220666f722074686973207175657374696f6e2e29057214000000721500000072170000007216000000da095f5f616e73776572732904720d000000720e000000721d000000721a000000721b000000721b0000007202000000da06616e737765722c000000730e000000000206010c011001060110010601721f0000002902720d000000da0677696e6e6572630200000000000000040000000500000043000000737e00000074007c017c00660219007d02740174026a037c006401660319007d03740174026a037c00640266031900733474046403830182017c03734074046404830182017c02734c74046405830182017c0174026a036b03735e740464068301820174057c017c0364078d0201006408740174026a037c00640166033c006400530029094e720f000000720e0000007a0f506f7374206e6f7420666f756e642e7a2c426f756e74792068617320616c7265616479206265656e20676976656e20666f72207468697320706f73742e7a1b5468697320616e7377657220646f6573206e6f742065786973742e7a1b596f752063616e206e6f7420617761726420796f757273656c662e29027212000000721300000072010000002906721e000000721600000072140000007215000000721700000072180000002904720d0000007220000000721f000000720f000000721b000000721b0000007202000000da05617761726437000000731000000000020c01100118010c010c0112010c017221000000290372120000007213000000721100000063030000000000000003000000040000004300000073240000007c02721474006a017c017c007c02830301006e0c74006a027c017c00830201006400530029014e29037209000000da0d7472616e736665725f66726f6dda087472616e736665722903721200000072130000007211000000721b000000721b00000072020000007218000000430000007306000000000104011002721800000029014e290eda075f5f646f635f5f7209000000da04486173687216000000721e000000da0b466f726569676e48617368da0a5f5f62616c616e636573da085f5f6578706f7274da03737472da03696e74721c000000721f00000072210000007218000000721b000000721b000000721b0000007202000000da083c6d6f64756c653e160000007318000000040108010e010e0104010c030601160d0601140a0601120b