Skip to content

Commit

Permalink
Add lint command (#29)
Browse files Browse the repository at this point in the history
* Add eslint script command

* Fix eslint warnings

* Fix lint-staged config
  • Loading branch information
gndelia authored Nov 7, 2024
1 parent 51f9b9b commit 3eecd27
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 65 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"extends": ["bloq", "prettier"],
"ignorePatterns": ["_esm/*", "_types/*"],
"overrides": [
{
"extends": ["bloq/typescript", "prettier"],
"files": ["*.ts"]
"files": ["src/**/*.ts"],
"rules": {
"camelcase": [
"off",
{
"allow": ["btc_", "l2_"]
}
]
}
},
{
"extends": ["bloq/markdown"],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
_esm
_types
.DS_Store
.eslintcache
.vscode
node_modules
tsconfig.tsbuildinfo
3 changes: 2 additions & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"!(package.json)": ["prettier --ignore-unknown --write"],
"!(*.{js,md,ts,tsx,yml}|package.json)": ["prettier --ignore-unknown --write"],
"*.{js,md,ts,tsx,yml}": ["eslint --cache --fix --quiet", "prettier --write"],
"package.json": ["better-sort-package-json", "prettier --write"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"clean": "rm -rf ./_esm ./_types",
"deps:check": "knip",
"format:check": "prettier --check .",
"lint": "eslint --cache .",
"prepublishOnly": "npm run build",
"tsc": "tsc --noEmit"
},
Expand Down
29 changes: 14 additions & 15 deletions src/actions/public/bitcoin-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,30 @@ export function getBitcoinAddressBalance(
) {
const { btcAddress } = parameters;
return readContract(client, {
address: bitcoinKitTxAddresses[client.chain!.id],
abi: bitcoinKitTxsAbi,
functionName: "getBitcoinAddressBalance",
address: bitcoinKitTxAddresses[client.chain!.id],
args: [btcAddress],
functionName: "getBitcoinAddressBalance",
});
}

export function getHeaderN(client: Client, parameters: { height: number }) {
const { height } = parameters;
return readContract(client, {
address: bitcoinKitTxAddresses[client.chain!.id],
abi: bitcoinKitTxsAbi,
functionName: "getHeaderN",
address: bitcoinKitTxAddresses[client.chain!.id],
args: [height],
functionName: "getHeaderN",
});
}

export function getLastHeader(client: Client) {
return readContract(client, {
address: bitcoinKitTxAddresses[client.chain!.id],
export const getLastHeader = (client: Client) =>
readContract(client, {
abi: bitcoinKitTxsAbi,
functionName: "getLastHeader",
address: bitcoinKitTxAddresses[client.chain!.id],
args: [],
functionName: "getLastHeader",
});
}

export function getTransactionByTxId(
client: Client,
Expand All @@ -45,20 +44,20 @@ export function getTransactionByTxId(
const { txId } = parameters;
const hash: Hash = isHash(txId) ? txId : `0x${txId}`;
return readContract(client, {
address: bitcoinKitTxAddresses[client.chain!.id],
abi: bitcoinKitTxsAbi,
functionName: "getTransactionByTxId",
address: bitcoinKitTxAddresses[client.chain!.id],
args: [hash],
functionName: "getTransactionByTxId",
});
}

export function getTxConfirmations(client: Client, parameters: { txId: Hash }) {
const { txId } = parameters;
return readContract(client, {
address: bitcoinKitTxAddresses[client.chain!.id],
abi: bitcoinKitTxsAbi,
functionName: "getTxConfirmations",
address: bitcoinKitTxAddresses[client.chain!.id],
args: [txId],
functionName: "getTxConfirmations",
});
}

Expand All @@ -68,9 +67,9 @@ export function getUtxosForBitcoinAddress(
) {
const { btcAddress, pageNumber, pageSize } = parameters;
return readContract(client, {
address: bitcoinKitTxAddresses[client.chain!.id],
abi: bitcoinKitTxsAbi,
functionName: "getUTXOsForBitcoinAddress",
address: bitcoinKitTxAddresses[client.chain!.id],
args: [btcAddress, pageNumber, pageSize],
functionName: "getUTXOsForBitcoinAddress",
});
}
2 changes: 1 addition & 1 deletion src/actions/public/bitcoin-tunnel-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export function getVaultAddressByOwner(
) {
const { ownerAddress } = parameters;
return readContract(client, {
address: bitcoinTunnelManagerAddresses[client.chain!.id],
abi: bitcoinTunnelManagerAbi,
address: bitcoinTunnelManagerAddresses[client.chain!.id],
args: [ownerAddress],
functionName: "getVaultAddressByOwner",
});
Expand Down
8 changes: 4 additions & 4 deletions src/actions/public/bitcoin-vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export function acknowledgedDeposits(
const { txId, vaultAddress } = parameters;
const hash: Hash = isHash(txId) ? txId : `0x${txId}`;
return readContract(client, {
address: vaultAddress,
abi: bitcoinVaultAbi,
functionName: "acknowledgedDeposits",
address: vaultAddress,
args: [hash],
functionName: "acknowledgedDeposits",
});
}

Expand All @@ -23,9 +23,9 @@ export function getBitcoinCustodyAddress(
) {
const { vaultAddress } = parameters;
return readContract(client, {
address: vaultAddress,
abi: bitcoinVaultAbi,
functionName: "getBitcoinCustodyAddress",
address: vaultAddress,
args: [],
functionName: "getBitcoinCustodyAddress",
});
}
6 changes: 3 additions & 3 deletions src/actions/public/get-btc-finality-by-block-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export async function getBtcFinalityByBlockHash(
throw err;
}
return {
l2_keystone: null,
btc_pub_height: -1,
btc_pub_header_hash: "",
btc_finality: -9,
btc_pub_header_hash: "",
btc_pub_height: -1,
l2_keystone: null,
};
}
}
34 changes: 17 additions & 17 deletions src/chains/hemi-sepolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ const sourceId = 11_155_111; // Sepolia

export const hemiSepolia = defineChain({
...chainConfig,
id: 743_111,
name: "Hemi Sepolia",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: {
http: ["https://testnet.rpc.hemi.network/rpc"],
webSocket: ["wss://testnet.rpc.hemi.network/wsrpc"],
},
opNode: {
http: ["https://testnet.rpc.hemi.network/noderpc"],
},
},
blockExplorers: {
default: {
name: "Hemi Sepolia Explorer",
Expand Down Expand Up @@ -63,6 +47,22 @@ export const hemiSepolia = defineChain({
},
},
},
testnet: true,
id: 743_111,
name: "Hemi Sepolia",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: {
http: ["https://testnet.rpc.hemi.network/rpc"],
webSocket: ["wss://testnet.rpc.hemi.network/wsrpc"],
},
opNode: {
http: ["https://testnet.rpc.hemi.network/noderpc"],
},
},
sourceId,
testnet: true,
});
32 changes: 16 additions & 16 deletions src/chains/hemi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ const sourceId = 1; // Ethereum mainnet

export const hemi = defineChain({
...chainConfig,
id: 43_111,
name: "Hemi Network",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: {
http: ["https://rpc.hemi.network/rpc"],
webSocket: ["wss://rpc.hemi.network/wsrpc"],
},
opNode: {
http: ["https://rpc.hemi.network/noderpc"],
},
},
blockExplorers: {
default: {
name: "Hemi Network Explorer",
Expand Down Expand Up @@ -63,6 +47,22 @@ export const hemi = defineChain({
},
},
},
id: 43_111,
name: "Hemi Network",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: {
http: ["https://rpc.hemi.network/rpc"],
webSocket: ["wss://rpc.hemi.network/wsrpc"],
},
opNode: {
http: ["https://rpc.hemi.network/noderpc"],
},
},
sourceId,
testnet: false,
});
11 changes: 4 additions & 7 deletions src/decorators/actions-to-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ type DecoratedActions<T extends Actions> = {
[K in keyof T]: (properties: Parameters<T[K]>[1]) => ReturnType<T[K]>;
};

export const actionsToDecorator = function <TActions extends Actions>(
actions: TActions,
) {
return function (client: Client) {
return Object.fromEntries(
export const actionsToDecorator =
<TActions extends Actions>(actions: TActions) =>
(client: Client) =>
Object.fromEntries(
Object.keys(actions).map((action) => [
action,
(properties: Parameters<TActions[typeof action]>[1]) =>
actions[action](client, properties),
]),
) as DecoratedActions<TActions>;
};
};

0 comments on commit 3eecd27

Please sign in to comment.