Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstep committed Dec 4, 2017
1 parent bc856b4 commit 67093a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 47 deletions.
9 changes: 3 additions & 6 deletions DApps/dicedapp_v2/bankroller.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

//(function(){
window.MyDApp_debug = (function(){
var myDApp = new DCLib.DApp({code : 'dicedapp_v2'})
window.MultDApp = (function(){
let DApp = new DCLib.DApp({code : 'multy_v2'})

// Banroller side code
// console.log(myDApp)

return myDApp
return DApp
})()

4 changes: 2 additions & 2 deletions DApps/dicedapp_v2/dapp.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "DiceDAppExample2",
"code" : "dicedapp_v2",
"name" : "multyplayerExample",
"code" : "multy_v2",

"index" : "./index.html",
"logic" : "./dapp_logic.js",
Expand Down
40 changes: 1 addition & 39 deletions DApps/dicedapp_v2/dapp_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,9 @@
* Define our DApp logic constructor,
* for use it in frontend and bankroller side
*/
DCLib.defineDAppLogic('dicedapp_v2', function(){
DCLib.defineDAppLogic('multy_v2', function(){
const _self = this

const MAX_RAND_NUM = 65536
const HOUSEEDGE = 0.02 // 2%

let history = []

var Roll = function(user_bet, user_num, random_hash){
// convert 1BET to 100000000
user_bet = DCLib.Utils.bet4dec(user_bet)

// generate random number
const random_num = DCLib.numFromHash(random_hash, 0, 65536)

let profit = -user_bet
// if user win
if (user_num >= random_num) {
profit = (user_bet * (MAX_RAND_NUM - MAX_RAND_NUM*HOUSEEDGE) / user_num) - user_bet
}

// add result to paychannel
_self.payChannel.addTX( profit )
_self.payChannel.printLog()

// push all data to our log
// just for debug
const roll_item = {
timestamp : new Date().getTime(),
user_bet : user_bet,
profit : profit,
user_num : user_num,
balance : _self.payChannel.getBalance(),
random_hash : random_hash,
random_num : random_num,
}
history.push(roll_item)

return roll_item
}

return {
roll : Roll,
history : history,
Expand Down

0 comments on commit 67093a9

Please sign in to comment.