Comparing version 0.1.17 to 0.1.18
{ | ||
"name": "eth-lib", | ||
"version": "0.1.17", | ||
"version": "0.1.18", | ||
"description": "Lightweight Ethereum libraries", | ||
@@ -32,6 +32,5 @@ "main": "src/index.js", | ||
"nano-json-stream-parser": "^0.1.2", | ||
"reqwest": "^2.0.5", | ||
"ws": "^3.0.0", | ||
"xhr2": "^0.1.4" | ||
"xhr-request-promise": "^0.1.2" | ||
} | ||
} |
@@ -11,2 +11,18 @@ const Api = provider => { | ||
// TODO check inputs | ||
// TODO move to proper file | ||
const encodeABI = (type, value) => { | ||
if (type === "bytes") { | ||
const length = Bytes.length(value); | ||
const nextMul32 = (((length - 1) / 32 | 0) + 1) * 32; | ||
const lengthEncoded = encodeABI("uint256", Nat.fromNumber(length)); | ||
const bytesEncoded = Bytes.padRight(nextMul32, value); | ||
return Bytes.concat(lengthEncoded, bytesEncoded); | ||
} else if (type === "uint256") { | ||
return Bytes.pad(32, value); | ||
} else { | ||
throw "Eth-lib can't encode ABI type " + type + " yet."; | ||
} | ||
} | ||
const sendTransaction = send("eth_sendTransaction"); | ||
@@ -50,3 +66,5 @@ const sendRawTransaction = send("eth_sendRawTransaction"); | ||
const methodSig = method.name + "(" + method.inputs.map(i => i.type).join(",") + ")"; | ||
return Bytes.concat(keccak256s(methodSig).slice(0,10), Bytes.flatten(params)); | ||
const methodHash = keccak256s(methodSig).slice(0,10); | ||
const encodedParams = params.map((param,i) => encodeABI(method.inputs[i].type, param)); | ||
return Bytes.concat(methodHash, Bytes.flatten(encodedParams)); | ||
} | ||
@@ -62,3 +80,3 @@ | ||
if (method && method.name) { | ||
const call = (waitReceipt, value) => (...params) => { | ||
const call = (type, value) => (...params) => { | ||
const transaction = { | ||
@@ -68,14 +86,17 @@ from: from, | ||
value: value, | ||
data: callMethodData(method)(...params.map(p => Bytes.pad(32,p))) | ||
data: callMethodData(method)(...params) | ||
}; | ||
return method.constant | ||
? callWithDefaults(transaction) | ||
: sendTransactionWithDefaults(transaction) | ||
.then(waitReceipt ? waitTransactionReceipt : (x => x)); | ||
return type === "data" | ||
? Promise.resolve(transaction) | ||
: method.constant | ||
? callWithDefaults(transaction) | ||
: sendTransactionWithDefaults(transaction) | ||
.then(type === "receipt" ? waitTransactionReceipt : (x => x)); | ||
}; | ||
contract[method.name] = call(true, "0x0"); | ||
contract[method.name] = call("receipt", "0x0"); | ||
if (!method.constant) { | ||
contract[method.name+"_pay"] = value => (...params) => call(true, value)(...params); | ||
contract[method.name+"_pay_txHash"] = value => (...params) => call(false, value)(...params); | ||
contract[method.name+"_txHash"] = call(false, "0x0"); | ||
contract[method.name+"_data"] = call("data", "0x0"); | ||
contract[method.name+"_pay"] = value => (...params) => call("receipt", value)(...params); | ||
contract[method.name+"_pay_txHash"] = value => (...params) => call("txHash", value)(...params); | ||
contract[method.name+"_txHash"] = call("txHash", "0x0"); | ||
} | ||
@@ -82,0 +103,0 @@ } |
@@ -64,2 +64,7 @@ const A = require("./array.js"); | ||
const padRight = (l,hex) => | ||
hex.length === l*2+2 ? hex : padRight(l,hex+"0"); | ||
console.log(padRight(32, "0x123456")); | ||
const fromNat = bn => | ||
@@ -78,2 +83,3 @@ bn === "0x0" ? "0x" : bn.length % 2 === 0 ? bn : "0x0" + bn.slice(2); | ||
pad, | ||
padRight, | ||
fromAscii, | ||
@@ -80,0 +86,0 @@ toAscii, |
const njsp = require("nano-json-stream-parser"); | ||
const rw = require("reqwest"); | ||
const request = require("xhr-request-promise"); | ||
@@ -61,8 +61,8 @@ const EthereumProvider = (url, intercept) => { | ||
api.send = makeSender((method, params, callback) => { | ||
rw({ | ||
url: url, | ||
method: "post", | ||
request(url, { | ||
method: "POST", | ||
contentType: "application/json-rpc", | ||
data: JSON.stringify(genPayload(method,params))}) | ||
.then(resp => { | ||
body: JSON.stringify(genPayload(method,params))}) | ||
.then(answer => { | ||
var resp = JSON.parse(answer); | ||
if (resp.error) { | ||
@@ -69,0 +69,0 @@ callback(resp.error.message); |
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
45517
5
21
1231
+ Addedxhr-request-promise@^0.1.2
+ Addedbuffer-to-arraybuffer@0.0.5(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addeddom-walk@0.1.2(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedis-function@1.0.2(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedparse-headers@2.0.5(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedquery-string@5.1.1(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@2.8.2(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
+ Addedtimed-out@4.0.1(transitive)
+ Addedurl-set-query@1.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxhr@2.6.0(transitive)
+ Addedxhr-request@1.1.0(transitive)
+ Addedxhr-request-promise@0.1.3(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedreqwest@^2.0.5
- Removedxhr2@^0.1.4
- Removedreqwest@2.0.5(transitive)
- Removedxhr2@0.1.4(transitive)