Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eth-lib

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eth-lib - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

package.json
{
"name": "eth-lib",
"version": "0.1.2",
"version": "0.1.3",
"description": "Lightweight Ethereum libraries",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -50,4 +50,4 @@ const Api = provider => {

// Address, Address, AbiDefinition -> Contract
const contract = (from, address, abiDefinition) => {
// Address, Address, ContractInterface -> Contract
const contract = (from, address, interface) => {
let contract = {};

@@ -57,3 +57,3 @@ contract._address = address;

contract.broadcast = {};
abiDefinition.forEach(method => {
interface.forEach(method => {
if (method && method.name) {

@@ -92,6 +92,6 @@ const call = (waitReceipt, value) => (...params) => {

// Address, Bytecode, AbiDefinition
const deployBytecodeContract = (from, code, abiDefinition) =>
// Address, Bytecode, ContractInterface
const deployBytecodeContract = (from, code, interface) =>
deployBytecode(from, code)
.then(receipt => contract(from, receipt.contractAddress, abiDefinition));
.then(receipt => contract(from, receipt.contractAddress, interface));

@@ -98,0 +98,0 @@ // Address, String, Address -> Contract

const njsp = require("nano-json-stream-parser");
const EthereumProvider = url => {
const EthereumProvider = (url, intercept) => {
let api = {};

@@ -8,3 +8,18 @@ let onResponse = {};

let nextId = 0;
let send;
const makeSender = send => {
const P = fn => (...args) => new Promise((resolve, reject) =>
fn(...args.concat((err,res) => err ? reject(err) : resolve(res))));
const sender = intercept => (method, params, callback) => {
const intercepted = intercept(method, params, P(sender(() => {})));
if (intercepted) {
intercepted.then(response => callback(null, response));
} else {
send(method, params, callback);
}
}
return sender(intercept);
};
const parseResponse = njsp(json => {

@@ -26,9 +41,14 @@ onResponse[json.id] && onResponse[json.id](null, json.result);

if (/^ws/.test(url)) {
const WebSocket = require("w"+"s");
const WebSocket = require("ws");
const ws = new WebSocket(url);
api.send = (method, params, callback) => {
const payload = genPayload(method, params);
onResponse[payload.id] = callback;
ws.send(JSON.stringify(payload));
}
api.send = makeSender((method, params, callback) => {
const intercepted = intercept(method, params, P(send(() => {})));
if (intercepted) {
intercepted.then(response => callback(null, response));
} else {
const payload = genPayload(method, params);
onResponse[payload.id] = callback;
ws.send(JSON.stringify(payload));
}
});
ws.on("message", parseResponse);

@@ -40,4 +60,3 @@ ws.on("open", () => callbacks.connect && callbacks.connect(eth));

const rw = require("reqwest");
api.send = (method, params, callback) => {
api.send = makeSender((method, params, callback) => {
rw({

@@ -56,3 +75,3 @@ url: url,

.catch(err => callback("Couldn't connect to Ethereum node."));
}
});

@@ -59,0 +78,0 @@ setTimeout(() => {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc