Skip to content

Commit 725cb7e

Browse files
committed
feat(contract): Method getSourceCode test + docs
1 parent 85cfa68 commit 725cb7e

File tree

5 files changed

+140
-776
lines changed

5 files changed

+140
-776
lines changed

dist/web3data.min.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,22 +2630,27 @@
26302630
*
26312631
* @param hash - The contract address.
26322632
* @returns The abi of the contract.
2633-
* @example
2634-
* const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
2633+
* @example const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
26352634
*/
26362635
getAbi(hash) {
26372636
throwIf$2(is$3.notHash(hash), NO_ADDRESS$2);
26382637
return this.getDetails(hash).then(({abi}) => abi)
26392638
}
26402639

2641-
getSourceCode(hash, filterOptions) {
2642-
if (is$3.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS$2))
2640+
/**
2641+
* Retrieves the contract's source code.
2642+
*
2643+
* @param hash - The contract address.
2644+
* @returns The source of the contract.
2645+
* @example const source = await web3data.contract.getSourceCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
2646+
*/
2647+
getSourceCode(hash) {
2648+
throwIf$2(is$3.notHash(hash), NO_ADDRESS$2);
26432649
return get$3(this.web3data, {
26442650
pathParam: hash,
26452651
endpoint: ENDPOINT$2,
2646-
subendpoint: 'source-code',
2647-
filterOptions
2648-
})
2652+
subendpoint: 'source-code'
2653+
}).then(onFulfilled$3, onError$3)
26492654
}
26502655

26512656
getCode(hash) {

docs/api.md

Lines changed: 90 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,39 @@ const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e
687687

688688

689689

690+
#### getSourceCode(hash)
691+
692+
693+
Retrieves the contract's source code.
694+
695+
696+
697+
698+
##### Parameters
699+
700+
| Name | Type | Description | |
701+
| ---- | ---- | ----------- | -------- |
702+
| hash | | The contract address. |   |
703+
704+
705+
706+
707+
##### Examples
708+
709+
```javascript
710+
const source = await web3data.contract.getSourceCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
711+
```
712+
713+
714+
##### Returns
715+
716+
717+
- The source of the contract.
718+
719+
720+
721+
722+
690723
### src/market.js
691724

692725

@@ -1136,15 +1169,27 @@ const batTokenAddress = web3data.market.getAssetAddresses('bat') const assetAddr
11361169

11371170

11381171

1139-
### src/utils.js
1172+
### src/web3data.js
11401173

11411174

11421175

1143-
#### get(web3data, subendpoint, endpoint, hash, pathParam, filterOptions)
1176+
#### Class: Web3DataFactory
11441177

11451178

1146-
Builds the endpoint url to pass to .rawQuery(). Checks for non empties and appends
1147-
the appropriate parameter(s) where applicable.
1179+
Contains common methods used in.
1180+
1181+
1182+
1183+
1184+
1185+
1186+
1187+
1188+
1189+
#### constructor(apiKey, options, blockchainId:, -, -)
1190+
1191+
1192+
Creates a Web3Data instance.
11481193

11491194

11501195

@@ -1153,12 +1198,11 @@ the appropriate parameter(s) where applicable.
11531198

11541199
| Name | Type | Description | |
11551200
| ---- | ---- | ----------- | -------- |
1156-
| web3data | | Instance on which to call .rawQuery(). |   |
1157-
| subendpoint | | The subendpoint. |   |
1158-
| endpoint | | The endpoint. |   |
1159-
| hash | | The address hash. |   |
1160-
| pathParam | | The path parameter. |   |
1161-
| filterOptions | | The filters associated with a given endpoint. |   |
1201+
| apiKey | | The Amberdata api key needed to access data. |   |
1202+
| options | `object` | Contains additional configuration options: |   |
1203+
| blockchainId: | | specifies the blockchain to get data from |   |
1204+
| - | | baseUrl: the base url of API calls |   |
1205+
| - | | websocketUrl: the websocket url to use |   |
11621206

11631207

11641208

@@ -1173,16 +1217,17 @@ the appropriate parameter(s) where applicable.
11731217
##### Returns
11741218

11751219

1176-
- Returns a Promise of the rawQuery request from web3data.
1220+
- `Void`
11771221

11781222

11791223

11801224

11811225

1182-
#### uuid(data)
1226+
#### rawQuery(url)
11831227

11841228

1185-
Generates a uuid see [this gist]() for more details.
1229+
Appends the API base url with the endpoint url. Then sends an
1230+
http request to the Amberdata API endpoint.
11861231

11871232

11881233

@@ -1191,7 +1236,7 @@ Generates a uuid see [this gist]() for more details.
11911236

11921237
| Name | Type | Description | |
11931238
| ---- | ---- | ----------- | -------- |
1194-
| data | | |   |
1239+
| url | | The endpoint url with any query/path params if set. |   |
11951240

11961241

11971242

@@ -1206,71 +1251,69 @@ Generates a uuid see [this gist]() for more details.
12061251
##### Returns
12071252

12081253

1209-
- `Void`
1254+
- The axios request object.
12101255

12111256

12121257

12131258

12141259

1215-
### src/web3data.js
1260+
#### rpc(method, params)
12161261

12171262

1263+
Method used to interact with web3api json rpc endpoints.
12181264

1219-
#### Class: Web3DataFactory
12201265

12211266

1222-
Contains common methods used in.
12231267

1268+
##### Parameters
12241269

1270+
| Name | Type | Description | |
1271+
| ---- | ---- | ----------- | -------- |
1272+
| method | | The json rpc method to call. |   |
1273+
| params | | The parameters to the json rpc call. |   |
12251274

12261275

12271276

12281277

1278+
##### Examples
12291279

1280+
```javascript
12301281

1282+
```
12311283

1232-
#### constructor(apiKey, options, blockchainId:, -, -)
12331284

1285+
##### Returns
12341286

1235-
Creates a Web3Data instance.
12361287

1288+
- Returns the json rpc result.
12371289

12381290

12391291

1240-
##### Parameters
12411292

1242-
| Name | Type | Description | |
1243-
| ---- | ---- | ----------- | -------- |
1244-
| apiKey | | The Amberdata api key needed to access data. |   |
1245-
| options | `object` | Contains additional configuration options: |   |
1246-
| blockchainId: | | specifies the blockchain to get data from |   |
1247-
| - | | baseUrl: the base url of API calls |   |
1248-
| - | | websocketUrl: the websocket url to use |   |
12491293

1294+
#### Class: Web3Data
12501295

12511296

1297+
Class Web3data contains methods for hitting Amberdata's
1298+
API endpoints.
12521299

1253-
##### Examples
12541300

1255-
```javascript
12561301

1257-
```
12581302

12591303

1260-
##### Returns
12611304

12621305

1263-
- `Void`
12641306

12651307

1308+
### src/utils.js
12661309

12671310

12681311

1269-
#### rawQuery(url)
1312+
#### get(web3data, subendpoint, endpoint, hash, pathParam, filterOptions)
12701313

12711314

1272-
Appends the API base url with the endpoint url. Then sends an
1273-
http request to the Amberdata API endpoint.
1315+
Builds the endpoint url to pass to .rawQuery(). Checks for non empties and appends
1316+
the appropriate parameter(s) where applicable.
12741317

12751318

12761319

@@ -1279,7 +1322,12 @@ http request to the Amberdata API endpoint.
12791322

12801323
| Name | Type | Description | |
12811324
| ---- | ---- | ----------- | -------- |
1282-
| url | | The endpoint url with any query/path params if set. |   |
1325+
| web3data | | Instance on which to call .rawQuery(). |   |
1326+
| subendpoint | | The subendpoint. |   |
1327+
| endpoint | | The endpoint. |   |
1328+
| hash | | The address hash. |   |
1329+
| pathParam | | The path parameter. |   |
1330+
| filterOptions | | The filters associated with a given endpoint. |   |
12831331

12841332

12851333

@@ -1294,16 +1342,16 @@ http request to the Amberdata API endpoint.
12941342
##### Returns
12951343

12961344

1297-
- The axios request object.
1345+
- Returns a Promise of the rawQuery request from web3data.
12981346

12991347

13001348

13011349

13021350

1303-
#### rpc(method, params)
1351+
#### uuid(data)
13041352

13051353

1306-
Method used to interact with web3api json rpc endpoints.
1354+
Generates a uuid see [this gist]() for more details.
13071355

13081356

13091357

@@ -1312,8 +1360,7 @@ Method used to interact with web3api json rpc endpoints.
13121360

13131361
| Name | Type | Description | |
13141362
| ---- | ---- | ----------- | -------- |
1315-
| method | | The json rpc method to call. |   |
1316-
| params | | The parameters to the json rpc call. |   |
1363+
| data | | |   |
13171364

13181365

13191366

@@ -1328,21 +1375,7 @@ Method used to interact with web3api json rpc endpoints.
13281375
##### Returns
13291376

13301377

1331-
- Returns the json rpc result.
1332-
1333-
1334-
1335-
1336-
1337-
#### Class: Web3Data
1338-
1339-
1340-
Class Web3data contains methods for hitting Amberdata's
1341-
API endpoints.
1342-
1343-
1344-
1345-
1378+
- `Void`
13461379

13471380

13481381

src/contract.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,27 @@ class Contract {
5858
*
5959
* @param hash - The contract address.
6060
* @returns The abi of the contract.
61-
* @example
62-
* const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
61+
* @example const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
6362
*/
6463
getAbi(hash) {
6564
throwIf(is.notHash(hash), NO_ADDRESS)
6665
return this.getDetails(hash).then(({abi}) => abi)
6766
}
6867

69-
getSourceCode(hash, filterOptions) {
70-
if (is.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS))
68+
/**
69+
* Retrieves the contract's source code.
70+
*
71+
* @param hash - The contract address.
72+
* @returns The source of the contract.
73+
* @example const source = await web3data.contract.getSourceCode('0x06012c8cf97bead5deae237070f9587f8e7a266d')
74+
*/
75+
getSourceCode(hash) {
76+
throwIf(is.notHash(hash), NO_ADDRESS)
7177
return get(this.web3data, {
7278
pathParam: hash,
7379
endpoint: ENDPOINT,
74-
subendpoint: 'source-code',
75-
filterOptions
76-
})
80+
subendpoint: 'source-code'
81+
}).then(onFulfilled, onError)
7782
}
7883

7984
getCode(hash) {

test/contract.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ test('throws exception when calling getAbi without hash', async t => {
6565
});
6666

6767
/*********** Test getSourceCode() ***********/
68-
test.skip('Successfully gets contract source code', async t => {
69-
let response = await t.context.web3data.contract.getSourceCode(TOKEN_ADDRESS);
70-
t.is(response.status, 200)
68+
test.only('Successfully gets contract source code', async t => {
69+
const source = await t.context.web3data.contract.getSourceCode(TOKEN_ADDRESS);
70+
t.is(typeof source, 'string')
7171
});
72-
test.skip('throws exception when calling getSourceCode without hash', async t => {
72+
test('throws exception when calling getSourceCode without hash', async t => {
7373
await t.throwsAsync(async () => {
7474
await t.context.web3data.contract.getSourceCode()
7575
}, { instanceOf: Error, message: 'No contract address supplied' });

test/recordings/contract_710824451/recording.har

Lines changed: 22 additions & 701 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)