Commit 1678b0e9 authored by aniket-engg's avatar aniket-engg Committed by Aniket

logsManager and txExecution

parent 2aa25bc4
const async = require('async')
const crypto = require('crypto')
import { eachOf } from 'async'
import { randomBytes } from 'crypto'
class LogsManager {
export class LogsManager {
notificationCallbacks
subscriptions
filters
filterTracking
oldLogs
constructor () {
this.notificationCallbacks = []
......@@ -12,7 +18,7 @@ class LogsManager {
}
checkBlock (blockNumber, block, web3) {
async.eachOf(block.transactions, (tx, i, next) => {
eachOf(block.transactions, (tx, i, next) => {
let txHash = '0x' + tx.hash().toString('hex')
web3.eth.getTransactionReceipt(txHash, (_error, receipt) => {
......@@ -97,7 +103,7 @@ class LogsManager {
}
subscribe (params) {
let subscriptionId = '0x' + crypto.randomBytes(16).toString('hex')
let subscriptionId = '0x' + randomBytes(16).toString('hex')
this.subscriptions[subscriptionId] = params
return subscriptionId
}
......@@ -107,7 +113,7 @@ class LogsManager {
}
newFilter (filterType, params) {
const filterId = '0x' + crypto.randomBytes(16).toString('hex')
const filterId = '0x' + randomBytes(16).toString('hex')
if (filterType === 'block' || filterType === 'pendingTransactions') {
this.filters[filterId] = { filterType }
}
......@@ -123,7 +129,7 @@ class LogsManager {
}
getLogsForFilter (filterId, logsOnly) {
const {filterType, params} = this.filter[filterId]
const {filterType, params} = this.filters[filterId]
const tracking = this.filterTracking[filterId]
if (logsOnly || filterType === 'filter') {
......@@ -161,5 +167,3 @@ class LogsManager {
}
}
module.exports = LogsManager
'use strict'
import { ethers } from 'ethers'
module.exports = {
/**
/**
* deploy the given contract
*
* @param {String} from - sender address
......@@ -16,7 +15,7 @@ module.exports = {
* [personal mode enabled, need password to continue] promptCb (okCb, cancelCb)
* @param {Function} finalCallback - last callback.
*/
createContract: function (from, data, value, gasLimit, txRunner, callbacks, finalCallback) {
export function createContract (from, data, value, gasLimit, txRunner, callbacks, finalCallback) {
if (!callbacks.confirmationCb || !callbacks.gasEstimationForceSend || !callbacks.promptCb) {
return finalCallback('all the callbacks must have been defined')
}
......@@ -25,9 +24,9 @@ module.exports = {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
finalCallback(error, txResult)
})
},
}
/**
/**
* call the current given contract ! that will create a transaction !
*
* @param {String} from - sender address
......@@ -42,22 +41,22 @@ module.exports = {
* [personal mode enabled, need password to continue] promptCb (okCb, cancelCb)
* @param {Function} finalCallback - last callback.
*/
callFunction: function (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) {
export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) {
const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' || funAbi.constant
const tx = { from, to, data, useCall, value, gasLimit }
txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
finalCallback(error, txResult)
})
},
}
/**
/**
* check if the vm has errored
*
* @param {Object} txResult - the value returned by the vm
* @return {Object} - { error: true/false, message: DOMNode }
*/
checkVMError: function (txResult) {
export function checkVMError (txResult) {
const errorCode = {
OUT_OF_GAS: 'out of gas',
STACK_UNDERFLOW: 'stack underflow',
......@@ -104,6 +103,6 @@ module.exports = {
}
ret.message = `${error}${exceptionError}${msg}\tDebug the transaction to get more information.`
return ret
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment