Skip to content

Commit dc94c29

Browse files
committed
feat(signature): Refactor response to ret only payload. Update tests. Added docs.
1 parent 985fec8 commit dc94c29

File tree

5 files changed

+141
-39
lines changed

5 files changed

+141
-39
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: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ Retrieves the blocks specified by its id (number or hash).
706706
#### Class: Contract
707707

708708

709-
Contains methods pertaining to the `/contract` endpoint of Amberdata's API.
709+
Contains methods pertaining to the `/contracts` endpoint of Amberdata's API.
710710

711711

712712

@@ -728,7 +728,7 @@ Creates an instance of Contract.
728728

729729
| Name | Type | Description | |
730730
| ---- | ---- | ----------- | -------- |
731-
| web3data | `Web3Data` | The web3data instance. |   |
731+
| web3data | | The web3data instance. |   |
732732

733733

734734

@@ -761,7 +761,7 @@ Retrieves all the detailed information for the specified contract (ABI, bytecode
761761

762762
| Name | Type | Description | |
763763
| ---- | ---- | ----------- | -------- |
764-
| hash | `string` | The address. |   |
764+
| hash | | The address. |   |
765765

766766

767767

@@ -776,7 +776,7 @@ const details = await web3data.contract.getDetails('0x06012c8cf97bead5deae237070
776776
##### Returns
777777

778778

779-
- `Promise.<object>` The detailed information for the specified contract.
779+
- The detailed information for the specified contract.
780780

781781

782782

@@ -794,22 +794,22 @@ Retrieves the functions of the specified contract (if available). If not availab
794794

795795
| Name | Type | Description | |
796796
| ---- | ---- | ----------- | -------- |
797-
| hash | `string` | The contract address. | &nbsp; |
797+
| hash | | The contract address. | &nbsp; |
798798

799799

800800

801801

802802
##### Examples
803803

804804
```javascript
805-
805+
const functions = await web3data.contract.getFunctions('0x06012c8cf97bead5deae237070f9587f8e7a266d')
806806
```
807807

808808

809809
##### Returns
810810

811811

812-
- `Promise.<object>` The functions or decompiled functions of the specified contract.
812+
- The functions or decompiled functions of the specified contract.
813813

814814

815815

@@ -827,7 +827,7 @@ Retrieves the vulnerabilities audit for the specified contract (if available).
827827

828828
| Name | Type | Description | |
829829
| ---- | ---- | ----------- | -------- |
830-
| hash | `string` | The contract address. | &nbsp; |
830+
| hash | | The contract address. | &nbsp; |
831831

832832

833833

@@ -842,7 +842,7 @@ const audit = await web3data.contract.getAudit('0x06012c8cf97bead5deae237070f958
842842
##### Returns
843843

844844

845-
- `Promise.<object>` The vulnerabilities audit for the specified contract.
845+
- The vulnerabilities audit for the specified contract.
846846

847847

848848

@@ -860,7 +860,7 @@ Retrieves the contract's abi.
860860

861861
| Name | Type | Description | |
862862
| ---- | ---- | ----------- | -------- |
863-
| hash | `string` | The contract address. | &nbsp; |
863+
| hash | | The contract address. | &nbsp; |
864864

865865

866866

@@ -875,7 +875,7 @@ const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e
875875
##### Returns
876876

877877

878-
- `Promise.<array>` The abi of the contract.
878+
- The abi of the contract.
879879

880880

881881

@@ -893,7 +893,7 @@ Retrieves the contract's source code.
893893

894894
| Name | Type | Description | |
895895
| ---- | ---- | ----------- | -------- |
896-
| hash | `string` | The contract address. | &nbsp; |
896+
| hash | | The contract address. | &nbsp; |
897897

898898

899899

@@ -908,7 +908,7 @@ const source = await web3data.contract.getSourceCode('0x06012c8cf97bead5deae2370
908908
##### Returns
909909

910910

911-
- `Promise.<string>` The source of the contract.
911+
- The source of the contract.
912912

913913

914914

@@ -926,7 +926,7 @@ Returns the contract's bytecode.
926926

927927
| Name | Type | Description | |
928928
| ---- | ---- | ----------- | -------- |
929-
| hash | `string` | The contract address. | &nbsp; |
929+
| hash | | The contract address. | &nbsp; |
930930

931931

932932

@@ -941,7 +941,7 @@ const code = await web3data.contract.getCode('0x06012c8cf97bead5deae237070f9587f
941941
##### Returns
942942

943943

944-
- `Promise.<string>` The contract's bytecode.
944+
- The contract's bytecode.
945945

946946

947947

@@ -1396,6 +1396,89 @@ const batTokenAddress = web3data.market.getAssetAddresses('bat') const assetAddr
13961396

13971397

13981398

1399+
### src/signature.js
1400+
1401+
1402+
1403+
#### Class: Signature
1404+
1405+
1406+
Contains methods pertaining to the `/signatures` endpoint of Amberdata's API.
1407+
1408+
1409+
1410+
1411+
1412+
1413+
1414+
1415+
1416+
#### constructor(web3data)
1417+
1418+
1419+
Creates an instance of Signature.
1420+
1421+
1422+
1423+
1424+
##### Parameters
1425+
1426+
| Name | Type | Description | |
1427+
| ---- | ---- | ----------- | -------- |
1428+
| web3data | | The web3data instance. | &nbsp; |
1429+
1430+
1431+
1432+
1433+
##### Examples
1434+
1435+
```javascript
1436+
1437+
```
1438+
1439+
1440+
##### Returns
1441+
1442+
1443+
- `Void`
1444+
1445+
1446+
1447+
1448+
1449+
#### getSignature(hash)
1450+
1451+
1452+
Retrieves detailed information about the specified signature hash.
1453+
1454+
1455+
1456+
1457+
##### Parameters
1458+
1459+
| Name | Type | Description | |
1460+
| ---- | ---- | ----------- | -------- |
1461+
| hash | | The (keccak 256) of the signature. | &nbsp; |
1462+
1463+
1464+
1465+
1466+
##### Examples
1467+
1468+
```javascript
1469+
const signatureDetails = await web3data.signature.getSignature('0xe2f0a05a')
1470+
```
1471+
1472+
1473+
##### Returns
1474+
1475+
1476+
- Information pertaining to the specified signature hash.
1477+
1478+
1479+
1480+
1481+
13991482
### src/transaction.js
14001483

14011484

src/contract.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const {
55
const {is, get, throwIf, onFulfilled, onError} = require('./utils')
66

77
/**
8-
* Contains methods pertaining to the `/contract` endpoint of Amberdata's API.
8+
* Contains methods pertaining to the `/contracts` endpoint of Amberdata's API.
99
*/
1010
class Contract {
1111
/**
1212
* Creates an instance of Contract.
1313
*
14-
* @param {Web3Data} web3data - The web3data instance.
14+
* @param web3data - The web3data instance.
1515
* @example
1616
*/
1717
constructor(web3data) {
@@ -21,8 +21,8 @@ class Contract {
2121
/**
2222
* Retrieves all the detailed information for the specified contract (ABI, bytecode, sourcecode...).
2323
*
24-
* @param {string} hash - The address.
25-
* @returns {Promise<object>} The detailed information for the specified contract.
24+
* @param hash - The address.
25+
* @returns The detailed information for the specified contract.
2626
* @example const details = await web3data.contract.getDetails('0x06012c8cf97bead5deae237070f9587f8e7a266d')
2727
*/
2828
getDetails(hash) {
@@ -36,8 +36,8 @@ class Contract {
3636
/**
3737
* Retrieves the functions of the specified contract (if available). If not available on chain, the byte code is decompiled and a list of functions is extracted from it.
3838
*
39-
* @param {string} hash - The contract address.
40-
* @returns {Promise<object>} The functions or decompiled functions of the specified contract.
39+
* @param hash - The contract address.
40+
* @returns The functions or decompiled functions of the specified contract.
4141
* @example const functions = await web3data.contract.getFunctions('0x06012c8cf97bead5deae237070f9587f8e7a266d')
4242
*/
4343
getFunctions(hash) {
@@ -52,8 +52,8 @@ class Contract {
5252
/**
5353
* Retrieves the vulnerabilities audit for the specified contract (if available).
5454
*
55-
* @param {string} hash - The contract address.
56-
* @returns {Promise<object>} The vulnerabilities audit for the specified contract.
55+
* @param hash - The contract address.
56+
* @returns The vulnerabilities audit for the specified contract.
5757
* @example const audit = await web3data.contract.getAudit('0x06012c8cf97bead5deae237070f9587f8e7a266d')
5858
*/
5959
getSecurityAudit(hash) {
@@ -68,8 +68,8 @@ class Contract {
6868
/**
6969
* Retrieves the contract's abi.
7070
*
71-
* @param {string} hash - The contract address.
72-
* @returns {Promise<array>} The abi of the contract.
71+
* @param hash - The contract address.
72+
* @returns The abi of the contract.
7373
* @example const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
7474
*/
7575
getAbi(hash) {
@@ -80,8 +80,8 @@ class Contract {
8080
/**
8181
* Retrieves the contract's source code.
8282
*
83-
* @param {string} hash - The contract address.
84-
* @returns {Promise<string>} The source of the contract.
83+
* @param hash - The contract address.
84+
* @returns The source of the contract.
8585
* @example const source = await web3data.contract.getSourceCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
8686
*/
8787
getSourceCode(hash) {
@@ -96,8 +96,8 @@ class Contract {
9696
/**
9797
* Returns the contract's bytecode.
9898
*
99-
* @param {string} hash - The contract address.
100-
* @returns {Promise<string>} The contract's bytecode.
99+
* @param hash - The contract address.
100+
* @returns The contract's bytecode.
101101
* @example const code = await web3data.contract.getCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
102102
*/
103103
getCode(hash) {

src/signature.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1-
const {get, is} = require('./utils')
1+
const {get, is, throwIf, onError, onFulfilled} = require('./utils')
22
const {
33
SIGNATURES_ENDPOINT: ENDPOINT,
44
ERROR_MESSAGE_SIGNATURE_NO_HASH: NO_HASH
55
} = require('./constants')
66

7+
/**
8+
* Contains methods pertaining to the `/signatures` endpoint of Amberdata's API.
9+
*/
710
class Signature {
11+
/**
12+
* Creates an instance of Signature.
13+
*
14+
* @param web3data - The web3data instance.
15+
* @example
16+
*/
817
constructor(web3data) {
918
this.web3data = web3data
1019
}
1120

12-
get4Byte(hash) {
13-
if (is.notHash(hash)) return Promise.reject(new Error(NO_HASH))
14-
return get(this.web3data, {hash, endpoint: ENDPOINT})
21+
/**
22+
* Retrieves detailed information about the specified signature hash.
23+
*
24+
* @param hash - The (keccak 256) of the signature.
25+
* @returns Information pertaining to the specified signature hash.
26+
* @example const signatureDetails = await web3data.signature.getSignature('0xe2f0a05a')
27+
*/
28+
getSignature(hash) {
29+
throwIf(is.notHash(hash), NO_HASH)
30+
return get(this.web3data, {hash, endpoint: ENDPOINT}).then(
31+
onFulfilled,
32+
onError
33+
)
1534
}
1635
}
1736

test/signature.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import test from "ava"
2-
import {ERROR_MESSAGE_SIGNATURE_NO_HASH as NO_HASH, ADDRESS} from "../src/constants";
2+
import {ERROR_MESSAGE_SIGNATURE_NO_HASH as NO_HASH} from "../src/constants";
33
import {setUpPolly, getNewWeb3DataInstance} from "./utils";
44

5-
/**********************************
5+
/**********************************gs
66
* -------- Tests Setup ---------- *
77
**********************************/
88
test.before(t => {
@@ -25,8 +25,8 @@ test.beforeEach(t => {
2525
* @return {Promise<void>}
2626
*/
2727
let statusSuccess = async (t, { method, params = {} }) => {
28-
let response = await t.context.web3data.signature[method]('0xe2f0a05a')
29-
t.is(response.status, 200)
28+
const [signatureDetails] = await t.context.web3data.signature[method]('0xe2f0a05a')
29+
t.true(signatureDetails.hasProp('textSignature'))
3030
}
3131
statusSuccess.title = (providedTitle = '', input) => `Successfully calls ${input.method} and returns status of 200`
3232

@@ -46,4 +46,4 @@ let rejectsPromise = async (t, { method, params = {} }, errorMessage) => {
4646
}
4747
rejectsPromise.title = (providedTitle = '', input) => `throws exception when calling ${input} without hash`
4848

49-
test([statusSuccess, rejectsPromise], {method: 'get4Byte'}, NO_HASH)
49+
test([statusSuccess, rejectsPromise], {method: 'getSignature'}, NO_HASH)

0 commit comments

Comments
 (0)