Skip to content

Commit

Permalink
fix: fixing PR checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Jun 28, 2024
1 parent b3e778c commit 79a6b55
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 167 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
27 changes: 27 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"root": true,
"ignorePatterns": ["dist/*", "node_modules/**"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"prettier/prettier": "warn",
"no-console": "warn",
"sort-imports": [
"warn",
{
"ignoreCase": true,
"ignoreDeclarationSort": true
}
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "warn",
"no-inner-declarations": "off"
}
}
13 changes: 3 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@ jobs:
uses: actions/checkout@v2

- name: Install Bun
run: |
curl -fsSL https://bun.sh/install | bash
echo 'export BUN_INSTALL="$HOME/.bun"' >> $GITHUB_ENV
echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> $GITHUB_ENV
source $GITHUB_ENV
- name: Verify Bun installation
run: bun --version
uses: oven-sh/setup-bun@v1

- name: Install dependencies
run: bun install

- name: Run checks
run: bun run make check
run: make check

- name: Run tests
run: bun run make test
run: make test
9 changes: 9 additions & 0 deletions .prettierc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
arrowParens: 'always'
bracketSpacing: false
endOfLine: 'lf'
printWidth: 100
semi: false
singleQuote: true
tabWidth: 4
trailingComma: 'es5'
parser: typescript
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ test: build node_modules

.PHONY: check
check: node_modules
@${BIN}/eslint src --ext .ts --max-warnings 0 --format unix && echo "Ok"
@${BIN}/eslint "src/**/*.ts" "tests/**/*.ts" --max-warnings 0 --format unix && echo "Ok"

.PHONY: format
format: node_modules
@${BIN}/eslint src --ext .ts --fix
@${BIN}/eslint "src/**/*.ts" "tests/**/*.ts" --ext .ts --fix

.PHONY: distclean
distclean: clean
Expand Down
Binary file modified bun.lockb
Binary file not shown.
56 changes: 32 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
{
"name": "lighthouse",
"module": "src/index.ts",
"type": "module",
"scripts": {
"start": "bun src/index.ts",
"build": "bun build src/index.ts --compile --outfile dist/lighthouse",
"dev": "bun --hot src/index.ts"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"overrides": {
"@wharfkit/antelope": "^1.0.7"
},
"dependencies": {
"@wharfkit/antelope": "^1.0.7",
"@wharfkit/common": "^1.2.2",
"bun-types": "latest",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0"
},
"devDependencies": {
"@types/bun": "^1.0.8"
}
"name": "lighthouse",
"module": "src/index.ts",
"type": "module",
"scripts": {
"start": "bun src/index.ts",
"build": "bun build src/index.ts --compile --outfile dist/lighthouse",
"dev": "bun --hot src/index.ts"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"overrides": {
"@wharfkit/antelope": "^1.0.7"
},
"dependencies": {
"@wharfkit/antelope": "^1.0.7",
"@wharfkit/common": "^1.2.2"
},
"devDependencies": {
"@types/bun": "^1.0.8",
"@types/mocha": "^10.0.7",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"bun-types": "latest",
"chai": "^5.1.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"mocha": "^10.5.2",
"prettier-plugin-svelte": "^3.2.5",
"svelte-eslint-parser": "^0.39.2",
"typescript-eslint": "^7.14.1"
}
}
70 changes: 32 additions & 38 deletions src/chains.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
import { ChainDefinition, Chains } from "@wharfkit/common";

export type Chain = ChainDefinition | {
id: string;
name: string;
url: string;
};
import { Chains } from '@wharfkit/common';

const AYETU_MAINNET = {
id: "9b06067cf9f0a293e854cbdbcf4bc0292bbf1137dd01d3d9300f403706444504",
name: "Ayetu",
url: "https://mainnet.ayetu.net",
id: '9b06067cf9f0a293e854cbdbcf4bc0292bbf1137dd01d3d9300f403706444504',
name: 'Ayetu',
url: 'https://mainnet.ayetu.net'
};

const KOY_MAINNET = {
id: "adf3860dc671acafa2e4ce7ab4fd90920a487e8e82a36e8b4364aad5129552cd",
name: "KOY",
url: "https://api.mainnet.koynetwork.io",
id: 'adf3860dc671acafa2e4ce7ab4fd90920a487e8e82a36e8b4364aad5129552cd',
name: 'KOY',
url: 'https://api.mainnet.koynetwork.io'
};

const AYETU_TESTNET = {
id: "38b20c9055b39035eaee7fdf450ce9b2572024bcc6d4ee8cddd50662a0cdeff1",
name: "Ayetu (Testnet)",
url: "https://testnet.ayetu.net",
}
id: '38b20c9055b39035eaee7fdf450ce9b2572024bcc6d4ee8cddd50662a0cdeff1',
name: 'Ayetu (Testnet)',
url: 'https://testnet.ayetu.net'
};

const KOY_TESTNET = {
id: "181e289803751d4e0fc257fd186edaa6df8169e28631f1bf63fc9287a80cfb5f",
name: "KOY (Testnet)",
url: "https://api.testnet.koynetwork.io",
}
id: '181e289803751d4e0fc257fd186edaa6df8169e28631f1bf63fc9287a80cfb5f',
name: 'KOY (Testnet)',
url: 'https://api.testnet.koynetwork.io'
};

export const MAINNET_CHAINS = [
Chains.EOS,
Chains.Telos,
Chains.WAX,
Chains.Proton,
Chains.Libre,
Chains.UX,
Chains.FIO,
AYETU_MAINNET,
KOY_MAINNET,
Chains.EOS,
Chains.Telos,
Chains.WAX,
Chains.Proton,
Chains.Libre,
Chains.UX,
Chains.FIO,
AYETU_MAINNET,
KOY_MAINNET
];

export const TESTNET_CHAINS = [
Chains.TelosTestnet,
Chains.WAXTestnet,
Chains.LibreTestnet,
Chains.FIOTestnet,
Chains.Jungle4,
AYETU_TESTNET,
KOY_TESTNET,
];
Chains.TelosTestnet,
Chains.WAXTestnet,
Chains.LibreTestnet,
Chains.FIOTestnet,
Chains.Jungle4,
AYETU_TESTNET,
KOY_TESTNET
];
98 changes: 54 additions & 44 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,74 @@
import { serve } from "bun";
import { APIClient, PublicKey } from "@wharfkit/antelope";
import { MAINNET_CHAINS, TESTNET_CHAINS, type Chain } from "./chains";
import { serve } from 'bun';
import { API, APIClient, PublicKey } from '@wharfkit/antelope';
import { MAINNET_CHAINS, TESTNET_CHAINS } from './chains';
import type { Chain } from './types';

export const accountLookup = async (req: Request) => {
const url = new URL(req.url);
const key = url.pathname.split("/")[2];
const includeTestnets = url.searchParams.get("includeTestnets") === "true";
const url = new URL(req.url);
const key = url.pathname.split('/')[2];
const includeTestnets = url.searchParams.get('includeTestnets') === 'true';

let publicKey: PublicKey;
let publicKey: PublicKey;

try {
publicKey = PublicKey.from(key)
} catch (error) {
return new Response(JSON.stringify({ error: "Invalid public key" }), { status: 400 });
}
try {
publicKey = PublicKey.from(key);
} catch (error) {
return new Response(JSON.stringify({ error: 'Invalid public key' }), { status: 400 });
}

const chains: Chain[] = includeTestnets ? [...MAINNET_CHAINS, ...TESTNET_CHAINS] : MAINNET_CHAINS;
const lookups = (await Promise.all(chains.map(chain => lookupNetwork(publicKey, chain)))).filter(({ accounts }) => accounts.length > 0)
const chains: Chain[] = includeTestnets ? [...MAINNET_CHAINS, ...TESTNET_CHAINS] : MAINNET_CHAINS;
const lookups = (
await Promise.all(chains.map((chain) => lookupNetwork(publicKey, chain)))
).filter(({ accounts }) => accounts.length > 0);

const networkAccounts = lookups.map(({ chain, accounts }) => ({
network: chain.name,
chainId: chain.id,
accounts,
}));
const networkAccounts = lookups.map(({ chain, accounts }) => ({
network: chain.name,
chainId: chain.id,
accounts
}));

const totalAccounts = networkAccounts.reduce((total, { accounts }) => total + accounts.length, 0);
console.log(`Found ${totalAccounts} auth(s) across ${networkAccounts.length} network(s)`);
const totalAccounts = networkAccounts.reduce((total, { accounts }) => total + accounts.length, 0);
log(`Found ${totalAccounts} auth(s) across ${networkAccounts.length} network(s)`);

return new Response(JSON.stringify(networkAccounts));
return new Response(JSON.stringify(networkAccounts));
};

export const lookupNetwork = async (publicKey: PublicKey, chain: Chain, apiClient?: APIClient) => {
try {
const accounts = await networkRequest(publicKey, chain, apiClient);
return { chain, accounts };
} catch (error) {
console.warn(`Lookup error on ${chain.name}: ${error}`);
return { chain, accounts: [] };;
}
try {
const accounts = await networkRequest(publicKey, chain, apiClient);
return { chain, accounts };
} catch (error) {
log(`Lookup error on ${chain.name}: ${error}`);
return { chain, accounts: [] };
}
};

const networkRequest = async (publicKey: PublicKey, chain: Chain, apiClient?: APIClient) => {
const client = apiClient || new APIClient(chain);
const response = await client.v1.chain.get_accounts_by_authorizers({ keys: [publicKey] });
return response.accounts.map((account: any) => ({
actor: account.account_name,
permission: account.permission_name,
}));
const client = apiClient || new APIClient(chain);
const response: API.v1.AccountsByAuthorizers = await client.v1.chain.get_accounts_by_authorizers({
keys: [publicKey]
});
return response.accounts.map((account) => ({
actor: account.account_name,
permission: account.permission_name
}));
};

function log(message: string) {
// eslint-disable-next-line no-console
console.warn(message);
}

serve({
fetch(req: Request) {
const url = new URL(req.url);
if (url.pathname.startsWith("/lookup")) {
return accountLookup(req);
}
fetch(req: Request) {
const url = new URL(req.url);
if (url.pathname.startsWith('/lookup')) {
return accountLookup(req);
}

return new Response("πŸ’‘πŸ ", { status: 200 });
},
port: 3000,
return new Response('πŸ’‘πŸ ', { status: 200 });
},
port: 3000
});

console.log('Server running at http://localhost:3000/ πŸš€')
log('Server running at http://localhost:3000/ πŸš€');
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ChainDefinition } from '@wharfkit/common';

export type Chain =
| ChainDefinition
| {
id: string;
name: string;
url: string;
};
Loading

0 comments on commit 79a6b55

Please sign in to comment.