Skip to content

Commit 3b34129

Browse files
Merge pull request #60 from web3data/feat/signature
Feat/signature
2 parents 923f8e8 + 64ef561 commit 3b34129

File tree

9 files changed

+469
-71
lines changed

9 files changed

+469
-71
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: 216 additions & 1 deletion
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

@@ -782,6 +782,72 @@ const details = await web3data.contract.getDetails('0x06012c8cf97bead5deae237070
782782

783783

784784

785+
#### getFunctions(hash)
786+
787+
788+
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.
789+
790+
791+
792+
793+
##### Parameters
794+
795+
| Name | Type | Description | |
796+
| ---- | ---- | ----------- | -------- |
797+
| hash | | The contract address. |   |
798+
799+
800+
801+
802+
##### Examples
803+
804+
```javascript
805+
const functions = await web3data.contract.getFunctions('0x06012c8cf97bead5deae237070f9587f8e7a266d')
806+
```
807+
808+
809+
##### Returns
810+
811+
812+
- The functions or decompiled functions of the specified contract.
813+
814+
815+
816+
817+
818+
#### getSecurityAudit(hash)
819+
820+
821+
Retrieves the vulnerabilities audit for the specified contract (if available).
822+
823+
824+
825+
826+
##### Parameters
827+
828+
| Name | Type | Description | |
829+
| ---- | ---- | ----------- | -------- |
830+
| hash | | The contract address. |   |
831+
832+
833+
834+
835+
##### Examples
836+
837+
```javascript
838+
const audit = await web3data.contract.getAudit('0x06012c8cf97bead5deae237070f9587f8e7a266d')
839+
```
840+
841+
842+
##### Returns
843+
844+
845+
- The vulnerabilities audit for the specified contract.
846+
847+
848+
849+
850+
785851
#### getAbi(hash)
786852

787853

@@ -848,6 +914,39 @@ const source = await web3data.contract.getSourceCode('0x06012c8cf97bead5deae2370
848914

849915

850916

917+
#### getCode(hash)
918+
919+
920+
Returns the contract's bytecode.
921+
922+
923+
924+
925+
##### Parameters
926+
927+
| Name | Type | Description | |
928+
| ---- | ---- | ----------- | -------- |
929+
| hash | | The contract address. |   |
930+
931+
932+
933+
934+
##### Examples
935+
936+
```javascript
937+
const code = await web3data.contract.getCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
938+
```
939+
940+
941+
##### Returns
942+
943+
944+
- The contract's bytecode.
945+
946+
947+
948+
949+
851950
### src/market.js
852951

853952

@@ -1297,6 +1396,122 @@ const batTokenAddress = web3data.market.getAssetAddresses('bat') const assetAddr
12971396

12981397

12991398

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 | `object` | The web3data instance. |   |
1429+
1430+
1431+
1432+
1433+
##### Examples
1434+
1435+
```javascript
1436+
new Signature(new Web3Data('API_KEY'))
1437+
```
1438+
1439+
1440+
##### Returns
1441+
1442+
1443+
- `Void`
1444+
1445+
1446+
1447+
1448+
1449+
#### getAudit(hash)
1450+
1451+
1452+
Alias for getSignature.
1453+
1454+
1455+
1456+
1457+
##### Parameters
1458+
1459+
| Name | Type | Description | |
1460+
| ---- | ---- | ----------- | -------- |
1461+
| hash | `string` | The (keccak 256) of the signature. |   |
1462+
1463+
1464+
1465+
1466+
##### Examples
1467+
1468+
```javascript
1469+
const signatureDetails = await web3data.signature.getAudit('0xe2f0a05a')
1470+
```
1471+
1472+
1473+
##### Returns
1474+
1475+
1476+
- `Promise.<Array>` Information pertaining to the specified signature hash.
1477+
1478+
1479+
1480+
1481+
1482+
#### getSignature(hash)
1483+
1484+
1485+
Retrieves detailed information about the specified signature hash.
1486+
1487+
1488+
1489+
1490+
##### Parameters
1491+
1492+
| Name | Type | Description | |
1493+
| ---- | ---- | ----------- | -------- |
1494+
| hash | `string` | The (keccak 256) of the signature. | &nbsp; |
1495+
1496+
1497+
1498+
1499+
##### Examples
1500+
1501+
```javascript
1502+
const signatureDetails = await web3data.signature.getSignature('0xe2f0a05a')
1503+
```
1504+
1505+
1506+
##### Returns
1507+
1508+
1509+
- `Promise.<Array>` Information pertaining to the specified signature hash.
1510+
1511+
1512+
1513+
1514+
13001515
### src/transaction.js
13011516

13021517

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"jsdoc/implements-on-classes": 1,
102102
"jsdoc/match-description": 1,
103103
"jsdoc/newline-after-description": 1,
104-
"jsdoc/no-types": 1,
105104
"jsdoc/no-undefined-types": 1,
106105
"jsdoc/require-description": 1,
107106
"jsdoc/require-description-complete-sentence": 1,

src/contract.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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
/**
@@ -33,24 +33,36 @@ class Contract {
3333
}).then(onFulfilled, onError)
3434
}
3535

36-
getFunctions(hash, filterOptions) {
36+
/**
37+
* 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.
38+
*
39+
* @param hash - The contract address.
40+
* @returns The functions or decompiled functions of the specified contract.
41+
* @example const functions = await web3data.contract.getFunctions('0x06012c8cf97bead5deae237070f9587f8e7a266d')
42+
*/
43+
getFunctions(hash) {
3744
if (is.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS))
3845
return get(this.web3data, {
3946
pathParam: hash,
4047
endpoint: ENDPOINT,
41-
subendpoint: 'functions',
42-
filterOptions
43-
})
48+
subendpoint: 'functions'
49+
}).then(onFulfilled, onError)
4450
}
4551

46-
getAudit(hash, filterOptions) {
52+
/**
53+
* Retrieves the vulnerabilities audit for the specified contract (if available).
54+
*
55+
* @param hash - The contract address.
56+
* @returns The vulnerabilities audit for the specified contract.
57+
* @example const audit = await web3data.contract.getAudit('0x06012c8cf97bead5deae237070f9587f8e7a266d')
58+
*/
59+
getSecurityAudit(hash) {
4760
if (is.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS))
4861
return get(this.web3data, {
4962
pathParam: hash,
5063
endpoint: ENDPOINT,
51-
subendpoint: 'audit',
52-
filterOptions
53-
})
64+
subendpoint: 'audit'
65+
}).then(onFulfilled, onError)
5466
}
5567

5668
/**
@@ -81,6 +93,13 @@ class Contract {
8193
}).then(onFulfilled, onError)
8294
}
8395

96+
/**
97+
* Returns the contract's bytecode.
98+
*
99+
* @param hash - The contract address.
100+
* @returns The contract's bytecode.
101+
* @example const code = await web3data.contract.getCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
102+
*/
84103
getCode(hash) {
85104
return this.getDetails(hash).then(details => details.bytecode || '0x')
86105
}

src/signature.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
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 {object} web3data - The web3data instance.
15+
* @example new Signature(new Web3Data('API_KEY'))
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+
* Alias for getSignature.
23+
*
24+
* @param {string} hash - The (keccak 256) of the signature.
25+
* @returns {Promise<Array>} Information pertaining to the specified signature hash.
26+
* @example const signatureDetails = await web3data.signature.getAudit('0xe2f0a05a')
27+
*/
28+
getAudit(hash) {
29+
return this.getSignature(hash)
30+
}
31+
32+
/**
33+
* Retrieves detailed information about the specified signature hash.
34+
*
35+
* @param {string} hash - The (keccak 256) of the signature.
36+
* @returns {Promise<Array>} Information pertaining to the specified signature hash.
37+
* @example const signatureDetails = await web3data.signature.getSignature('0xe2f0a05a')
38+
*/
39+
getSignature(hash) {
40+
throwIf(is.notHash(hash), NO_HASH)
41+
return get(this.web3data, {hash, endpoint: ENDPOINT}).then(
42+
onFulfilled,
43+
onError
44+
)
1545
}
1646
}
1747

src/web3data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const WebSocketClient = require('./websocket')
2424

2525
/**
2626
* Contains common methods used in.
27+
*
2728
* @private
2829
*/
2930
class Web3DataFactory {

0 commit comments

Comments
 (0)