Comparing version 0.1.2 to 0.1.3
{ | ||
"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(() => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
48539
1166
2