Skip to content

Commit 0395d74

Browse files
jcorteslcaresia
authored andcommitted
[Components] beaconchain (#14647)
1 parent 55d2e93 commit 0395d74

File tree

8 files changed

+221
-8
lines changed

8 files changed

+221
-8
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import app from "../../beaconchain.app.mjs";
2+
3+
export default {
4+
key: "beaconchain-get-epoch",
5+
name: "Get Epoch",
6+
description: "Returns information for a specified epoch by the epoch number or an epoch tag (can be latest or finalized). [See the documentation](https://beaconcha.in/api/v1/docs/index.html#/Epoch/get_api_v1_epoch__epoch_)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
epoch: {
12+
propDefinition: [
13+
app,
14+
"epoch",
15+
],
16+
},
17+
},
18+
methods: {
19+
getEpoch({
20+
epoch, ...args
21+
} = {}) {
22+
return this.app._makeRequest({
23+
path: `/epoch/${epoch}`,
24+
...args,
25+
});
26+
},
27+
},
28+
async run({ $ }) {
29+
const {
30+
getEpoch,
31+
epoch,
32+
} = this;
33+
34+
const response = await getEpoch({
35+
$,
36+
epoch,
37+
});
38+
39+
$.export("$summary", `Successfully retrieved epoch \`${response.data.epoch}\`.`);
40+
return response;
41+
},
42+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import app from "../../beaconchain.app.mjs";
2+
3+
export default {
4+
key: "beaconchain-get-execution-blocks",
5+
name: "Get Execution Blocks",
6+
description: "Retrieve execution blocks by execution block number. [See the documentation](https://beaconcha.in/api/v1/docs/index.html#/Execution/get_api_v1_execution_block__blockNumber_)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
blockNumbers: {
12+
type: "string[]",
13+
label: "Block Number",
14+
description: "Enter one or more execution block numbers, up to a maximum of 100.",
15+
},
16+
},
17+
methods: {
18+
getExecutionBlocks({
19+
blockNumber, ...args
20+
} = {}) {
21+
return this.app._makeRequest({
22+
path: `/execution/block/${blockNumber}`,
23+
...args,
24+
});
25+
},
26+
},
27+
async run({ $ }) {
28+
const {
29+
getExecutionBlocks,
30+
blockNumbers,
31+
} = this;
32+
33+
const response = await getExecutionBlocks({
34+
$,
35+
blockNumber: Array.isArray(blockNumbers)
36+
? blockNumbers.map((value) => value.trim()).join(",")
37+
: blockNumbers,
38+
});
39+
40+
$.export("$summary", "Successfully retrieved execution blocks.");
41+
return response;
42+
},
43+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import app from "../../beaconchain.app.mjs";
2+
3+
export default {
4+
key: "beaconchain-get-slots",
5+
name: "Get Slots",
6+
description: "Returns all slots for a specified epoch. [See the documentation](https://beaconcha.in/api/v1/docs/index.html#/Epoch/get_api_v1_epoch__epoch__slots)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
epoch: {
12+
description: "Returns all slots for a specified epoch.",
13+
propDefinition: [
14+
app,
15+
"epoch",
16+
],
17+
},
18+
},
19+
methods: {
20+
getEpochSlots({
21+
epoch, ...args
22+
} = {}) {
23+
return this.app._makeRequest({
24+
path: `/epoch/${epoch}/slots`,
25+
...args,
26+
});
27+
},
28+
},
29+
async run({ $ }) {
30+
const {
31+
getEpochSlots,
32+
epoch,
33+
} = this;
34+
35+
const response = await getEpochSlots({
36+
$,
37+
epoch,
38+
});
39+
40+
$.export("$summary", `Successfully retrieved \`${response.data.length}\` slot(s).`);
41+
return response;
42+
},
43+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import app from "../../beaconchain.app.mjs";
2+
3+
export default {
4+
key: "beaconchain-get-validators",
5+
name: "Get Validators",
6+
description: "Returns information for all validators up to 100 by index or public key. [See the documentation](https://beaconcha.in/api/v1/docs/index.html#/Validator/get_api_v1_validator__indexOrPubkey_).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
indexesOrPubkeys: {
12+
type: "string[]",
13+
label: "Validator Indexes Or Public Keys",
14+
description: "Enter up to 100 validator indices or public keys.",
15+
},
16+
},
17+
methods: {
18+
getValidators({
19+
indexOrPubkey, ...args
20+
} = {}) {
21+
return this.app._makeRequest({
22+
path: `/validator/${indexOrPubkey}`,
23+
...args,
24+
});
25+
},
26+
},
27+
async run({ $ }) {
28+
const {
29+
getValidators,
30+
indexesOrPubkeys,
31+
} = this;
32+
33+
const response = await getValidators({
34+
$,
35+
indexOrPubkey: Array.isArray(indexesOrPubkeys)
36+
? indexesOrPubkeys.map((value) => value.trim()).join(",")
37+
: indexesOrPubkeys,
38+
});
39+
40+
$.export("$summary", "Successfully retrieved validators.");
41+
return response;
42+
},
43+
};
Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "beaconchain",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
epoch: {
9+
type: "string",
10+
label: "Epoch",
11+
description: "Epoch number, the string `latest` or the string `finalized`.",
12+
},
13+
},
514
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
15+
getUrl(path) {
16+
return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`;
17+
},
18+
getHeaders(headers) {
19+
return {
20+
...headers,
21+
"apikey": `${this.$auth.api_key}`,
22+
};
23+
},
24+
_makeRequest({
25+
$ = this, path, headers, ...args
26+
} = {}) {
27+
return axios($, {
28+
...args,
29+
url: this.getUrl(path),
30+
headers: this.getHeaders(headers),
31+
});
32+
},
33+
post(args = {}) {
34+
return this._makeRequest({
35+
method: "POST",
36+
...args,
37+
});
938
},
1039
},
11-
};
40+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const BASE_URL = "https://beaconcha.in";
2+
const VERSION_PATH = "/api/v1";
3+
4+
export default {
5+
BASE_URL,
6+
VERSION_PATH,
7+
};

components/beaconchain/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/beaconchain",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Beaconchain Components",
55
"main": "beaconchain.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "3.0.3"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)