Skip to content

Feat/custom rpc url #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/web3data.min.js

Large diffs are not rendered by default.

474 changes: 238 additions & 236 deletions docs/api.md

Large diffs are not rendered by default.

3,355 changes: 2,067 additions & 1,288 deletions package-lock.json

Large diffs are not rendered by default.

49 changes: 26 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,59 @@
"litecoin",
"zcash"
],
"authors": ["@trevorjtclarke", "Taylor Dawson"],
"authors": [
"@trevorjtclarke",
"Taylor Dawson"
],
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/web3data/web3data-js/issues"
},
"homepage": "https://github.com/web3data/web3data-js#readme",
"devDependencies": {
"@ava/babel": "^1.0.0",
"@ava/babel": "^1.0.1",
"@ava/babel-preset-stage-4": "^4.0.0",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/register": "^7.8.3",
"@pollyjs/adapter-node-http": "^4.0.3",
"@pollyjs/core": "^4.0.2",
"@pollyjs/persister-fs": "^4.0.2",
"ava": "^3.1.0",
"@babel/core": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/register": "^7.9.0",
"@pollyjs/adapter-node-http": "^4.1.0",
"@pollyjs/core": "^4.1.0",
"@pollyjs/persister-fs": "^4.1.0",
"ava": "^3.7.1",
"capture-console": "^1.0.1",
"cross-env": "^7.0.0",
"cross-env": "^7.0.2",
"docsify-cli": "^4.4.0",
"dotenv": "^8.2.0",
"doxdox": "^3.0.0",
"doxdox-parser-dox": "github:taylorjdawson/doxdox-parser-dox",
"doxdox-plugin-markdown": "github:taylorjdawson/doxdox-plugin-markdown",
"eslint-plugin-jsdoc": "^21.0.0",
"doxdox-plugin-markdown": "taylorjdawson/doxdox-plugin-markdown",
"eslint-plugin-jsdoc": "^24.0.0",
"get-port": "^5.1.1",
"husky": "^4.2.1",
"husky": "^4.2.5",
"jsdoc-to-markdown": "^5.0.3",
"lodash": "^4.17.15",
"nyc": "^15.0.0",
"nyc": "^15.0.1",
"parcel": "^1.12.4",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"rollup": "^1.30.1",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"rollup": "^2.7.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-filesize": "^6.2.1",
"rollup-plugin-filesize": "^7.0.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-terser": "^5.3.0",
"superstatic": "^6.0.4",
"xo": "^0.25.3"
"xo": "^0.29.1"
},
"dependencies": {
"axios": "^0.19.2",
"isomorphic-ws": "^4.0.1",
"uuid": "^3.4.0",
"ws": "^7.2.1"
"uuid": "^7.0.3",
"ws": "^7.2.3"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions src/bch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Bch {
}

/* See Web3Data class for details on rpc method */
rpc(method, params) {
return this.web3data.rpc(method, params)
rpc(method, parameters) {
return this.web3data.rpc(method, parameters)
}
}

Expand Down
30 changes: 16 additions & 14 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,36 @@ class Block {
}

/**
* Retrieves the latest block number
* Retrieves the latest block number.
*
* @returns {String} block Number
* @returns {string} Block Number.
* @example
*/
getBlockNumber() {
return this.web3data.block.getBlock('latest').then(block => {
return this.web3data.block.getBlock('latest').then((block) => {
throwIf(block | !block.number, 'Failed to retrieve block number.')
return parseInt(block.number, 10)
return Number.parseInt(block.number, 10)
})
}

/**
* Retrieves the block transaction count for a specific block based on hash or number
* Retrieves the block transaction count for a specific block based on hash or number.
*
* @param id - The number or hash of the block for which to retrieve block information.
* @param [filterOptions] -
* @returns
* @example
*/
getBlockTransactionCount(id) {
return this.web3data.block.getBlock(id).then(block => {
return this.web3data.block.getBlock(id).then((block) => {
throwIf(
!block || (!block.predictions && !block.numTransactions),
'Failed to retrieve block transaction count.'
)
// If 'predictions' field exists then it's a future block thus has no txns
return block.predictions ? null : parseInt(block.numTransactions, 10)
return block.predictions
? null
: Number.parseInt(block.numTransactions, 10)
})
}

Expand All @@ -110,14 +112,14 @@ class Block {
* Retrieves a single transaction for a block specified by its id (number or hash) and transaction index.
*
* @param id - The number or hash of the block for which to retrieve block information.
* @param index - The number of the transaction block index
* @param index - The number of the transaction block index.
* @param [filterOptions] -
* @returns
* @example
*/
getTransactionFromBlock(id, index) {
throwIf(is.undefined(id), NO_BLOCK_ID)
return this.web3data.block.getTransactions(id).then(txns => {
return this.web3data.block.getTransactions(id).then((txns) => {
throwIf(!txns, 'Failed to retrieve transaction.')

// Check that 'index' is within valid range
Expand All @@ -128,7 +130,7 @@ class Block {
/**
* Retrieves the uncle specified by its id (number or hash).
*
* @param id - The number or hash of the uncle
* @param id - The number or hash of the uncle.
* @param index - The index of the uncle, in most cases this is 0-2.
* @param [filterOptions] -
* @returns
Expand All @@ -141,7 +143,7 @@ class Block {
.getBlock(id, {
validationMethod: 'full'
})
.then(block => {
.then((block) => {
throwIf(
!block ||
(!block.predictions && !block.numTransactions && !block.validation),
Expand All @@ -161,7 +163,7 @@ class Block {
}

/**
* Retrieves the block token transfers executed at a specific block
* Retrieves the block token transfers executed at a specific block.
*
* @param id - The number or hash of the block for which to retrieve block information.
* @param [filterOptions] -
Expand All @@ -179,7 +181,7 @@ class Block {
}

/**
* Retrieves the block logs executed at a specific block
* Retrieves the block logs executed at a specific block.
*
* @param id - The number or hash of the block for which to retrieve block information.
* @param [filterOptions] -
Expand All @@ -197,7 +199,7 @@ class Block {
}

/**
* Retrieves the block functions/internalMessages executed at a specific block
* Retrieves the block functions/internalMessages executed at a specific block.
*
* @param id - The number or hash of the block for which to retrieve block information.
* @param [filterOptions] -
Expand Down
4 changes: 2 additions & 2 deletions src/bsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Bsv {
}

/* See Web3Data class for details on rpc method */
rpc(method, params) {
return this.web3data.rpc(method, params)
rpc(method, parameters) {
return this.web3data.rpc(method, parameters)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/btc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Btc {
}

/* See Web3Data class for details on rpc method */
rpc(method, params) {
return this.web3data.rpc(method, params)
rpc(method, parameters) {
return this.web3data.rpc(method, parameters)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Contract {
* @example const code = await web3data.contract.getCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
*/
getCode(hash) {
return this.getDetails(hash).then(details => details.bytecode || '0x')
return this.getDetails(hash).then((details) => details.bytecode || '0x')
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Eth {
}

/* See Web3Data class for details on rpc method */
rpc(method, params) {
return this.web3data.rpc(method, params)
rpc(method, parameters) {
return this.web3data.rpc(method, parameters)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ltc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Ltc {
}

/* See Web3Data class for details on rpc method */
rpc(method, params) {
return this.web3data.rpc(method, params)
rpc(method, parameters) {
return this.web3data.rpc(method, parameters)
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Market {
async getEtherPrice() {
return get(this.web3data, {
endpoint: ENDPOINT + '/prices/eth/latest'
}).then(response => response.payload.eth_usd.price, onError)
}).then((response) => response.payload.eth_usd.price, onError)
}

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ class Market {
features = Array.isArray(features) ? features : [features]

// Iterate through each feature and if all is valid return array of promises
features = features.map(feature => {
features = features.map((feature) => {
// Check each feature that it is valid
throwIf(is.undefined(feature) || !FEATURES.includes(feature), NO_FEATURE)

Expand All @@ -98,13 +98,13 @@ class Market {
.then(onFulfilled, onError)
// Return an object with 'feature' as the key and response the value
// .split('/')[0] removes the extra endpoint added above in switch
.then(response => ({[feature.split('/')[0]]: response}))
.then((response) => ({[feature.split('/')[0]]: response}))
)
})

// Returns array of promises that once resolved are merged into a single object
return Promise.all([...features]).then(data =>
data.reduce((accumObj, curObj) => ({...accumObj, ...curObj}))
return Promise.all([...features]).then((data) =>
data.reduce((accumObject, curObject) => ({...accumObject, ...curObject}))
)
}

Expand Down Expand Up @@ -146,7 +146,7 @@ class Market {
getOrders(pair, exchange, filterOptions = {}) {
throwIf(is.undefined(pair), NO_MARKET_PAIR)
exchange = Array.isArray(exchange) ? exchange : [exchange]
exchange.forEach(exchange =>
exchange.forEach((exchange) =>
throwIf(is.undefined(exchange), 'No exchange specified')
)
filterOptions.exchange = exchange
Expand Down
4 changes: 2 additions & 2 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Transaction {
*/
getPendingTransactions() {
return this.getTransactions({status: 'pending'}).then(
pendingTransactions => {
(pendingTransactions) => {
throwIf(
is.undefined(pendingTransactions) || is.null(pendingTransactions),
'Failed to retrieve pending transactions.'
Expand Down Expand Up @@ -135,7 +135,7 @@ class Transaction {
* const gasPrice = await web3data.transaction.getGasPrice()
*/
getGasPrice() {
return this.getGasPrediction().then(gasPrediction => {
return this.getGasPrediction().then((gasPrediction) => {
throwIf(
!gasPrediction.average || !gasPrediction.average.gasPrice,
'Failed to retrieve gas price.'
Expand Down
Loading