@truffle/blockchain-utils
Advanced tools
Comparing version 0.0.19-alphaTez.0 to 0.0.19
"use strict"; | ||
require("source-map-support/register"); | ||
const Blockchain = { | ||
@@ -31,35 +32,39 @@ getBlockByNumber(blockNumber, provider, callback) { | ||
}, | ||
asURI(provider, callback) { | ||
let genesis, latest; | ||
this.getBlockByNumber("0x0", provider, (err, { result }) => { | ||
if (err) | ||
return callback(err); | ||
genesis = result; | ||
this.getBlockByNumber("latest", provider, (err, { result }) => { | ||
asURI(provider) { | ||
return new Promise((resolve, reject) => { | ||
let genesis, latest; | ||
this.getBlockByNumber("0x0", provider, (err, { result }) => { | ||
if (err) | ||
return callback(err); | ||
latest = result; | ||
const url = `blockchain://${genesis.hash.replace("0x", "")}/block/${latest.hash.replace("0x", "")}`; | ||
callback(null, url); | ||
return reject(err); | ||
genesis = result; | ||
this.getBlockByNumber("latest", provider, (err, { result }) => { | ||
if (err) | ||
return reject(err); | ||
latest = result; | ||
const url = `blockchain://${genesis.hash.replace("0x", "")}/block/${latest.hash.replace("0x", "")}`; | ||
resolve(url); | ||
}); | ||
}); | ||
}); | ||
}, | ||
matches(uri, provider, callback) { | ||
const parsedUri = this.parse(uri); | ||
const expected_genesis = parsedUri.genesis_hash; | ||
const expected_block = parsedUri.block_hash; | ||
this.getBlockByNumber("0x0", provider, (err, { result }) => { | ||
if (err) | ||
return callback(err); | ||
const block = result; | ||
if (block.hash !== expected_genesis) | ||
return callback(null, false); | ||
this.getBlockByHash(expected_block, provider, (err, { result }) => { | ||
// Treat an error as if the block didn't exist. This is because | ||
// some clients respond differently. | ||
matches(uri, provider) { | ||
return new Promise((resolve, reject) => { | ||
const parsedUri = this.parse(uri); | ||
const expected_genesis = parsedUri.genesis_hash; | ||
const expected_block = parsedUri.block_hash; | ||
this.getBlockByNumber("0x0", provider, (err, { result }) => { | ||
if (err) | ||
return reject(err); | ||
const block = result; | ||
if (err || block == null) { | ||
return callback(null, false); | ||
} | ||
callback(null, true); | ||
if (block.hash !== expected_genesis) | ||
return resolve(false); | ||
this.getBlockByHash(expected_block, provider, (err, { result }) => { | ||
// Treat an error as if the block didn't exist. This is because | ||
// some clients respond differently. | ||
const block = result; | ||
if (err || block == null) { | ||
return resolve(false); | ||
} | ||
resolve(true); | ||
}); | ||
}); | ||
@@ -66,0 +71,0 @@ }); |
103
index.ts
@@ -0,1 +1,2 @@ | ||
import "source-map-support/register"; | ||
import { Provider, Callback, JsonRPCResponse } from "web3/providers"; | ||
@@ -53,59 +54,63 @@ import { parsedUriObject } from "typings"; | ||
asURI(provider: Provider, callback: Callback<any>) { | ||
let genesis: any, latest; | ||
asURI(provider: Provider) { | ||
return new Promise((resolve, reject) => { | ||
let genesis: any, latest; | ||
this.getBlockByNumber( | ||
"0x0", | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
if (err) return callback(err); | ||
genesis = result; | ||
this.getBlockByNumber( | ||
"0x0", | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
if (err) return reject(err); | ||
genesis = result; | ||
this.getBlockByNumber( | ||
"latest", | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
if (err) return callback(err); | ||
latest = result; | ||
const url = `blockchain://${genesis.hash.replace( | ||
"0x", | ||
"" | ||
)}/block/${latest.hash.replace("0x", "")}`; | ||
callback(null, url); | ||
} | ||
); | ||
} | ||
); | ||
this.getBlockByNumber( | ||
"latest", | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
if (err) return reject(err); | ||
latest = result; | ||
const url = `blockchain://${genesis.hash.replace( | ||
"0x", | ||
"" | ||
)}/block/${latest.hash.replace("0x", "")}`; | ||
resolve(url); | ||
} | ||
); | ||
} | ||
); | ||
}); | ||
}, | ||
matches(uri: string, provider: Provider, callback: Callback<any>) { | ||
const parsedUri = this.parse(uri); | ||
matches(uri: string, provider: Provider) { | ||
return new Promise((resolve, reject) => { | ||
const parsedUri = this.parse(uri); | ||
const expected_genesis = parsedUri.genesis_hash; | ||
const expected_block = parsedUri.block_hash; | ||
const expected_genesis = parsedUri.genesis_hash; | ||
const expected_block = parsedUri.block_hash; | ||
this.getBlockByNumber( | ||
"0x0", | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
if (err) return callback(err); | ||
const block = result; | ||
if (block.hash !== expected_genesis) return callback(null, false); | ||
this.getBlockByNumber( | ||
"0x0", | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
if (err) return reject(err); | ||
const block = result; | ||
if (block.hash !== expected_genesis) return resolve(false); | ||
this.getBlockByHash( | ||
expected_block, | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
// Treat an error as if the block didn't exist. This is because | ||
// some clients respond differently. | ||
const block = result; | ||
if (err || block == null) { | ||
return callback(null, false); | ||
this.getBlockByHash( | ||
expected_block, | ||
provider, | ||
(err: Error, { result }: JsonRPCResponse) => { | ||
// Treat an error as if the block didn't exist. This is because | ||
// some clients respond differently. | ||
const block = result; | ||
if (err || block == null) { | ||
return resolve(false); | ||
} | ||
resolve(true); | ||
} | ||
callback(null, true); | ||
} | ||
); | ||
} | ||
); | ||
); | ||
} | ||
); | ||
}); | ||
} | ||
@@ -112,0 +117,0 @@ }; |
@@ -11,3 +11,3 @@ { | ||
}, | ||
"version": "0.0.19-alphaTez.0", | ||
"version": "0.0.19", | ||
"main": "dist/index.js", | ||
@@ -37,3 +37,6 @@ "scripts": { | ||
}, | ||
"gitHead": "9c106f4529dc4e3a2e88e722aea53a40eea5e4de" | ||
"dependencies": { | ||
"source-map-support": "^0.5.19" | ||
}, | ||
"gitHead": "cd27f14cf31ad6d3201ebbaa9bfa5eb83dbc590a" | ||
} |
Sorry, the diff of this file is not supported yet
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
13118
236
1
+ Addedsource-map-support@^0.5.19
+ Addedbuffer-from@1.1.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-support@0.5.21(transitive)