From 460f4cd6dbf4381870132c14d3ea69e3a312cee0 Mon Sep 17 00:00:00 2001 From: Alex Step Date: Mon, 13 Nov 2017 15:45:41 +0200 Subject: [PATCH] clean and bugfix --- src/model/DApps/DApp.js | 2 +- src/model/DApps/DApps.js | 3 ++ src/model/DApps/approve.js | 89 ------------------------------------ src/model/DApps/messaging.js | 53 --------------------- 4 files changed, 4 insertions(+), 143 deletions(-) delete mode 100644 src/model/DApps/approve.js delete mode 100644 src/model/DApps/messaging.js diff --git a/src/model/DApps/DApp.js b/src/model/DApps/DApp.js index 24a965d..c9390e7 100644 --- a/src/model/DApps/DApp.js +++ b/src/model/DApps/DApp.js @@ -348,7 +348,7 @@ export default class DApp { if (receipt.transactionHash) { // Set deposit in logic - this.users[params.user_id].logic.payChannel.setDeposit( player_deposit ) + this.users[params.user_id].logic.payChannel.setDeposit( Utils.bet2dec(player_deposit) ) } this.response(params, { receipt:receipt }, response_room) diff --git a/src/model/DApps/DApps.js b/src/model/DApps/DApps.js index a98acbb..c570130 100644 --- a/src/model/DApps/DApps.js +++ b/src/model/DApps/DApps.js @@ -162,6 +162,9 @@ class _DCLib { raw_msg = Utils.remove0x(raw_msg) return ( need_address.toLowerCase() == this.web3.eth.accounts.recover(raw_msg, signed_msg).toLowerCase() ) } + checkHashSig(raw_msg, signed_msg, need_address){ + return ( need_address.toLowerCase() == this.web3.eth.accounts.recover(raw_msg, signed_msg).toLowerCase() ) + } } diff --git a/src/model/DApps/approve.js b/src/model/DApps/approve.js deleted file mode 100644 index 4a4b176..0000000 --- a/src/model/DApps/approve.js +++ /dev/null @@ -1,89 +0,0 @@ -import _config from 'app.config' -import Eth from 'Eth/Eth' - - -export default class ApproveContract { - // Проверяем разрешил ли игрок списывать бэты контракту - constructor(address, callback){ - this.getAllowance(address, allowance_bets =>{ - // console.log('allowance_bets',allowance_bets) - if (allowance_bets < 1000000) { - this.approveContract(address, 2000000, ()=>{ - this.setGameContract(address, callback) - return - }) - return - } - - // all ok - callback() - }) - } - - // Проверяем сколько денег разрешено списывать контракту игры - getAllowance(address, callback){ - if (!address) { - return - } - - Eth.RPC.request('call', [{ - 'from' : Eth.Wallet.get().openkey, - 'to' : _config.erc20_address, - 'data' : '0x'+Eth.hashName('allowance(address,address)') + Utils.pad(Eth.Wallet.get().openkey.substr(2), 64) + Utils.pad(address.substr(2), 64) - }, 'latest']).then( response => { - callback( Utils.hexToNum(response.result) ) - }) - } - - // Разрешаем контракту игры списывать с нас бэты - approveContract(address, max_bets, callback, repeat=3){ - - if (!confirm(`Allow the game ${this.code} / ${address} to write off with your money?`)) { - return - } - - this.transactContractFunction( - _config.erc20_address, _config.erc20_abi, - - 'approve', [address, max_bets*100000000], - - 0, - - response => { - if (!response || !response.result) { - setTimeout(()=>{ - console.log('repeat approveContract') - repeat-- - if (repeat < 1) { - callback({error:'Cant_approve_contract'}) - return - } - this.approveContract(address, max_bets, callback, repeat) - }, 3000) - return - } - - const checkResult = ()=>{ setTimeout( ()=>{ - this.getAllowance(address, res => { - if (res >= max_bets*100000000) { - callback( res ) - return - } - checkResult() - }) - }, 2000) } - - checkResult() - } - ) - } - - transactContractFunction(address, abi, func_name, func_params, value=0, callback){ - Eth.Wallet.signedContractFuncTx( - address, abi, func_name, func_params, - signedTx => { - Eth.RPC.request('sendRawTransaction', ['0x' + signedTx]).then( callback ) - } - ) - } -} \ No newline at end of file diff --git a/src/model/DApps/messaging.js b/src/model/DApps/messaging.js deleted file mode 100644 index 23e3b46..0000000 --- a/src/model/DApps/messaging.js +++ /dev/null @@ -1,53 +0,0 @@ -import Eth from 'Eth/Eth' -import Rtc from 'rtc' -import * as Utils from '../utils' - -export default class Messaging { - constructor(params) { - this.dapp_code = params.code - this.dapp_hash = Utils.sha3( params.code ) - this.contract = params.contract - - // common dapp room - this.Room = new Rtc( (Eth.Wallet.get().openkey || false) , 'rtc_room_'+this.dapp_code ) - - this.iamActive() - - this.subscribes = {} - this.Room.subscribe(this.dapp_hash, data => { - if (!data || - !data.action || - !data.dapp_code || - data.dapp_code != this.dapp_code - ) { return } - - if (this.subscribes[data.action]) { - this.subscribes[data.action].forEach( func =>{ - func(data) - }) - } - }) - } - - on(action, callback){ - if (!this.subscribes[action]) { - this.subscribes[action] = [] - } - this.subscribes[action].push( callback ) - } - - iamActive(){ - Eth.getBetsBalance( Eth.Wallet.get().openkey , bets=>{ - this.Room.sendMsg({ - action : 'bankroller_active', - dapp_code : this.dapp_code, - address : this.dapp_hash, - deposit : bets*100000000 - }) - - setTimeout(()=>{ - this.iamActive() - }, 2000) - }) - } -} \ No newline at end of file