Skip to content

Commit 923f8e8

Browse files
Merge pull request #59 from web3data/feat/zcash
feat(zcash): Add zcash.
2 parents 6c71108 + b80b91f commit 923f8e8

File tree

9 files changed

+211
-94
lines changed

9 files changed

+211
-94
lines changed

dist/web3data.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api.md

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [web3data-js](https://github.com/web3data/web3data-js#readme) *0.5.16*
1+
# [web3data-js](https://github.com/web3data/web3data-js#readme) *0.5.17*
22

33
> A javascript wrapper for accessing amberdata's public API.
44
@@ -1627,99 +1627,10 @@ const metrics = await web3data.transaction.getMetrics()
16271627

16281628

16291629

1630-
### src/utils.js
1631-
1632-
1633-
1634-
#### get(web3data, subendpoint, endpoint, hash, pathParam, filterOptions)
1635-
1636-
1637-
Builds the endpoint url to pass to .rawQuery(). Checks for non empties and appends
1638-
the appropriate parameter(s) where applicable.
1639-
1640-
1641-
1642-
1643-
##### Parameters
1644-
1645-
| Name | Type | Description | |
1646-
| ---- | ---- | ----------- | -------- |
1647-
| web3data | | Instance on which to call .rawQuery(). |   |
1648-
| subendpoint | | The subendpoint. |   |
1649-
| endpoint | | The endpoint. |   |
1650-
| hash | | The address hash. |   |
1651-
| pathParam | | The path parameter. |   |
1652-
| filterOptions | | The filters associated with a given endpoint. |   |
1653-
1654-
1655-
1656-
1657-
##### Examples
1658-
1659-
```javascript
1660-
1661-
```
1662-
1663-
1664-
##### Returns
1665-
1666-
1667-
- Returns a Promise of the rawQuery request from web3data.
1668-
1669-
1670-
1671-
1672-
1673-
#### uuid(data)
1674-
1675-
1676-
Generates a uuid see [this gist]() for more details.
1677-
1678-
1679-
1680-
1681-
##### Parameters
1682-
1683-
| Name | Type | Description | |
1684-
| ---- | ---- | ----------- | -------- |
1685-
| data | | |   |
1686-
1687-
1688-
1689-
1690-
##### Examples
1691-
1692-
```javascript
1693-
1694-
```
1695-
1696-
1697-
##### Returns
1698-
1699-
1700-
- `Void`
1701-
1702-
1703-
1704-
1705-
17061630
### src/web3data.js
17071631

17081632

17091633

1710-
#### Class: Web3DataFactory
1711-
1712-
1713-
Contains common methods used in.
1714-
1715-
1716-
1717-
1718-
1719-
1720-
1721-
1722-
17231634
#### constructor(apiKey, options, blockchainId:, -, -)
17241635

17251636

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3data-js",
3-
"version": "0.5.16",
3+
"version": "0.5.17",
44
"description": "A javascript wrapper for accessing amberdata's public API.",
55
"main": "index.js",
66
"browser": "dist/web3data.min.js",

src/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ the appropriate parameter(s) where applicable.
1313
* @param filterOptions - The filters associated with a given endpoint.
1414
* @returns Returns a Promise of the rawQuery request from web3data.
1515
* @example
16+
* @private
1617
*/
1718
const get = (
1819
web3data,
@@ -95,6 +96,7 @@ is.notInObject = (object, property) => !is.inObject(object, property)
9596
*
9697
* @param data
9798
* @example
99+
* @private
98100
*/
99101
const uuid = data =>
100102
_uuid(JSON.stringify(data), 'ccfeca02-f0e9-4433-a740-b830cceb3d2d')

src/web3data.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ const Btc = require('./btc')
1919
const Bch = require('./bch')
2020
const Bsv = require('./bsv')
2121
const Ltc = require('./ltc')
22+
const Zec = require('./zec')
2223
const WebSocketClient = require('./websocket')
2324

2425
/**
2526
* Contains common methods used in.
27+
* @private
2628
*/
2729
class Web3DataFactory {
2830
/**
@@ -123,6 +125,7 @@ class Web3Data extends Web3DataFactory {
123125
this.bch = new Bch(Web3DataFactory, apiKey, options)
124126
this.bsv = new Bsv(Web3DataFactory, apiKey, options)
125127
this.ltc = new Ltc(Web3DataFactory, apiKey, options)
128+
this.zec = new Zec(Web3DataFactory, apiKey, options)
126129

127130
this.websocket = null
128131
}

src/zec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {
2+
BLOCKCHAIN_ID_ZCASH: BLOCKCHAIN_ID,
3+
BTC_METHODS: METHODS
4+
} = require('./constants')
5+
const {methodFactory} = require('./utils')
6+
7+
/**
8+
* Class for all ZCash based methods.
9+
*
10+
* @private
11+
*/
12+
class Zec {
13+
constructor(Web3data, apiKey, options) {
14+
options.blockchainId = BLOCKCHAIN_ID
15+
this.web3data = new Web3data(apiKey, options)
16+
methodFactory(this, METHODS)
17+
}
18+
19+
/* See Web3Data class for details on rpc method */
20+
rpc(method, params) {
21+
return this.web3data.rpc(method, params)
22+
}
23+
}
24+
25+
module.exports = Zec

test/market.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ test('throws exception when calling getOrders without exchange param', async t =
160160

161161
/*********** Test getBbos() ***********/
162162
// TODO: Pending API bug fix
163-
test.skip('Successfully gets latest bos', async t => {
163+
test.skip('Successfully gets latest bbos', async t => {
164164
const bbos = await t.context.web3data.market.getBbos('eth_btc')
165165
const exchangePairBbo = Object.values(Object.values(bbos))[0]
166166

167167
t.true(exchangePairBbo.hasProp('price'))
168168
})
169169
// TODO: Pending API bug fix
170-
test.skip('Successfully gets historical bbos', async t => {
170+
test('Successfully gets historical bbos', async t => {
171171
const bbos = await t.context.web3data.market.getBbos('eth_btc', {startDate: DATE_2019_10_14, endDate: DATE_2019_10_15})
172172

173173
// Check existence of historical data properties

test/recordings/market_3052940913/recording.har

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,152 @@
47694769
"ssl": -1,
47704770
"wait": 817
47714771
}
4772+
},
4773+
{
4774+
"_id": "426dd7a52a332951f2e8b6489d5fd396",
4775+
"_order": 0,
4776+
"cache": {},
4777+
"request": {
4778+
"bodySize": 0,
4779+
"cookies": [],
4780+
"headers": [
4781+
{
4782+
"name": "accept",
4783+
"value": "application/json, text/plain, */*"
4784+
},
4785+
{
4786+
"name": "user-agent",
4787+
"value": "axios/0.19.0"
4788+
},
4789+
{
4790+
"name": "host",
4791+
"value": "web3api.io"
4792+
}
4793+
],
4794+
"headersSize": 254,
4795+
"httpVersion": "HTTP/1.1",
4796+
"method": "GET",
4797+
"queryString": [
4798+
{
4799+
"name": "startDate",
4800+
"value": "1571011200"
4801+
},
4802+
{
4803+
"name": "endDate",
4804+
"value": "1571097600"
4805+
}
4806+
],
4807+
"url": "https://web3api.io/api/v2/market/orders/eth_btc/bbo/historical?startDate=1571011200&endDate=1571097600&x-api-key="
4808+
},
4809+
"response": {
4810+
"bodySize": 236,
4811+
"content": {
4812+
"mimeType": "application/json; charset=utf-8",
4813+
"size": 236,
4814+
"text": "{\"status\":200,\"title\":\"OK\",\"description\":\"Successful request\",\"payload\":{\"data\":[],\"metadata\":{\"columns\":[\"exchange\",\"timestamp\",\"timestampNanoseconds\",\"isBid\",\"price\",\"volume\",\"numOrders\"],\"startDate\":1571011200,\"endDate\":1571097600}}}"
4815+
},
4816+
"cookies": [
4817+
{
4818+
"expires": "2019-11-08T19:51:47.000Z",
4819+
"name": "AWSALB",
4820+
"path": "/",
4821+
"value": "YMZZGCrNGWQKvfIdf2ZF8Cf2octzu8sWv4dmhNL3THaIH4mivGCEOWJGy936HfQW0A4ehc8S/d48PIrY87zSX5Ri1RYayVHoCRoFx3+YY9Q3v8mdZNe9bUHE8xve"
4822+
}
4823+
],
4824+
"headers": [
4825+
{
4826+
"name": "hasprop"
4827+
},
4828+
{
4829+
"name": "values"
4830+
},
4831+
{
4832+
"name": "content-type",
4833+
"value": "application/json; charset=utf-8"
4834+
},
4835+
{
4836+
"name": "content-length",
4837+
"value": "236"
4838+
},
4839+
{
4840+
"name": "connection",
4841+
"value": "close"
4842+
},
4843+
{
4844+
"name": "date",
4845+
"value": "Fri, 01 Nov 2019 19:51:47 GMT"
4846+
},
4847+
{
4848+
"name": "x-amzn-requestid",
4849+
"value": "9c81b1a0-443c-4bde-b4e9-ad62bc284ac0"
4850+
},
4851+
{
4852+
"name": "access-control-allow-origin",
4853+
"value": "*"
4854+
},
4855+
{
4856+
"name": "x-response-time",
4857+
"value": "101.714ms"
4858+
},
4859+
{
4860+
"name": "x-amzn-remapped-content-length",
4861+
"value": "236"
4862+
},
4863+
{
4864+
"name": "x-amzn-remapped-connection",
4865+
"value": "keep-alive"
4866+
},
4867+
{
4868+
"_fromType": "array",
4869+
"name": "set-cookie",
4870+
"value": "AWSALB=YMZZGCrNGWQKvfIdf2ZF8Cf2octzu8sWv4dmhNL3THaIH4mivGCEOWJGy936HfQW0A4ehc8S/d48PIrY87zSX5Ri1RYayVHoCRoFx3+YY9Q3v8mdZNe9bUHE8xve; Expires=Fri, 08 Nov 2019 19:51:47 GMT; Path=/"
4871+
},
4872+
{
4873+
"name": "x-amz-apigw-id",
4874+
"value": "Cfrw_FGKIAMFowg="
4875+
},
4876+
{
4877+
"name": "etag",
4878+
"value": "W/\"ec-da2SsGJiCaR6HLqDAJJ5WTeSK8w\""
4879+
},
4880+
{
4881+
"name": "x-amzn-remapped-date",
4882+
"value": "Fri, 01 Nov 2019 19:51:47 GMT"
4883+
},
4884+
{
4885+
"name": "x-cache",
4886+
"value": "Miss from cloudfront"
4887+
},
4888+
{
4889+
"name": "via",
4890+
"value": "1.1 7f5e0d3b9ea85d0d75063a66c0ebc841.cloudfront.net (CloudFront)"
4891+
},
4892+
{
4893+
"name": "x-amz-cf-pop",
4894+
"value": "HIO50-C1"
4895+
},
4896+
{
4897+
"name": "x-amz-cf-id",
4898+
"value": "Tek1BjyySK33Vl4aNcexlZC74BKMHYlBJGCRismQDkHe5E2uHLb_8Q=="
4899+
}
4900+
],
4901+
"headersSize": 1051,
4902+
"httpVersion": "HTTP/1.1",
4903+
"redirectURL": "",
4904+
"status": 200,
4905+
"statusText": "OK"
4906+
},
4907+
"startedDateTime": "2019-11-01T19:51:46.515Z",
4908+
"time": 734,
4909+
"timings": {
4910+
"blocked": -1,
4911+
"connect": -1,
4912+
"dns": -1,
4913+
"receive": 0,
4914+
"send": 0,
4915+
"ssl": -1,
4916+
"wait": 734
4917+
}
47724918
}
47734919
],
47744920
"pages": [],

test/zec.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import test from 'ava'
2+
import {setUpPolly, getNewWeb3DataInstance} from "./utils";
3+
import { BTC_METHODS as METHODS } from "../src/constants";
4+
5+
/***********************************
6+
* -------- Tests Setup ---------- *
7+
**********************************/
8+
test.before(t => {
9+
t.context.polly = setUpPolly('ltc')
10+
})
11+
12+
test.after(async t => {
13+
await t.context.polly.stop()
14+
})
15+
16+
test.beforeEach(t => {
17+
t.context.web3data = getNewWeb3DataInstance()
18+
});
19+
20+
/*********************************
21+
* ----------- Tests ----------- *
22+
*********************************/
23+
24+
test('Check the zec namespace contains all defined methods', t => {
25+
for(const namespace of Object.keys(METHODS)) {
26+
for (const method of METHODS[namespace]) {
27+
t.truthy(t.context.web3data.zec[namespace][method])
28+
}
29+
}
30+
})

0 commit comments

Comments
 (0)