-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements/refactoring/updates (#5)
* update Github workflows * add clickhouse methods * add native Bun fetch * update queries * update index * Update readme * remove lint workflow * update readme * add openapi3-ts * update comments * Add toJSON
- Loading branch information
1 parent
75fae9f
commit 79b2cc3
Showing
34 changed files
with
751 additions
and
788 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# API Server | ||
PORT=8080 | ||
HOSTNAME=localhost | ||
|
||
# Clickhouse Database | ||
HOST=http://127.0.0.1:8123 | ||
DATABASE=default | ||
USERNAME=default | ||
PASSWORD= | ||
MAX_LIMIT=500 | ||
|
||
# Logging | ||
VERBOSE=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,14 @@ | ||
name: Test | ||
name: Bun Test | ||
|
||
on: | ||
push: | ||
branches: [develop*, main] | ||
pull_request: | ||
branches: [develop*, main] | ||
on: push | ||
|
||
jobs: | ||
bun-test: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
environment: dev-test | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install bun | ||
uses: oven-sh/setup-bun@v1 | ||
|
||
- name: "Install Dependencies" | ||
run: | | ||
bun install | ||
- name: "Setup local Clickhouse DB" | ||
uses: metrico/[email protected] | ||
|
||
- name: "Insert mock data into Clickhouse DB for testing" | ||
run: | | ||
curl https://clickhouse.com/ | sh | ||
echo "CREATE DATABASE ${{ secrets.DB_NAME }}" > create.sql | ||
./clickhouse client --queries-file ./create.sql | ||
echo "USE ${{ secrets.DB_NAME }}; CREATE TABLE TotalSupply (address FixedString(40), supply Nullable(String),id String , block_id FixedString(64), module_hash FixedString(40),chain LowCardinality(String) ) ENGINE = MergeTree() ORDER BY (address); CREATE TABLE Contracts (address FixedString(40), name Nullable(String), symbol Nullable(String), decimals Nullable(String), id String , block_id FixedString(64), module_hash FixedString(40),chain LowCardinality(String)) ENGINE = MergeTree() ORDER BY (address); CREATE TABLE balance_changes (contract FixedString(40), owner Nullable(String), old_balance Nullable(String), new_balance Nullable(String), transaction_id Nullable(String), id String , block_id FixedString(64), module_hash FixedString(40),chain LowCardinality(String)) ENGINE = MergeTree() ORDER BY (contract); CREATE TABLE IF NOT EXISTS manifest ( module_hash FixedString(40), module_name String(), chain LowCardinality(String), type String(), ) ENGINE = ReplacingMergeTree PRIMARY KEY (module_hash) ORDER BY (module_hash, module_name); CREATE TABLE IF NOT EXISTS block ( block_id FixedString(64), block_number UInt32(), chain LowCardinality(String), timestamp DateTime64(3, 'UTC'), final_block Bool, ) ENGINE = ReplacingMergeTree PRIMARY KEY (block_id) ORDER BY (block_id, block_number, timestamp);" > setup.sql | ||
./clickhouse client --queries-file ./setup.sql | ||
echo "INSERT INTO ${{ secrets.DB_NAME }}.block (block_id, block_number, chain, timestamp,final_block) VALUES ('0006b5036d09b082543fe4306d98f6ad9b438fa4c139124106018fdfc90ad38f', 15010581, 'eth', '2022-06-23 01:43:01.000',true);" > block.sql | ||
./clickhouse client --queries-file ./block.sql | ||
echo "INSERT INTO ${{ secrets.DB_NAME }}.TotalSupply (address, supply, id, block_id,module_hash,chain) VALUES ('cb9df5dc2ed5d7d3972f601acfe35cdbe57341e0', '100000', '00000000000045166c45af0fc6e4cf31d9e14b9a', '0006b5036d09b082543fe4306d98f6ad9b438fa4c139124106018fdfc90ad38f','9a8fdd0be04bbe23f68ed4c38a02f7cbc96b86fb','eth');" > insert1.sql | ||
./clickhouse client --queries-file ./insert1.sql | ||
echo "INSERT INTO ${{ secrets.DB_NAME }}.Contracts (address, name, symbol, decimals,id, block_id,module_hash,chain) VALUES ('cb9df5dc2ed5d7d3972f601acfe35cdbe57341e0', 'wing', '$wing', '8','00000000000045166c45af0fc6e4cf31d9e14b9a', '0006b5036d09b082543fe4306d98f6ad9b438fa4c139124106018fdfc90ad38f','9a8fdd0be04bbe23f68ed4c38a02f7cbc96b86fb','eth');" > insert2.sql | ||
./clickhouse client --queries-file ./insert2.sql | ||
echo "INSERT INTO ${{ secrets.DB_NAME }}.balance_changes (contract, owner, old_balance, new_balance, transaction_id,id, block_id,module_hash,chain) VALUES ('c083e9947Cf02b8FfC7D3090AE9AEA72DF98FD47', '39fA8c5f2793459D6622857E7D9FbB4BD91766d3', '123123', '3423443', 'ab3612eed62a184eed2ae86bcad766183019cf40f82e5316f4d7c4e61f4baa44','00000000000045166c45af0fc6e4cf31d9e14b9a', '0006b5036d09b082543fe4306d98f6ad9b438fa4c139124106018fdfc90ad38f','9a8fdd0be04bbe23f68ed4c38a02f7cbc96b86fb','eth');" > insert3.sql | ||
./clickhouse client --queries-file ./insert3.sql | ||
- name: "Run test" | ||
run: | | ||
bun test | ||
env: | ||
HOSTNAME: ${{ vars.HOST}} | ||
PORT: ${{ vars.PORT }} | ||
DB_HOST: ${{ vars.DB_HOST }} | ||
DB_NAME: ${{ secrets.DB_NAME }} | ||
DB_USERNAME: ${{ secrets.DB_USERNAME }} | ||
DB_PASSWORD: "" | ||
- uses: actions/checkout@v3 | ||
- uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
- run: bun install | ||
- run: bun run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// from: https://github.com/pinax-network/substreams-clock-api/blob/main/index.ts | ||
import { config } from "./src/config"; | ||
import { logger } from "./src/logger"; | ||
import GET from "./src/fetch/GET"; | ||
import * as prometheus from "./src/prometheus.js"; | ||
|
||
if (config.verbose) logger.enable(); | ||
|
||
const app = Bun.serve({ | ||
hostname: config.hostname, | ||
port: config.port, | ||
fetch(req: Request) { | ||
if (req.method === "GET") return GET(req); | ||
prometheus.request_error.inc({pathname: new URL(req.url).pathname, status: 400}); | ||
return new Response("Invalid request", { status: 400 }); | ||
} | ||
}); | ||
|
||
logger.info(`Server listening on http://${app.hostname}:${app.port}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// from: https://github.com/pinax-network/substreams-clock-api/blob/main/src/clickhouse/createClient.ts | ||
import { createClient } from "@clickhouse/client-web"; | ||
import { ping } from "./ping"; | ||
import { APP_NAME, config } from "../config"; | ||
|
||
const client = createClient({ | ||
...config, | ||
clickhouse_settings: { | ||
allow_experimental_object_type: 1, | ||
}, | ||
application: APP_NAME, | ||
}) | ||
|
||
// These overrides should not be required but the @clickhouse/client-web instance | ||
// does not work well with Bun's implementation of Node streams. | ||
// https://github.com/oven-sh/bun/issues/5470 | ||
client.command = client.exec; | ||
client.ping = ping; | ||
|
||
export default client; |
Oops, something went wrong.