Skip to content

Commit 17254fb

Browse files
committed
feat(tokens): [Method] getTransfers - Add docs + tests.
1 parent 35e0669 commit 17254fb

File tree

5 files changed

+608
-311
lines changed

5 files changed

+608
-311
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: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ const historicalSupplies = await t.context.web3data.token.getSupplies('0x06012c8
17401740
#### getTransfers(hash[, filterOptions])
17411741

17421742

1743-
1743+
Retrieves all token transfers involving the specified address.
17441744

17451745

17461746

@@ -1749,7 +1749,7 @@ const historicalSupplies = await t.context.web3data.token.getSupplies('0x06012c8
17491749

17501750
| Name | Type | Description | |
17511751
| ---- | ---- | ----------- | -------- |
1752-
| hash | `string` | The address for which to retrieve token holders. |   |
1752+
| hash | `string` | The address for which to retrieve token transfers. |   |
17531753
| filterOptions | `object` | The filters associated with the request. | *Optional* |
17541754

17551755

@@ -1758,90 +1758,14 @@ const historicalSupplies = await t.context.web3data.token.getSupplies('0x06012c8
17581758
##### Examples
17591759

17601760
```javascript
1761-
1761+
const transfers = await web3data.token.getTransfers('0x06012c8cf97bead5deae237070f9587f8e7a266d', {validationMethod: 'full'})
17621762
```
17631763

17641764

17651765
##### Returns
17661766

17671767

1768-
- `Promise.<object>`
1769-
1770-
1771-
1772-
1773-
1774-
### src/utils.js
1775-
1776-
1777-
1778-
#### get(web3data, subendpoint, endpoint, hash, pathParam, filterOptions)
1779-
1780-
1781-
Builds the endpoint url to pass to .rawQuery(). Checks for non empties and appends
1782-
the appropriate parameter(s) where applicable.
1783-
1784-
1785-
1786-
1787-
##### Parameters
1788-
1789-
| Name | Type | Description | |
1790-
| ---- | ---- | ----------- | -------- |
1791-
| web3data | | Instance on which to call .rawQuery(). | &nbsp; |
1792-
| subendpoint | | The subendpoint. | &nbsp; |
1793-
| endpoint | | The endpoint. | &nbsp; |
1794-
| hash | | The address hash. | &nbsp; |
1795-
| pathParam | | The path parameter. | &nbsp; |
1796-
| filterOptions | | The filters associated with a given endpoint. | &nbsp; |
1797-
1798-
1799-
1800-
1801-
##### Examples
1802-
1803-
```javascript
1804-
1805-
```
1806-
1807-
1808-
##### Returns
1809-
1810-
1811-
- Returns a Promise of the rawQuery request from web3data.
1812-
1813-
1814-
1815-
1816-
1817-
#### uuid(data)
1818-
1819-
1820-
Generates a uuid see [this gist]() for more details.
1821-
1822-
1823-
1824-
1825-
##### Parameters
1826-
1827-
| Name | Type | Description | |
1828-
| ---- | ---- | ----------- | -------- |
1829-
| data | | | &nbsp; |
1830-
1831-
1832-
1833-
1834-
##### Examples
1835-
1836-
```javascript
1837-
1838-
```
1839-
1840-
1841-
##### Returns
1842-
1843-
1844-
- `Void`
1768+
- `Promise.<Array>` All token transfers involving the specified address.
18451769

18461770

18471771

@@ -2177,6 +2101,82 @@ const metrics = await web3data.transaction.getMetrics()
21772101

21782102

21792103

2104+
### src/utils.js
2105+
2106+
2107+
2108+
#### get(web3data, subendpoint, endpoint, hash, pathParam, filterOptions)
2109+
2110+
2111+
Builds the endpoint url to pass to .rawQuery(). Checks for non empties and appends
2112+
the appropriate parameter(s) where applicable.
2113+
2114+
2115+
2116+
2117+
##### Parameters
2118+
2119+
| Name | Type | Description | |
2120+
| ---- | ---- | ----------- | -------- |
2121+
| web3data | | Instance on which to call .rawQuery(). | &nbsp; |
2122+
| subendpoint | | The subendpoint. | &nbsp; |
2123+
| endpoint | | The endpoint. | &nbsp; |
2124+
| hash | | The address hash. | &nbsp; |
2125+
| pathParam | | The path parameter. | &nbsp; |
2126+
| filterOptions | | The filters associated with a given endpoint. | &nbsp; |
2127+
2128+
2129+
2130+
2131+
##### Examples
2132+
2133+
```javascript
2134+
2135+
```
2136+
2137+
2138+
##### Returns
2139+
2140+
2141+
- Returns a Promise of the rawQuery request from web3data.
2142+
2143+
2144+
2145+
2146+
2147+
#### uuid(data)
2148+
2149+
2150+
Generates a uuid see [this gist]() for more details.
2151+
2152+
2153+
2154+
2155+
##### Parameters
2156+
2157+
| Name | Type | Description | |
2158+
| ---- | ---- | ----------- | -------- |
2159+
| data | | | &nbsp; |
2160+
2161+
2162+
2163+
2164+
##### Examples
2165+
2166+
```javascript
2167+
2168+
```
2169+
2170+
2171+
##### Returns
2172+
2173+
2174+
- `Void`
2175+
2176+
2177+
2178+
2179+
21802180
### src/web3data.js
21812181

21822182

src/token.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
const {is, get, onFulfilled, onError, throwIf} = require('./utils')
1+
const {
2+
is,
3+
get,
4+
onFulfilled,
5+
onError,
6+
throwIf,
7+
recordsFormatter
8+
} = require('./utils')
29
const {
310
ERROR_MESSAGE_TOKEN_NO_ADDRESS: NO_ADDRESS,
411
ERROR_MESSAGE_TOKEN_NO_HOLDER_ADDRESS: NO_HOLDER_ADDRESS,
@@ -136,10 +143,13 @@ class Token {
136143
}
137144

138145
/**
139-
* @param {string} hash - The address for which to retrieve token holders.
146+
* Retrieves all token transfers involving the specified address.
147+
*
148+
* @param {string} hash - The address for which to retrieve token transfers.
140149
* @param {object} [filterOptions] - The filters associated with the request.
141-
* @returns {Promise<object>}
150+
* @returns {Promise<Array>} All token transfers involving the specified address.
142151
* @example
152+
* const transfers = await web3data.token.getTransfers('0x06012c8cf97bead5deae237070f9587f8e7a266d', {validationMethod: 'full'})
143153
*/
144154
getTransfers(hash, filterOptions = {}) {
145155
throwIf(is.notHash(hash), NO_ADDRESS)
@@ -148,7 +158,7 @@ class Token {
148158
endpoint: ENDPOINT,
149159
subendpoint: 'transfers',
150160
filterOptions
151-
}).then(onFulfilled, onError)
161+
}).then(onFulfilled.bind({formatter: recordsFormatter}), onError)
152162
}
153163
}
154164

test/recordings/token_2491017778/recording.har

Lines changed: 501 additions & 222 deletions
Large diffs are not rendered by default.

test/token.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ test('Rejects promise if no holder address supplied', async t => {
9292
}, { instanceOf: Error, message: NO_HOLDER_ADDRESS })
9393
});
9494

95-
96-
97-
test([rejectsPromise], {method: 'getTransfers'}, NO_ADDRESS)
98-
9995
/*********** Test getRankings() ***********/
10096
test('Successfully calls getRankings()', async t => {
10197
const {data: [rank1]} = await t.context.web3data.token.getRankings();
@@ -160,3 +156,15 @@ test('Successfully calls getSupplies() - historical with filters', async t => {
160156
t.is(supplies.metadata.columns[3], 'totalSupply')
161157
t.true(isISOFormat(supplies.metadata.startDate))
162158
})
159+
160+
/*********** Test getTransfers() ***********/
161+
test([rejectsPromise], {method: 'getTransfers'}, NO_ADDRESS)
162+
test('Successfully calls getTransfers()', async t => {
163+
const [transfer] = await t.context.web3data.token.getTransfers(TOKEN_ADDRESS);
164+
t.true(transfer.hasProp('transactionHash'))
165+
})
166+
test('Successfully calls getTransfers() - with filters', async t => {
167+
const [transfer] = await t.context.web3data.token.getTransfers(TOKEN_ADDRESS, {validationMethod: 'full'});
168+
t.true(transfer.hasProp('validation'))
169+
})
170+

0 commit comments

Comments
 (0)