@truffle/blockchain-utils
Advanced tools
Comparing version 0.0.21-alphaTez.3 to 0.0.21-next.0
"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.21-alphaTez.3", | ||
"version": "0.0.21-next.0", | ||
"main": "dist/index.js", | ||
@@ -20,2 +20,5 @@ "scripts": { | ||
"types": "./typings/index.d.ts", | ||
"dependencies": { | ||
"source-map-support": "^0.5.19" | ||
}, | ||
"devDependencies": { | ||
@@ -26,3 +29,3 @@ "@types/assert": "^1.4.2", | ||
"@types/web3": "1.0.19", | ||
"mocha": "5.2.0", | ||
"mocha": "8.0.1", | ||
"ts-node": "^8.3.0", | ||
@@ -39,3 +42,3 @@ "typescript": "^3.6.3" | ||
}, | ||
"gitHead": "d29ebd9d610cf07fbd046b0a19bd6113916f7ad3" | ||
"gitHead": "688ff063674ded09ca98eb830286e38fee30ae42" | ||
} |
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"module": "commonjs", | ||
@@ -4,0 +5,0 @@ "esModuleInterop": true, |
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
13726
14
249
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)