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

Commit

Permalink
fix inject payChannel in logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstep committed Nov 9, 2017
1 parent 1f011b7 commit 9c93dc9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 6 additions & 4 deletions DApps/TestDApp2/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
window.MyDApp2 = (function(){

const GameLogic = 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 = Utils.bet4dec(user_bet)
user_bet = DCLib.Utils.bet4dec(user_bet)

// generate random number
const random_num = DCLib.numFromHash(random_hash, 0, 65536)
Expand All @@ -21,8 +23,8 @@ window.MyDApp2 = (function(){
}

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

// push all data to our log
// just for debug
Expand All @@ -31,7 +33,7 @@ window.MyDApp2 = (function(){
user_bet : user_bet,
profit : profit,
user_num : user_num,
balance : this.payChannel.getBalance(),
balance : _self.payChannel.getBalance(),
random_hash : random_hash,
random_num : random_num,
}
Expand Down
19 changes: 14 additions & 5 deletions src/model/DApps/DApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import * as Utils from '../utils'

import paychannelLogic from './paychannel'

const payChannelWrap = function(logic){
let payChannel = new paychannelLogic()
logic.prototype.payChannel = payChannel
let modifiedLogic = new logic()
modifiedLogic.payChannel = payChannel
return modifiedLogic
}



const Account = Eth.Wallet
const _openkey = Account.get().openkey
const web3 = Account.web3
Expand Down Expand Up @@ -150,14 +160,10 @@ export default class DApp {
this.users[user_id] = {
id : connection_id,
num : Object.keys(this.users).length,
logic : new this.logic,
logic : payChannelWrap(this.logic),
room : new Rtc( _openkey, this.hash+'_'+connection_id )
}

// inject payChannel in logic
this.users[user_id].logic.payChannel = new paychannelLogic()


const signMsg = async (rawMsg=false)=>{
if (!rawMsg) return ''

Expand Down Expand Up @@ -219,6 +225,9 @@ export default class DApp {
if (!data.func || !data.func.name || !data.func.args) return
if (!User.logic[data.func.name]) return

console.log('User.logic', User.logic)
console.log('User.logic.payChannel', User.logic.payChannel)

let args = await prepareArgs(data.func.args)
let returns = User.logic[data.func.name].apply(this, args)

Expand Down

0 comments on commit 9c93dc9

Please sign in to comment.