Skip to content

Commit 2e8143e

Browse files
committed
feat(contract): Merge master
2 parents e5d3d1d + d4c3663 commit 2e8143e

File tree

10 files changed

+3283
-1299
lines changed

10 files changed

+3283
-1299
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.

dist/web3data.min.js.map

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api.md

Lines changed: 784 additions & 326 deletions
Large diffs are not rendered by default.

src/address.js

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ const {
33
ADDRESSES_ENDPOINT: ENDPOINT
44
} = require('./constants')
55

6-
const {is, get, throwIf, onFulfilled, onError} = require('./utils')
6+
const {
7+
is,
8+
get,
9+
throwIf,
10+
onFulfilled,
11+
onError,
12+
recordsFormatter
13+
} = require('./utils')
714

815
/**
916
* Contains methods pertaining to the `/address` endpoint of Amberdata's API.
@@ -19,21 +26,33 @@ class Address {
1926
this.web3data = web3data
2027
}
2128

29+
/**
30+
* Alias of getAll().
31+
*
32+
* @param [filterOptions] - The filters associated with the request.
33+
* @example web3data.address.getAllAddresses({
34+
* size: 100,
35+
* })
36+
*/
37+
getAllAddresses(filterOptions = {}) {
38+
return this.getAll(filterOptions)
39+
}
40+
2241
/**
2342
* Returns every address that has been seen on the network.
2443
*
2544
* @param filterOptions - The filters associated with the request.
2645
* @param [filterOptions.hash] - Filter by a specific address.
2746
* @param [filterOptions.size] - The size of the response. <b>Default:</b> `100`.
28-
* @returns Containing an object with an array of objects containing. See [API docs](https://docs.amberdata.io/reference#get-all-addresses) for details on return.
47+
* @returns Containing an object with an array of objects containing. See [API docs](https://docs.amberdata.io/reference#get-all-addresses) for details on response.
2948
* @public
30-
* @example web3data.address.getAllAddresses({
49+
* @example web3data.address.getAll({
3150
* size: 100,
3251
* })
3352
*/
34-
getAllAddresses(filterOptions = {}) {
53+
getAll(filterOptions = {}) {
3554
return get(this.web3data, {endpoint: ENDPOINT, filterOptions}).then(
36-
onFulfilled,
55+
onFulfilled.bind({formatter: recordsFormatter}),
3756
onError
3857
)
3958
}
@@ -58,8 +77,17 @@ class Address {
5877
}).then(onFulfilled, onError)
5978
}
6079

80+
/**
81+
* Retrieves the historical adoption for the specified address.
82+
*
83+
* @param hash - The address.
84+
* @param [filterOptions] - The filters associated with the request. See [API docs](https://docs.amberdata.io/reference#get-address-adoption) for details.
85+
* @returns The historical adoption data for the specified address.
86+
* @example
87+
* const adoption = await web3data.address.getAdoption('0x06012c8cf97bead5deae237070f9587f8e7a266d')
88+
*/
6189
getAdoption(hash, filterOptions) {
62-
if (is.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS))
90+
throwIf(is.notHash(hash), NO_ADDRESS)
6391
return get(this.web3data, {
6492
hash,
6593
endpoint: ENDPOINT,
@@ -308,8 +336,16 @@ Returns null if no address is found.
308336
}).then(onFulfilled, onError)
309337
}
310338

339+
/**
340+
* Retrieves the historical usage for the specified address.
341+
*
342+
* @param hash - The address.
343+
* @param [filterOptions] - The filters associated with the request. See [API docs](https://docs.amberdata.io/reference#get-address-usage) for details.
344+
* @returns The usage statistics for the specified address.
345+
* @example const usage = await web3data.address.getUsage(ADDRESS)
346+
*/
311347
getUsage(hash, filterOptions) {
312-
if (is.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS))
348+
throwIf(is.notHash(hash), NO_ADDRESS)
313349
return get(this.web3data, {
314350
hash,
315351
endpoint: ENDPOINT,
@@ -318,12 +354,17 @@ Returns null if no address is found.
318354
}).then(onFulfilled, onError)
319355
}
320356

321-
// TODO: Needs tests
322-
getMetrics(filterOptions) {
357+
/**
358+
* Get metrics for all addresses that have exist publicly for a given blockchain. Default metrics are for Ethereum over a 24h period.
359+
*
360+
* @returns The address metrics.
361+
* @example
362+
* const metrics = await web3data.address.getMetrics(ADDRESS)
363+
*/
364+
getMetrics() {
323365
return get(this.web3data, {
324366
endpoint: ENDPOINT,
325-
subendpoint: 'metrics/latest',
326-
filterOptions
367+
subendpoint: 'metrics/latest'
327368
}).then(onFulfilled, onError)
328369
}
329370
}

src/transaction.js

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,63 @@ const {
1212
recordsFormatter
1313
} = require('./utils')
1414

15+
/**
16+
* Contains methods pertaining to the `/address` endpoint of Amberdata's API.
17+
* See [documentation](https://docs.amberdata.io/reference#get-all-transactions) details about our transaction endpoints.
18+
*/
1519
class Transaction {
20+
/**
21+
* Creates an instance of Transaction. Meant to be used in conjunction with the Web3Data class.
22+
*
23+
* @param web3data - The web3data instance.
24+
* @example
25+
*/
1626
constructor(web3data) {
1727
this.web3data = web3data
1828
}
1929

20-
getTransactions(filterOptions) {
30+
/**
31+
* Retrieves all transactions matching the specified filters.
32+
*
33+
* @param [filterOptions] - The filter options associated with the request.
34+
* @param [filterOptions.status] - Filter by the status of the transactions to retrieve (all, completed, failed, pending).
35+
* @param [filterOptions.includePrice] - Indicates whether or not to include price data with the results.
36+
* @returns All transactions matched by the specified filters.
37+
* @example const transactions = await web3data.transaction.getTransactions()
38+
*
39+
* // Include pricing data with transactions
40+
* const transactions = await web3data.transaction.getTransactions({
41+
* includePrice: true
42+
* })
43+
*/
44+
getTransactions(filterOptions = {}) {
2145
return get(this.web3data, {
2246
endpoint: ENDPOINT,
2347
filterOptions
2448
}).then(onFulfilled.bind({formatter: recordsFormatter}), onError)
2549
}
2650

27-
getTransaction(hash, filterOptions) {
51+
/**
52+
* See 'getTransactions' for details.
53+
*
54+
* @param filterOptions
55+
* @example
56+
*/
57+
getAll(filterOptions) {
58+
return this.getTransactions(filterOptions)
59+
}
60+
61+
/**
62+
* Retrieves the transaction data for the specified hash.
63+
*
64+
* @param hash - The transaction hash.
65+
* @param [filterOptions] - The filter options associated with the request. See [docs](https://docs.amberdata.io/reference#get-transaction) for more details.
66+
* @param [filterOptions.validationMethod=none] - The validation method to be added to the response: `none`, `basic`, `full`.
67+
* @param [filterOptions.includePrice=true] - Indicates whether or not to include price data with the results.
68+
* @returns The data for the specified transaction hash.
69+
* @example const transaction = await web3data.transaction.getTransaction('0xd0a5a0912fdf87993b3cebd696f1ee667a8fbbe8fc890a22dcbdf114f36de4cf')
70+
*/
71+
getTransaction(hash, filterOptions = {}) {
2872
throwIf(is.notHash(hash), NO_HASH)
2973
return get(this.web3data, {
3074
pathParam: hash,
@@ -33,6 +77,12 @@ class Transaction {
3377
}).then(onFulfilled, onError)
3478
}
3579

80+
/**
81+
* Retrieves all pending transaction.
82+
*
83+
* @returns The pending transactions.
84+
* @example const pendingTransactions = await web3data.transaction.getPendingTransactions()
85+
*/
3686
getPendingTransactions() {
3787
return this.getTransactions({status: 'pending'}).then(
3888
pendingTransactions => {
@@ -46,21 +96,44 @@ class Transaction {
4696
)
4797
}
4898

99+
/**
100+
* Retrieves the latest gas predictions for the transactions.
101+
*
102+
* @returns The latest gas predictions for the transactions.
103+
* @example
104+
* const gasPredictions = await web3data.transaction.getGasPrediction()
105+
*/
49106
getGasPrediction() {
50107
return get(this.web3data, {
51108
endpoint: ENDPOINT,
52109
subendpoint: 'gas/predictions'
53110
}).then(onFulfilled, onError)
54111
}
55112

56-
getGasPercentiles(filterOptions) {
113+
/**
114+
* Retrieves the latest gas price percentiles for the transactions.
115+
*
116+
* @param [filterOptions] - The filter options associated with the request.
117+
* @param [filterOptions.numBlocks] - Number of past blocks on which to base the percentiles.
118+
* @returns The latest gas price percentiles for the transactions.
119+
* @example
120+
* const gasPercentiles = await web3data.transaction.getGasPercentiles()
121+
*/
122+
getGasPercentiles(filterOptions = {}) {
57123
return get(this.web3data, {
58124
endpoint: ENDPOINT,
59125
subendpoint: 'gas/percentiles',
60126
filterOptions
61127
}).then(onFulfilled, onError)
62128
}
63129

130+
/**
131+
* Retrieves the latest average gas price. Uses `getGasPrediction` under the hood.
132+
*
133+
* @returns The latest gas price.
134+
* @example
135+
* const gasPrice = await web3data.transaction.getGasPrice()
136+
*/
64137
getGasPrice() {
65138
return this.getGasPrediction().then(gasPrediction => {
66139
throwIf(
@@ -71,15 +144,31 @@ class Transaction {
71144
})
72145
}
73146

74-
getVolume(filterOptions) {
147+
/**
148+
* Retrieves the historical (time series) volume of transactions.
149+
*
150+
* @param [filterOptions] - The filter options associated with the request. See [docs](https://docs.amberdata.io/reference#get-historical-transaction-volume) for more details.
151+
* @returns The historical (time series) volume of transactions.
152+
* @example
153+
* const volume = await web3data.transaction.getVolume()
154+
*/
155+
getVolume(filterOptions = {}) {
75156
return get(this.web3data, {
76157
endpoint: ENDPOINT,
77158
subendpoint: 'volume',
78159
filterOptions
79160
}).then(onFulfilled, onError)
80161
}
81162

82-
getMetrics(filterOptions) {
163+
/**
164+
* Get metrics for recent confirmed transactions for a given blockchain. Default metrics are over a 24h period.
165+
*
166+
* @returns Metrics for recent confirmed transactions.
167+
* @example
168+
* const metrics = await web3data.transaction.getMetrics()
169+
*
170+
*/
171+
getMetrics(filterOptions = {}) {
83172
return get(this.web3data, {
84173
endpoint: ENDPOINT,
85174
subendpoint: 'metrics/latest',

test/address.test.js

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import test, {only} from "ava"
22
import {ADDRESS } from './constants'
33
import {ERROR_MESSAGE_ADDRESS_NO_ADDRESS as NO_ADDRESS} from "../src/constants";
4-
import {setUpPolly, hasProp, getNewWeb3DataInstance} from "./utils";
4+
import {
5+
setUpPolly,
6+
hasProp,
7+
getNewWeb3DataInstance,
8+
isISOFormat
9+
} from "./utils";
510

611
/**********************************
712
* -------- Tests Setup ---------- *
@@ -22,11 +27,30 @@ test.beforeEach(t => {
2227
* -------- Test address -------- *
2328
**********************************/
2429

30+
/*********** Test getAll() ***********/
31+
test('Successfully calls getAll()', async t => {
32+
const [addresses] = await t.context.web3data.address.getAll()
33+
t.true(addresses.hasProp('firstBlockNumber'))
34+
})
35+
36+
test('Successfully calls getAll() - with filters', async t => {
37+
const [addresses] = await t.context.web3data.address.getAll({type: 'CONTRACT'})
38+
t.true(addresses.hasProp('type'))
39+
t.is(addresses.type.toUpperCase(), 'CONTRACT')
40+
t.true(addresses.creator !== null)
41+
})
42+
2543
/*********** Test getAllAddresses() ***********/
26-
test('Successfully gets all addresses', async t => {
27-
let addresses = await t.context.web3data.address.getAllAddresses()
28-
t.true({}.hasOwnProperty.call(addresses, 'records'))
29-
t.true({}.hasOwnProperty.call(addresses, 'totalRecords'))
44+
test('Successfully calls getAllAddresses()', async t => {
45+
const [addresses] = await t.context.web3data.address.getAllAddresses()
46+
t.true(addresses.hasProp('firstBlockNumber'))
47+
})
48+
49+
test('Successfully calls getAllAddresses() - with filters', async t => {
50+
const [addresses] = await t.context.web3data.address.getAllAddresses({type: 'CONTRACT'})
51+
t.true(addresses.hasProp('type'))
52+
t.is(addresses.type.toUpperCase(), 'CONTRACT')
53+
t.true(addresses.creator !== null)
3054
})
3155

3256
/*********** Test getInformation() ***********/
@@ -69,10 +93,19 @@ test('Successfully gets address metadata - with filters', async t => {
6993
})
7094

7195
/*********** Test getAdoption() ***********/
72-
test('Successfully gets address adoption', async t => {
73-
const response = await t.context.web3data.address.getAdoption(ADDRESS)
74-
t.true({}.hasOwnProperty.call(response, 'metadata'))
96+
test('Successfully calls getAdoption()', async t => {
97+
const adoption = await t.context.web3data.address.getAdoption(ADDRESS)
98+
t.true(adoption.hasProp('metadata'))
99+
t.true(adoption.metadata.hasProp('columns'))
75100
})
101+
102+
test('Successfully calls getAdoption() - with filters', async t => {
103+
const adoption = await t.context.web3data.address.getAdoption(ADDRESS, {timeFormat: 'iso'})
104+
t.true(adoption.hasProp('metadata'))
105+
t.true(adoption.metadata.hasProp('columns'))
106+
t.true(isISOFormat(adoption.metadata.startDate))
107+
})
108+
76109
test('throws exception when calling getAdoption without hash', async t => {
77110
await t.throwsAsync(async () => {
78111
await t.context.web3data.address.getAdoption()
@@ -237,9 +270,15 @@ test('throws exception when calling getTokenBalances without hash', async t => {
237270
})
238271

239272
/*********** Test getUsage() ***********/
240-
test('Successfully gets address usage', async t => {
241-
const response = await t.context.web3data.address.getUsage(ADDRESS)
242-
t.true({}.hasOwnProperty.call(response, 'metadata'))
273+
test('Successfully calls getUsage()', async t => {
274+
const usage = await t.context.web3data.address.getUsage(ADDRESS)
275+
t.true(usage.hasProp('metadata'))
276+
})
277+
278+
test('Successfully calls getUsage() - with filters', async t => {
279+
const usage = await t.context.web3data.address.getUsage(ADDRESS, {timeFormat: 'iso'})
280+
t.true(usage.hasProp('metadata'))
281+
t.true(isISOFormat(usage.metadata.startDate))
243282
})
244283

245284
test('throws exception when calling getUsage without hash', async t => {
@@ -372,3 +411,9 @@ test('Successfully gets historical address balance + paginates properly', async
372411
const balance = await t.context.web3data.address.getBalance(ADDRESS, {startDate: 1506184430, page: 0, size: SIZE})
373412
t.is(balance.data.length, SIZE)
374413
})
414+
415+
/*********** Test getMetrics() ***********/
416+
test('Successfully calls getMetrics()', async t => {
417+
const metrics = await t.context.web3data.address.getMetrics(ADDRESS)
418+
t.true(metrics.hasProp('activeTotal'))
419+
})

0 commit comments

Comments
 (0)