Socket
Socket
Sign inDemoInstall

ethereum-web3-plus

Package Overview
Dependencies
5
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.6 to 0.2.7

17

event-watcher.js

@@ -54,2 +54,3 @@ //#########################################################################################

this.web3Filters = []; // an array of Filters being watched
this.historyToBlock = 0; // used to break the reading between history and watching
}

@@ -60,3 +61,3 @@

if(this.callback)
if(error) callback(error, null);
if(error) this.callback(error, null);
else {

@@ -76,7 +77,10 @@ log.isNew=this.isNew;

// callback must be function(Error, Log) Log is completed with contract, isNew, txSender, txTarget
EventSynchronizer.prototype.historyFromBloc = function(fromBlock, callback) {
EventSynchronizer.prototype.historyFromBlock = function(fromBlock, callback) {
if(this.events.length==0) if(callback) callback("No event registered!", null);
this.historyToBlock = this.events[0].instance._eth.blockNumber;
var toBlock = (+this.historyToBlock);
for(var i=0; i<this.events.length; i++) {
var ev=this.events[i];
var bound = {callback: callback, contractName: ev.contractName, isNew:false };
var F = ev.instance[ev.eventName](this.filters, {fromBlock:fromBlock, toBlock:'latest'});
var F = ev.instance[ev.eventName](this.filters, {fromBlock:fromBlock, toBlock:toBlock});
bound.filter=F; // add it to the bound object so that the stopWatching can be called in the callback

@@ -89,7 +93,10 @@ F.get( internalCallbackArray.bind(bound) );

EventSynchronizer.prototype.startWatching = function(callback) {
// create the filter from 'latest'
// create the filter from historyToBlock+1
if(this.events.length==0) if(callback) callback("No event registered!", null);
if(this.historyToBlock==0) this.historyToBlock = this.events[0].instance._eth.blockNumber;
var fromBlock = (+this.historyToBlock+1);
for(var i=0; i<this.events.length; i++) {
var ev=this.events[i];
var bound = {callback: callback, contractName: ev.contractName, isNew:true };
var F = ev.instance[ev.eventName](this.filters, {fromBlock:'latest', toBlock:'latest'});
var F = ev.instance[ev.eventName](this.filters, {fromBlock:fromBlock, toBlock:'latest'});
F.watch( internalCallbackUnitary.bind(bound) );

@@ -96,0 +103,0 @@ this.web3Filters.push( F);

@@ -12,3 +12,3 @@

if(!module.parent) {console.log("use require() to load this package"); return; }
var fs=require('fs');
var Web3 = module.parent.require('web3');

@@ -97,3 +97,3 @@ var EventSynchronizer = require("./event-watcher.js");

// returns the txHash to be watched with waitFor
Web3.prototype.newInstanceTx = function(){
Web3.prototype.newInstanceTxOld = function(){
var args=Array.prototype.slice.call(arguments);

@@ -112,3 +112,21 @@ var name=args.shift(); // extract the name and leave the rest

// Optimisation of the gas to be used.
Web3.prototype.newInstanceTx = function(){
var args=Array.prototype.slice.call(arguments);
var name=args.shift(); // extract the name and leave the rest
if(typeof this.solidityCompiler !== 'object') return null; // the compiler has not been created
var c = this.solidityCompiler.getContract(name);
if(!c) return null;
// add the ethereum attributes
args.push({ data:this.solidityCompiler.getCode(name) });//, gas:this.eth.getBlock('latest').gasLimit });
//console.log("args for new before gas", args);
var data=c.new.getData.apply(c, args);
var gas = this.eth.estimateGas({data:data});
//console.log("args for new", args);
// call the new function. there is no callback so the return value is the TxHash
var tx= this.eth.sendTransaction({data:data, gas:gas});
return tx;
}
Web3.prototype.instanceAt = function(name, address) {

@@ -121,3 +139,10 @@ if(typeof this.solidityCompiler !== 'object') return null; // the compiler has not been created

Web3.prototype.instanceLibrary = function(name) {
if(typeof this.solidityCompiler !== 'object') return null; // the compiler has not been created
if(!this.solidityCompiler.DeployedLib[name]) return null; // the library is not deployed
//console.log("instanceLibrary:", name, this.solidityCompiler.DeployedLib[name]);
return this.instanceAt(name, this.solidityCompiler.DeployedLib[name]);
}
var isArray = function (object) {

@@ -153,3 +178,2 @@ return object instanceof Array;

var BlockWatcher = function(web3, bindEnvironment) {

@@ -238,10 +262,11 @@ var self=this;

}
//self.saveState();
} // end if no error
});
this.start = function() {
if(this.filter) { this.filter.stopWatching(); this.filter=null; } // clear any previous watching and filter
if(!this.filter) this.filter = this.web3.eth.filter('latest');
this.filter.stopWatching();
console.log("Starting the block watcher");
this.filter.watch(this.newBlock);
//this.loadState();
}

@@ -252,5 +277,6 @@ this.stop = function() {

}
this.waitFor = function(txHash, gas, args, callback, options) {
this.tx_wait[txHash]={gas: gas, args: args, cb: callback,
startBlock:this.web3.eth.blockNumber,
startBlock: options.startBlock || this.web3.eth.blockNumber,
canonicalAfter: options.canonicalAfter || 0,

@@ -297,2 +323,4 @@ dropAfter:options.dropAfter || 99999999 };

var gas=tx.gas; // the requested max gas that will be compared to the gasUsed of the transaction receipt
if(tx.blockNumber) // if the transaction is already in a block, use it as a start point of watching.
options.startBlock = tx.blockNumber;

@@ -299,0 +327,0 @@ if(!this.blockWatcher) {;

{
"name": "ethereum-web3-plus",
"version": "0.2.6",
"version": "0.2.7",
"description": "Adds some simplifications to the web3 package such as compilation, instance creation, call sequencing, events readers",

@@ -18,3 +18,11 @@ "main": "index.js",

"web3": "^0.18.2"
}
},
"repository": {
"type": "git",
"url": "https://github.com/guenoledc/ethereum-web3-plus.git"
},
"bugs": {
"url": "https://github.com/guenoledc/ethereum-web3-plus/issues"
},
"homepage": "https://github.com/guenoledc/ethereum-web3-plus/my_package"
}

@@ -173,3 +173,3 @@ # Documentation page for ethereum-web3-plus

var es = web3.eventSynchronizer("EventGenerator.Happening", {index:[13,14], key:"Other"} );
es.historyFromBloc(63000, function(error, log) {
es.historyFromBlock(63000, function(error, log) {
web3.completeLog(log); // optional: additional function to complete the content of the log message (see below)

@@ -225,2 +225,8 @@ console.log("Log:",log); } );

## Change log
### v 0.2.7
-
- bug corrections
- change name of historyFromBlock
- control of a valid callback before calling
### v 0.2.6 and v 0.2.5

@@ -227,0 +233,0 @@ - Documentation corrections

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc