SHARE
TWEET

Untitled

a guest Jun 27th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# STDLIB_VERSION 3 #-}
  2. {-# CONTENT_TYPE DAPP #-}
  3. {-# SCRIPT_TYPE ACCOUNT #-}
  4.  
  5. let NONE = "none"
  6. func getNumberByKey(key: String) = {
  7.     let num = match getInteger(this, key) {
  8.             case a:Int => a
  9.             case _ => 0
  10.     }
  11.     num
  12. }
  13. func getStrByKey(key: String) = {
  14.     let str = match getString(this, key) {
  15.             case a:String => a
  16.             case _ => NONE
  17.     }
  18.     str
  19. }
  20. func getKeyWhitelistRef(account: String) = {
  21.     "wl_ref_" + account
  22. }
  23. func getKeyWhitelistStatus(account: String) = {
  24.     "wl_sts_" + account
  25. }
  26. func getKeyBalance(account: String) = {
  27.     "balance_" + account
  28. }
  29. func getKeyWhitelistBio(account: String) = {
  30.     "wl_bio_" + account
  31. }
  32. func getKeyWhitelistBlock(account: String) = {
  33.     "wl_blk_" + account
  34. }
  35. func getKeyItemAuthor(item: String) = {
  36.     "author_" + item
  37. }
  38. func getKeyItemBlock(item: String) = {
  39.     "block_" + item
  40. }
  41. func getKeyItemVotingExpiration(item: String) = {
  42.     "expiration_block_" + item
  43. }
  44. func getKeyItemBank(item: String) = {
  45.     "bank_" + item
  46. }
  47. func getKeyItemStatus(item: String) = {
  48.     "status_" + item
  49. }
  50. func getKeyItemData(item: String) = {
  51.     "datajson_" + item
  52. }
  53. func getKeyItemCrowdExpiration(item: String) = {
  54.     "expiration_one_" + item
  55. }
  56. func getKeyItemWhaleExpiration(item: String) = {
  57.     "expiration_two_" + item
  58. }
  59. func getKeyItemNCommits(item: String) = {
  60.     "ncommits_" + item
  61. }
  62. func getKeyItemAccCommit(item: String, account: String) = {
  63.     "commit_" + item + "_" + account
  64. }
  65. func getKeyItemAccReveal(item: String, account: String) = {
  66.     "reveal_" + item + "_" + account
  67. }
  68. func getKeyItemVotesYes(item: String) = {
  69.     "cnt_yes_" + item
  70. }
  71. func getKeyItemVotesNo(item: String) = {
  72.     "cnt_no_" + item
  73. }
  74. func getKeyItemAccFinal(item: String, account: String) = {
  75.     "final_" + item + "_" + account
  76. }
  77. func getKeyItemFundPositive(item: String) = {
  78.     "positive_fund_" + item
  79. }
  80. func getKeyItemFundNegative(item: String) = {
  81.     "negative_fund_" + item
  82. }
  83. func getKeyItemAccFundPositive(item: String, account: String) = {
  84.     getKeyItemFundPositive(item) + "_" + account
  85. }
  86. func getKeyItemAccFundNegative(item: String, account: String) = {
  87.     getKeyItemFundNegative(item) + "_" + account
  88. }
  89. func getKeyItemAccReviewsCnt(item: String, account: String) = {
  90.     "reviews_cnt_" + item + "_" + account
  91. }
  92. func getKeyItemAccReview(item: String, account: String) = {
  93.     "review_" + item + "_" + account
  94. }
  95. func getKeyItemAccReviewText(item: String, account: String, cnt: String) = {
  96.     getKeyItemAccReview(item, account) + "_text_id:" + cnt
  97. }
  98. func getKeyItemAccReviewMode(item: String, account: String, cnt: String) = {
  99.     getKeyItemAccReview(item, account) + "_mode_id:" + cnt
  100. }
  101. func getKeyItemAccReviewTier(item: String, account: String, cnt: String) = {
  102.     getKeyItemAccReview(item, account) + "_tier_id:" + cnt
  103. }
  104. func getKeyItemAccVoteReviewText(item: String, account: String) = {
  105.     getKeyItemAccReview(item, account) + "_votereview"
  106. }
  107. func getKeyItemAccWhaleReviewText(item: String, account: String) = {
  108.     getKeyItemAccReview(item, account) + "_whalereview"
  109. }
  110. func getKeyItemBuyoutAmount(item: String) = {
  111.     "buyout_amount_" + item
  112. }
  113. func getKeyItemAccWinnings(item: String, account: String) = {
  114.     "winnings_" + item + "_" + account
  115. }
  116.  
  117. func getValueWhitelistRef(account: String) = {
  118.     getStrByKey(getKeyWhitelistRef(account))
  119. }
  120. func getValueWhitelistStatus(account: String) = {
  121.     getStrByKey(getKeyWhitelistStatus(account))
  122. }
  123. func getValueBalance(account: String) = {
  124.     getNumberByKey(getKeyBalance(account))
  125. }
  126. func getValueWhitelistBio(account: String) = {
  127.     getStrByKey(getKeyWhitelistBio(account))
  128. }
  129. func getValueWhitelistBlock(account: String) = {
  130.     getStrByKey(getKeyWhitelistBlock(account))
  131. }
  132. func getValueItemAuthor(item: String) = {
  133.     getStrByKey(getKeyItemAuthor(item))
  134. }
  135. func getValueItemBlock(item: String) = {
  136.     getNumberByKey(getKeyItemBlock(item))
  137. }
  138. func getValueItemVotingExpiration(item: String) = {
  139.     getNumberByKey(getKeyItemVotingExpiration(item))
  140. }
  141. func getValueItemBank(item: String) = {
  142.     getNumberByKey(getKeyItemBank(item))
  143. }
  144. func getValueItemStatus(item: String) = {
  145.     getStrByKey(getKeyItemStatus(item))
  146. }
  147. func getValueItemData(item: String) = {
  148.     getStrByKey(getKeyItemData(item))
  149. }
  150. func getValueItemCrowdExpiration(item: String) = {
  151.     getNumberByKey(getKeyItemCrowdExpiration(item))
  152. }
  153. func getValueItemWhaleExpiration(item: String) = {
  154.     getNumberByKey(getKeyItemWhaleExpiration(item))
  155. }
  156. func getValueItemNCommits(item: String) = {
  157.     getNumberByKey(getKeyItemNCommits(item))
  158. }
  159. func getValueItemAccCommit(item: String, account: String) = {
  160.     getStrByKey(getKeyItemAccCommit(item, account))
  161. }
  162. func getValueItemAccReveal(item: String, account: String) = {
  163.     getStrByKey(getKeyItemAccReveal(item, account))
  164. }
  165. func getValueItemVotesYes(item: String) = {
  166.     getNumberByKey(getKeyItemVotesYes(item))
  167. }
  168. func getValueItemVotesNo(item: String) = {
  169.     getNumberByKey(getKeyItemVotesNo(item))
  170. }
  171. func getValueItemAccFinal(item: String, account: String) = {
  172.     getStrByKey(getKeyItemAccFinal(item, account))
  173. }
  174. func getValueItemFundPositive(item: String) = {
  175.     getNumberByKey(getKeyItemFundPositive(item))
  176. }
  177. func getValueItemFundNegative(item: String) = {
  178.     getNumberByKey(getKeyItemFundNegative(item))
  179. }
  180. func getValueItemAccFundPositive(item: String, account: String) = {
  181.     getNumberByKey(getKeyItemAccFundPositive(item, account))
  182. }
  183. func getValueItemAccFundNegative(item: String, account: String) = {
  184.     getNumberByKey(getKeyItemAccFundNegative(item, account))
  185. }
  186. func getValueItemAccReviewsCnt(item: String, account: String) = {
  187.     getNumberByKey(getKeyItemAccReviewsCnt(item, account))
  188. }
  189. func getValueItemAccReviewText(item: String, account: String, cnt: String) = {
  190.     getStrByKey(getKeyItemAccReviewText(item, account, cnt))
  191. }
  192. func getValueItemAccReviewMode(item: String, account: String, cnt: String) = {
  193.     getStrByKey(getKeyItemAccReviewMode(item, account, cnt))
  194. }
  195. func getValueItemAccReviewTier(item: String, account: String, cnt: String) = {
  196.     getNumberByKey(getKeyItemAccReviewTier(item, account, cnt))
  197. }
  198. func getValueItemBuyoutAmount(item: String) = {
  199.     getNumberByKey(getKeyItemBuyoutAmount(item))
  200. }
  201. func getValueItemAccWinnings(item: String, account: String) = {
  202.     getNumberByKey(getKeyItemAccWinnings(item, account))
  203. }
  204.  
  205. let WHITELISTED = "registered"
  206. let INVITED = "invited"
  207. let WHALE = "whale"
  208.  
  209. let NEW = "new"
  210. let COMMIT = "voting_commit"
  211. let REVEAL = "voting_reveal"
  212. let FEATURED = "featured"
  213. let DELISTED = "delisted"
  214. let CASHOUT = "cashout"
  215. let BUYOUT = "buyout"
  216. let FINISHED = "finished"
  217. let CLAIMED = "claimed"
  218.  
  219. let POSITIVE = "positive"
  220. let NEGATIVE = "negative"
  221.  
  222. let GENESIS = "3NBB3iv7YDRsD8ZM2Pw2V5eTcsfqh3j2mvF"
  223.  
  224. # (GLOBALS) TCR implementation with commit-reveal scheme
  225. let VOTERS = 3
  226. let QUORUM = 2
  227. let LISTINGFEE = 500000000/1000
  228. let VOTEBET = 150000000/1000
  229.  
  230. let TIERS = [10, 50, 250, 1250, 6250]
  231. let MULTIPLIER = 150
  232.  
  233. @Callable(i)
  234. func inviteuser(newaccount: String, data: String) = {
  235.     let account = toBase58String(i.caller.bytes)
  236.     if (getValueWhitelistRef(newaccount) != NONE)
  237.         then throw("User has already been invited")
  238.     else if (getKeyWhitelistStatus(account) != WHITELISTED && account != GENESIS)
  239.         then throw("Your account should be whitelisted")
  240.     else {
  241.         WriteSet([
  242.             DataEntry(getKeyWhitelistRef(newaccount), account),
  243.             DataEntry(getKeyWhitelistBio(newaccount), data),
  244.             DataEntry(getKeyWhitelistStatus(newaccount), INVITED)
  245.         ])
  246.     }
  247. }
  248. @Callable(i)
  249. func signup(data: String, type: String) = {
  250.     let account = toBase58String(i.caller.bytes)
  251.     if (getValueWhitelistStatus(account) != INVITED && GENESIS != account)
  252.         then throw("Referral invite needed")
  253.     else {
  254.         WriteSet([
  255.             DataEntry(getKeyWhitelistBio(account), data),
  256.             DataEntry(getKeyWhitelistBlock(account), height),
  257.             DataEntry(getKeyWhitelistStatus(account), if (type == WHALE) then WHALE else WHITELISTED)
  258.         ])
  259.     }
  260. }
  261. @Callable(i)
  262. func userupdate(data: String, type: String) = {
  263.     let account = toBase58String(i.caller.bytes)
  264.     WriteSet([
  265.         DataEntry(getKeyWhitelistBio(account), data),
  266.         DataEntry(getKeyWhitelistStatus(account), if (type == WHALE) then WHALE else WHITELISTED)
  267.     ])
  268. }
  269. @Callable(i)
  270. func projupdate(item: String, data: String) = {
  271.     let account = toBase58String(i.caller.bytes)
  272.     if (getValueItemAuthor(item) != account) then throw("You're not author")
  273.     else {
  274.         WriteSet([DataEntry(getKeyItemData(item), data)])
  275.     }
  276. }
  277.  
  278. @Callable(i)
  279. func withdraw() = {
  280.     let currentKey = toBase58String(i.caller.bytes)
  281.     let amount = getValueBalance(currentKey)
  282.     if (amount <= 0) then throw("Not enough balance")
  283.     else ScriptResult(
  284.         WriteSet([ DataEntry(getKeyBalance(currentKey), 0)]),
  285.         TransferSet([ScriptTransfer(i.caller, amount, unit)])
  286.     )
  287. }
  288. @Callable(i)
  289. func additem(item: String, expVoting: Int, expCrowd: Int, expWhale: Int, data: String) = {
  290.     let account = toBase58String(i.caller.bytes)
  291.     let pmt = extract(i.payment)
  292.     if (isDefined(pmt.assetId)) then throw("can use waves only at the moment")
  293.     else {
  294.         if (pmt.amount != LISTINGFEE)
  295.             then throw("Please pay exact amount for the listing")
  296.         else if (expVoting > 2 && expCrowd > 3 && expWhale > 4)
  297.             then throw("Incorrect time parameters")
  298.         else if (getValueItemAuthor(item) != NONE)
  299.             then throw("Item already exist")
  300.         else WriteSet([
  301.             DataEntry(getKeyItemAuthor(item), account),
  302.             DataEntry(getKeyItemBlock(item), height),
  303.             DataEntry(getKeyItemVotingExpiration(item), height + expVoting),
  304.             DataEntry(getKeyItemBank(item), LISTINGFEE),
  305.             DataEntry(getKeyItemStatus(item), NEW),
  306.             DataEntry(getKeyItemData(item), data),
  307.             DataEntry(getKeyItemCrowdExpiration(item), height + expCrowd),
  308.             DataEntry(getKeyItemWhaleExpiration(item), height + expWhale)
  309.         ])
  310.     }
  311. }
  312. @Callable(i)
  313. func votecommit(item: String, hash: String) = {
  314.     let account = toBase58String(i.caller.bytes)
  315.     let commits = getValueItemNCommits(item)
  316.     let status = getValueItemStatus(item)
  317.     let pmt = extract(i.payment)
  318.     if (isDefined(pmt.assetId)) then throw("can use waves only at the moment")
  319.     else {
  320.         if (pmt.amount != 2*VOTEBET)
  321.             then throw("Not enough funds to vote for a new item")
  322.         else if (height > getValueItemVotingExpiration(item))
  323.             then throw("The voting has expired")
  324.         else if (getValueItemAuthor(item) == account)
  325.             then throw("Cannot vote for own proposal")
  326.         else if (status != NEW && status != COMMIT)
  327.             then throw("Wrong item status for 'commit' action")
  328.         else if (commits >= VOTERS)
  329.             then throw("No more voters for this item")
  330.         else if (getValueItemAccCommit(item, account) != NONE)
  331.             then throw("Can't vote twice")
  332.         else WriteSet([
  333.             DataEntry(getKeyItemStatus(item), if ( commits + 1 == VOTERS ) then REVEAL else COMMIT),
  334.             DataEntry(getKeyItemAccCommit(item, account), hash),
  335.             DataEntry(getKeyItemNCommits(item), commits + 1)
  336.         ])
  337.     }
  338. }
  339. @Callable(i)
  340. func votereveal(item: String, vote: String, salt: String, review: String) = {
  341.     let ridehash = toBase58String(sha256(toBytes(vote + salt)))
  342.     let account = toBase58String(i.caller.bytes)
  343.     let yesmltp = if(vote == FEATURED) then 1 else 0
  344.     let notmltp = if(vote == DELISTED) then 1 else 0
  345.     let yescnt = getValueItemVotesYes(item)
  346.     let notcnt = getValueItemVotesNo(item)
  347.     let newstatus = if ( yescnt >= QUORUM ) then FEATURED else
  348.         (if ( notcnt >= QUORUM ) then DELISTED else REVEAL)
  349.     if (getValueItemAccCommit(item, account) != ridehash)
  350.         then throw("Hashes don't match")
  351.     else if (height > getValueItemVotingExpiration(item))
  352.         then throw("The challenge has expired")
  353.     else if (getValueItemNCommits(item) < VOTERS)
  354.         then throw("It's still commit stage")
  355.     else if (getValueItemStatus(item) != REVEAL && getValueItemStatus(item) != newstatus)
  356.         then throw("Wrong item status for 'reveal' action")
  357.     else if (getValueItemAccReveal(item, account) != NONE)
  358.         then throw("Can't vote twice")
  359.     else if (vote != FEATURED && vote != DELISTED)
  360.         then throw("Bad vote result format")
  361.     else WriteSet([
  362.             DataEntry(getKeyItemAccReveal(item, account), vote),
  363.             DataEntry(getKeyItemVotesYes(item), yescnt + yesmltp),
  364.             DataEntry(getKeyItemVotesNo(item), notcnt + notmltp),
  365.             DataEntry(getKeyItemStatus(item), newstatus),
  366.             DataEntry(getKeyItemAccVoteReviewText(item, account), review),
  367.             DataEntry(getKeyBalance(account), getValueBalance(account) + VOTEBET)
  368.         ])
  369. }
  370.  
  371. @Callable(i)
  372. func finalizevoting(item: String, account: String) = {
  373.     let yescnt = getValueItemVotesYes(item)
  374.     let notcnt = getValueItemVotesNo(item)
  375.     let accvote = getValueItemAccReveal(item, account)
  376.     let isauthor = account == getValueItemAuthor(item)
  377.     let finalstatus = if ( yescnt > QUORUM ) then FEATURED else
  378.         (if ( notcnt > QUORUM ) then DELISTED else NONE)
  379.     let mltisnotfullmajority = if (yescnt == VOTERS || notcnt == VOTERS) then 0 else 1
  380.     let nwinners = if ( finalstatus == FEATURED ) then yescnt else
  381.         (if ( finalstatus == DELISTED ) then notcnt else 0)
  382.     let nloosers = VOTERS - nwinners
  383.     let mltacciswinner = if (finalstatus == accvote) then 1 else 0
  384.     let voteprofit = if (nwinners == 0) then 0 else
  385.         mltacciswinner*(VOTEBET +
  386.             mltisnotfullmajority*(nloosers*VOTEBET + LISTINGFEE)/nwinners)
  387.     let authorreturn = LISTINGFEE*(if(isauthor) then 1 else 0)*
  388.         (if (mltisnotfullmajority == 1) then 0 else 1)*(if(finalstatus == FEATURED) then 1 else 0)
  389.     if (height < getValueItemVotingExpiration(item))
  390.         then throw("The voting hasn't finished yet")
  391.     else if (getValueItemAccFinal(item, account) == FINISHED)
  392.         then throw("Account has already claimed")
  393.     else if (accvote == NONE && !isauthor)
  394.         then throw("Account hasnot voted, hasnot reveal or isnot author")
  395.     else if (finalstatus == NONE)
  396.         then throw("Voting has expired")
  397.     else WriteSet([
  398.         DataEntry(getKeyItemAccFinal(item, account), FINISHED),
  399.         DataEntry(getKeyBalance(account), getValueBalance(account) + voteprofit + authorreturn)
  400.     ])
  401. }
  402.  
  403. @Callable(i)
  404. func closeexpiredvoting(item: String, account: String) = {
  405.     let finalstatus = if ( getValueItemVotesYes(item) > QUORUM ) then FEATURED else
  406.         (if ( getValueItemVotesNo(item) > QUORUM ) then DELISTED else NONE)
  407.     let accvote = getValueItemAccReveal(item, account)
  408.     let isauthor = account == getValueItemAuthor(item)
  409.     let acccomi = getValueItemAccCommit(item, account)
  410.     let hasrevealstage = getValueItemNCommits(item) == VOTERS
  411.     let authorreturn = LISTINGFEE*(if(isauthor) then 1 else 0)
  412.     let votersreturn1 = VOTEBET*(if(hasrevealstage) then 1 else 0)*
  413.         (if (accvote != NONE) then 1 else 0)
  414.     let votersreturn2 = 2*VOTEBET*(if(hasrevealstage) then 0 else 1)*
  415.         (if (acccomi != NONE) then 1 else 0)
  416.     if (height < getValueItemVotingExpiration(item))
  417.         then throw("The voting hasn't finished yet")
  418.     else if (!isauthor && acccomi == NONE)
  419.         then throw("Wrong account or item")
  420.     else if (getValueItemAccFinal(item, account) == FINISHED)
  421.         then throw("Account has already claimed")
  422.     else if (finalstatus != NONE)
  423.         then throw("Wrong item status")
  424.     else WriteSet([
  425.         DataEntry(getKeyItemAccFinal(item, account), FINISHED),
  426.         DataEntry(getKeyBalance(account), getValueBalance(account) +
  427.             authorreturn + votersreturn1 + votersreturn2)
  428.     ])
  429. }
  430.  
  431. @Callable(i)
  432. func donate( item: String, tier: Int, mode: String, review: String ) = {
  433.     let account = toBase58String(i.caller.bytes)
  434.     let pmt = extract(i.payment)
  435.     if (isDefined(pmt.assetId)) then throw("can use waves only at the moment")
  436.     else {
  437.         let cnt = getValueItemAccReviewsCnt(item, account) + 1
  438.         let newnegativefund = getValueItemFundNegative(item) +
  439.                     ( if ( mode == NEGATIVE ) then 1 else 0) * pmt.amount
  440.         let newpositivefund = getValueItemFundPositive(item) +
  441.                     ( if ( mode == POSITIVE ) then 1 else 0) * pmt.amount
  442.         if (getValueItemStatus(item) != FEATURED)
  443.             then throw("The project hasn't accepted by community")
  444.         else if (height >= getValueItemCrowdExpiration(item))
  445.             then throw("The time for crowdfunding has expired")
  446.         else if (newnegativefund >= newpositivefund)
  447.             then throw("Negative fund can't be higher than positive fund")
  448.         else if (mode != POSITIVE && mode != NEGATIVE)
  449.             then throw("Wrong mode parameter")
  450.         else if (getValueItemAuthor(item) == account)
  451.             then throw("Can't donate own project")
  452.         else if (pmt.amount != TIERS[tier - 1])
  453.             then throw("The payment must be equal to tier amount: " + toString(TIERS[tier - 1]))
  454.         else WriteSet([
  455.             DataEntry(getKeyItemAccReviewsCnt(item, account), cnt),
  456.             DataEntry(getKeyItemAccFundPositive(item, account),
  457.                 getValueItemAccFundPositive(item, account) +
  458.                     ( if ( mode == POSITIVE ) then 1 else 0) * pmt.amount ),
  459.             DataEntry(getKeyItemAccFundNegative(item, account),
  460.                 getValueItemAccFundNegative(item, account) +
  461.                     ( if ( mode == NEGATIVE ) then 1 else 0) * pmt.amount ),
  462.             DataEntry(getKeyItemFundPositive(item), newpositivefund),
  463.             DataEntry(getKeyItemFundNegative(item), newnegativefund),
  464.             DataEntry(getKeyItemAccReviewText(item, account, toString(cnt)), review),
  465.             DataEntry(getKeyItemAccReviewMode(item, account, toString(cnt)), mode),
  466.             DataEntry(getKeyItemAccReviewTier(item, account, toString(cnt)), tier)
  467.         ])
  468.     }
  469. }
  470.  
  471. @Callable(i)
  472. func whale( item: String, review: String ) = {
  473.     let account = toBase58String(i.caller.bytes)
  474.     let pmt = extract(i.payment)
  475.     if (isDefined(pmt.assetId)) then throw("can use waves only at the moment")
  476.     else {
  477.         if (getValueItemStatus(item) != FEATURED)
  478.             then throw("The project hasn't accepted by community")
  479.         else if (height < getValueItemCrowdExpiration(item))
  480.             then throw("The time for crowdfunding has not expired yet")
  481.         else if (height > getValueItemWhaleExpiration(item))
  482.             then throw("The time for grant has expired")
  483.         else if (getValueItemStatus(item) == BUYOUT)
  484.             then throw("Investement has already done")
  485.         else if (pmt.amount < (getValueItemFundPositive(item)*MULTIPLIER)/100)
  486.             then throw("Investement must be more than "
  487.             + toString(MULTIPLIER) + "% of supportes funds")
  488.         else WriteSet([
  489.             DataEntry(getKeyItemStatus(item), BUYOUT),
  490.             DataEntry(getKeyItemAccWhaleReviewText(item, account), review),
  491.             DataEntry(getKeyBalance(getValueItemAuthor(item)),
  492.                 getValueBalance(getValueItemAuthor(item)) + getValueItemFundPositive(item)),
  493.             DataEntry(getKeyItemBuyoutAmount(item), pmt.amount)
  494.         ])
  495.     }
  496. }
  497.  
  498. @Callable(i)
  499. func claimwinnings( item: String, account: String ) = {
  500.     let status = getValueItemStatus(item)
  501.     let isbayout = if (status == BUYOUT) then 1 else 0
  502.     let iscrowdf = if (status != BUYOUT) then 1 else 0
  503.     let positivefund = getValueItemFundPositive(item)
  504.     let negativefund = getValueItemFundNegative(item)
  505.     let share = isbayout*(getValueItemAccFundPositive(item, account)*100)/
  506.             (if (positivefund <= 0) then 1 else positivefund) +
  507.         iscrowdf*(getValueItemAccFundNegative(item, account)*100)/
  508.             (if (negativefund <= 0) then 1 else negativefund)
  509.     let tmpnegwin = (negativefund*MULTIPLIER)/100
  510.     let betprofit = isbayout*((share*negativefund)/100) +
  511.         iscrowdf*((share*(if (tmpnegwin < positivefund) then tmpnegwin else positivefund))/100)
  512.     let roiprofit = isbayout*((share*getValueItemBuyoutAmount(item))/100)
  513.     let authorprofit = (if (getValueItemAuthor(item) == account) then 1 else 0)*
  514.         positivefund*(if (status != BUYOUT) then 1 else 0)
  515.     if (status == DELISTED)
  516.         then throw("The project hasn't accepted by community")
  517.     else if (status != BUYOUT && height <= getValueItemWhaleExpiration(item))
  518.         then throw("The time for grant has not expired yet")
  519.     else if (positivefund + negativefund <= 0)
  520.         then throw("The campaign wasn't active")
  521.     else WriteSet([
  522.         DataEntry(getKeyBalance(account), getValueBalance(account) +
  523.             betprofit + roiprofit + authorprofit),
  524.         DataEntry(getKeyItemStatus(item), if (authorprofit > 0) then CASHOUT else status),
  525.         DataEntry(getKeyItemAccFinal(item, account), CLAIMED)
  526.     ])
  527. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top