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

Commit

Permalink
DApp channel open
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstep committed Nov 8, 2017
1 parent b4fc2b6 commit 4a68e14
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 71 deletions.
101 changes: 55 additions & 46 deletions DApps/TestDApp2/client.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,67 @@

window.MyDApp2 = (function(){

return new DCLib.DApp({
code : 'test_v2',

logic : function(){
var balance = 0
var history = []
const GameLogic = function(){
var balance = 0
var deposit = 0
var profit = 0
var history = []

var setBalance = function(deposit){
balance = deposit*1
return balance
}
var setDeposit = function(d){
deposit = DCLib.Utils.bet4dec(d)
balance = d*1
return balance
}

var getBalance = function(){
return balance
}
var getDeposit = function(){ return DCLib.Utils.bet2dec(deposit) }
var getBalance = function(){ return DCLib.Utils.bet2dec(balance) }
var getProfit = function(){ return DCLib.Utils.bet2dec(profit) }

var Roll = function(user_bet, user_num, random_hash){
let profit = -user_bet

const random_num = DCLib.numFromHash(random_hash, 0, 65536)
console.log(random_num)

if (user_num > random_num) {
profit = (user_bet * (65536 - 1310) / user_num) - user_bet
}
if (user_num == random_num) {
profit = user_bet
}

balance += profit*1

const roll_item = {
timestamp : new Date().getTime(),
user_bet : user_bet,
profit : profit,
user_num : user_num,
balance : balance,
random_hash : random_hash,
random_num : random_num,
}

history.push(roll_item)

return roll_item
var Roll = function(user_bet, user_num, random_hash){
let i_profit = -user_bet

const random_num = DCLib.numFromHash(random_hash, 0, 65536)
console.log(random_num)

if (user_num > random_num) {
i_profit = (user_bet * (65536 - 1310) / user_num) - user_bet
}
if (user_num == random_num) {
i_profit = user_bet
}

return {
setBalance: setBalance,
getBalance: getBalance,
roll: Roll,
history: history,
profit += i_profit*1
balance = deposit + profit

const roll_item = {
timestamp : new Date().getTime(),
user_bet : user_bet,
profit : i_profit,
user_num : user_num,
balance : balance,
random_hash : random_hash,
random_num : random_num,
}

history.push(roll_item)

return roll_item
}

return {
__getProfit : getProfit,
setDeposit : setDeposit,
getDeposit : getDeposit,
getBalance : getBalance,

roll : Roll,
history : history,
}
}

return new DCLib.DApp({
code : 'test_v2',
logic : GameLogic,
})

})()
Expand Down
3 changes: 3 additions & 0 deletions src/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ module.exports = {
api_url: 'https://platform.dao.casino/api/',
confirm_timeout: 7000,

gasPrice : 40*1000000000,
gasLimit : 40*100000,

contracts: {
erc20 : require('./contracts/contracts/erc20.js'),
paychannel : require('./contracts/contracts/paychannel.js'),
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/contracts/paychannel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a68e14

Please sign in to comment.