|
1 | | -const net = require('net'); |
2 | | -const Web3 = require("web3"); |
3 | 1 | const Promise = require("bluebird"); |
4 | 2 | const BadRequestError = require('../libs/error').BadRequestError; |
5 | 3 | const config = require("../config/app-config"); |
6 | 4 | const log = require('./../libs/log')(module); |
7 | | -// const TransferService = require('./TransferService'); |
8 | 5 |
|
9 | | - |
10 | | -function getWeb3() { |
11 | | - const web3 = new Web3(new Web3.providers.IpcProvider(process.env['HOME'] + config.get("GETH_LOCATION"), net)); |
12 | | - Promise.promisifyAll(web3.eth, { suffix: "Promise" }); |
13 | | - Promise.promisifyAll(web3.personal, { suffix: "Promise" }); |
14 | | - return web3; |
15 | | -} |
16 | | - |
17 | | -const web3 = getWeb3(); |
18 | 6 | const CONTRACT_ABI = require("../contracts/e2pEscrow").abi; |
| 7 | +const web3 = require('../utils/web3'); |
| 8 | + |
| 9 | +// init contract |
19 | 10 | const CONTRACT_ADDRESS = config.get("ESCROW_CONTRACT_ADDRESS"); |
20 | 11 | const contractInstance = web3.eth.contract(CONTRACT_ABI).at(CONTRACT_ADDRESS); |
21 | | - |
22 | 12 | Promise.promisifyAll(contractInstance, { suffix: "Promise" }); |
23 | 13 |
|
24 | 14 |
|
25 | | -function subscribeForPendingEvents() { |
26 | | - // log.debug("Subscribing for pending events."); |
27 | | - //var options = {address: CONTRACT_ADDRESS, fromBlock: 'earliest', toBlock: 'earliest'}; |
28 | | - //var filter = web3.eth.filter(options); |
29 | | - var myEvent = contractInstance.LogDeposit({}, {fromBlock: 'pending', toBlock: 'pending'}); |
30 | | - |
31 | | - |
32 | | - myEvent.watch((error, tx) => { |
33 | | - // try { |
34 | | - // const tx = await web3.eth.getTransactionPromise(txHash); |
35 | | - // if (tx.to === CONTRACT_ADDRESS) { |
36 | | - log.debug("GOT PENDING EVENT: "); |
37 | | - log.debug(tx); |
38 | | - // } |
39 | | - // } catch(err) { |
40 | | - // log.debug(err); |
41 | | - // } |
42 | | - }); |
43 | | -} |
44 | | - |
45 | 15 | function* getByTransitAddress(transitAddress) { |
46 | 16 | function _parseTransfer(data) { |
47 | 17 | return { |
@@ -78,7 +48,7 @@ function* checkSignature(transitAddress, to, v, r, s) { |
78 | 48 | function* checkTransferStatusBeforeWithdraw(transitAddress) { |
79 | 49 | // transfer instance from blockchain |
80 | 50 | const transferBc = yield getByTransitAddress(transitAddress); |
81 | | - // log.debug({transferBc, transitAddress}); |
| 51 | + |
82 | 52 | // if no transfer in blockchain or no amount for transfer set |
83 | 53 | if (!(transferBc && transferBc.amount > 0)) { |
84 | 54 | throw new BadRequestError('No pending transfer found on blockchain!'); |
@@ -110,5 +80,4 @@ module.exports = { |
110 | 80 | checkSignature, |
111 | 81 | withdraw, |
112 | 82 | checkTransferStatusBeforeWithdraw, |
113 | | - subscribeForPendingEvents |
114 | 83 | } |
0 commit comments