Skip to content

Commit 7a22358

Browse files
committed
feat: rebuild integration
1 parent 30cfd52 commit 7a22358

13 files changed

Lines changed: 225 additions & 237 deletions

File tree

.github/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--suppress HtmlDeprecatedAttribute -->
2+
3+
<div align="center">
4+
<h1>KYVE + EVM</h1>
5+
</div>
6+
7+
![banner](https://github.com/kyve-org/assets/raw/main/banners/EVM.png)
8+
9+
## Configuration
10+
11+
```json
12+
{
13+
"rpc": "",
14+
"github": "https://github.com/kyve-org/evm"
15+
}
16+
```
17+
18+
## Endpoints
19+
20+
- [`eth_blockNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc)
21+
- [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc)

.github/webhook.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
const Discord = require("webhook-discord");
1+
const Discord = require('webhook-discord');
22
const client = new Discord.Webhook(process.env.DISCORD);
33

44
const message = new Discord.MessageBuilder()
5-
.setColor("#58C6B2")
6-
.setTitle(":new: New Release :new:")
5+
.setColor('#58C6B2')
6+
.setTitle(':new: New Release :new:')
77
.setDescription(`\`@kyve/evm\` ${process.env.VERSION} released.`)
8-
.setURL(
9-
`https://github.com/KYVENetwork/evm/releases/tag/${process.env.VERSION}`
10-
)
11-
.setName("Release Bot");
8+
.setURL(`https://github.com/kyve-org/evm/releases/tag/${process.env.VERSION}`)
9+
.setName('Release Bot');
1210

11+
// noinspection JSIgnoredPromiseFromCall
1312
client.send(message);

.github/workflows/deployDev.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy
1+
name: Release
22

33
on:
44
release:
@@ -14,7 +14,7 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2
17+
- uses: actions/setup-node@v3
1818

1919
- name: Install yarn.
2020
run: npm install -g yarn
@@ -23,18 +23,18 @@ jobs:
2323
- name: Build.
2424
run: yarn build:binaries
2525

26-
- uses: actions/upload-artifact@v2
26+
- uses: actions/upload-artifact@v3
2727
with:
2828
name: kyve-evm-linux
29-
path: ./out/index-linux
30-
- uses: actions/upload-artifact@v2
29+
path: ./out/evm-linux
30+
- uses: actions/upload-artifact@v3
3131
with:
3232
name: kyve-evm-macos
33-
path: ./out/index-macos
34-
- uses: actions/upload-artifact@v2
33+
path: ./out/evm-macos
34+
- uses: actions/upload-artifact@v3
3535
with:
36-
name: kyve-evm-win.exe
37-
path: ./out/index-win.exe
36+
name: kyve-evm-win
37+
path: ./out/evm-win.exe
3838

3939
docker:
4040
name: Build and publish Docker container.
@@ -59,7 +59,7 @@ jobs:
5959

6060
steps:
6161
- uses: actions/checkout@v2
62-
- uses: actions/setup-node@v2
62+
- uses: actions/setup-node@v3
6363

6464
- name: Install yarn.
6565
run: npm install -g yarn

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
.idea
12
db
23
dist
34
logs
45
node_modules
56
out
67
.DS_Store
7-
arweave.json

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14-alpine
1+
FROM node:current-alpine
22

33
COPY package.json .
44
RUN yarn install

README.md

Lines changed: 0 additions & 74 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kyve/evm",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"license": "MIT",
55
"scripts": {
66
"build": "rimraf dist && tsc",
@@ -19,17 +19,18 @@
1919
],
2020
"outputPath": "out"
2121
},
22+
"prettier": {
23+
"singleQuote": true
24+
},
2225
"dependencies": {
23-
"@kyve/core": "^1.0.7",
24-
"ethers": "^5.5.3"
26+
"@kyve/core": "^1.0.8",
27+
"ethers": "^5.6.5"
2528
},
2629
"devDependencies": {
27-
"@types/node": "^17.0.10",
28-
"pkg": "^5.5.2",
29-
"prettier": "^2.5.1",
30+
"pkg": "^5.6.0",
31+
"prettier": "^2.6.2",
3032
"rimraf": "^3.0.2",
31-
"tslog": "^3.3.1",
32-
"typescript": "^4.5.4",
33+
"typescript": "^4.6.4",
3334
"webhook-discord": "^3.7.8"
3435
}
3536
}

src/index.ts

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,63 @@
1-
import KYVE from "@kyve/core";
2-
import { providers } from "ethers";
3-
import { version } from "../package.json";
1+
import KYVE from '@kyve/core';
2+
import { Network, Signature } from './types';
3+
import { fetchBlock } from './utils';
4+
import { name, version } from '../package.json';
45

5-
process.env.KYVE_RUNTIME = "@kyve/evm";
6+
process.env.KYVE_RUNTIME = name;
67
process.env.KYVE_VERSION = version;
78

89
KYVE.metrics.register.setDefaultLabels({
910
app: process.env.KYVE_RUNTIME,
1011
});
1112

12-
class EVM extends KYVE {
13-
// pull data item from source
13+
class KyveEvm extends KYVE {
1414
public async getDataItem(key: number): Promise<{ key: number; value: any }> {
15-
let provider;
1615
let block;
1716

18-
// setup provider for evm chain
1917
try {
20-
provider = new providers.StaticJsonRpcProvider(this.pool.config.rpc);
18+
let network: Network | undefined;
19+
if (this.pool.config.chainId && this.pool.config.chainName) {
20+
network = {
21+
chainId: this.pool.config.chainId,
22+
name: this.pool.config.chainName,
23+
};
24+
}
25+
26+
block = await fetchBlock(
27+
this.pool.config.rpc,
28+
key,
29+
await this.getSignature(),
30+
network
31+
);
2132
} catch (err) {
2233
this.logger.warn(
23-
` EXTERNAL ERROR: Failed to connect with rpc: ${this.pool.config.rpc}. Retrying ...`
34+
`⚠️ EXTERNAL ERROR: Failed to fetch block ${key}. Retrying ...`
2435
);
25-
// forward error to core
36+
2637
throw err;
2738
}
2839

29-
// try to fetch current block height
30-
try {
31-
const height = await provider.getBlockNumber();
40+
if (!block) throw new Error();
3241

33-
// throw error if requested block height is not available yet
34-
if (height < key) {
35-
this.logger.warn(
36-
` EXTERNAL ERROR: Requested block does not exist yet. Retrying ...`
37-
);
38-
throw new Error();
39-
}
40-
} catch (err) {
41-
this.logger.warn(
42-
` EXTERNAL ERROR: Failed to fetch current block height. Retrying ...`
43-
);
44-
// forward error to core
45-
throw err;
46-
}
42+
return { key, value: block };
43+
}
4744

48-
// fetch block with transactions at requested height
49-
try {
50-
block = await provider?.getBlockWithTransactions(key)!;
45+
private async getSignature(): Promise<Signature> {
46+
const address = await this.sdk.wallet.getAddress();
47+
const timestamp = new Date().valueOf().toString();
5148

52-
// delete transaction confirmations from block since they are not deterministic
53-
block.transactions.forEach(
54-
(transaction: Partial<providers.TransactionResponse>) =>
55-
delete transaction.confirmations
56-
);
57-
} catch (err) {
58-
this.logger.warn(
59-
` EXTERNAL ERROR: Failed to fetch data item from source at height ${key}. Retrying ...`
60-
);
61-
// forward error to core
62-
throw err;
63-
}
49+
const message = `${address}//${this.poolId}//${timestamp}`;
50+
51+
const { signature, pub_key } = await this.sdk.signString(message);
6452

6553
return {
66-
key,
67-
value: block,
54+
signature,
55+
pubKey: pub_key.value,
56+
poolId: this.poolId.toString(),
57+
timestamp,
6858
};
6959
}
7060
}
7161

72-
new EVM().start();
62+
// noinspection JSIgnoredPromiseFromCall
63+
new KyveEvm().start();

src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface Network {
2+
chainId: number;
3+
name: string;
4+
}
5+
6+
export interface Signature {
7+
signature: string;
8+
pubKey: string;
9+
poolId: string;
10+
timestamp: string;
11+
}

0 commit comments

Comments
 (0)