From 9c93dc9dd790046b46a267b464795eec3374f72c Mon Sep 17 00:00:00 2001 From: Alex Step Date: Thu, 9 Nov 2017 15:00:26 +0200 Subject: [PATCH] fix inject payChannel in logic --- DApps/TestDApp2/client.js | 10 ++++++---- src/model/DApps/DApp.js | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/DApps/TestDApp2/client.js b/DApps/TestDApp2/client.js index c996d43..82fc79d 100644 --- a/DApps/TestDApp2/client.js +++ b/DApps/TestDApp2/client.js @@ -2,6 +2,8 @@ window.MyDApp2 = (function(){ const GameLogic = function(){ + const _self = this + const MAX_RAND_NUM = 65536 const HOUSEEDGE = 0.02 // 2% @@ -9,7 +11,7 @@ window.MyDApp2 = (function(){ 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) @@ -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 @@ -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, } diff --git a/src/model/DApps/DApp.js b/src/model/DApps/DApp.js index 92e0fd9..f3378cf 100644 --- a/src/model/DApps/DApp.js +++ b/src/model/DApps/DApp.js @@ -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 @@ -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 '' @@ -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)