Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.eslintrc.js
node_modules/
bin/
lib/
Expand Down
66 changes: 37 additions & 29 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
module.exports = {
root: true,
env: { node: true },
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import', 'sort-imports-es6-autofix'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript'
'plugin:import/typescript',
],
rules: {
/* -------------------- error -------------------- */
indent: [2, 2, { SwitchCase: 1 }],
quotes: [2, 'single'],
semi: [1, 'always'],
'no-trailing-spaces': [2],
'quote-props': [2, 'as-needed'],
"arrow-parens": [2, "as-needed"],
'arrow-parens': [2, 'as-needed'],
'eol-last': [2, 'always'],
'object-curly-spacing': [2, 'always'],
'comma-dangle': [2, {
Expand All @@ -24,42 +25,49 @@ module.exports = {
exports: 'always-multiline',
functions: 'only-multiline',
}],
'@typescript-eslint/member-delimiter-style': 2,

/* -------------------- warn -------------------- */
semi: [1, 'always'],
'@typescript-eslint/no-unused-vars': [1, {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
}],
'sort-imports-es6-autofix/sort-imports-es6': 1,
'max-len': [1, {
code: 120,
ignoreComments: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],

/* ---------- turn off ---------- */
/* -------------------- off -------------------- */
'@typescript-eslint/no-extra-semi': 0,
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/naming-convention': 0,
'@typescript-eslint/no-explicit-any': 0, // any is sometimes unavoidable
'@typescript-eslint/consistent-type-definitions': 0, // can use Type and Interface
'@typescript-eslint/explicit-function-return-type': 0, // type inference on return type is useful
'@typescript-eslint/no-explicit-any': 0, // any is sometimes unavoidable
'@typescript-eslint/consistent-type-definitions': 0, // can use Type and Interface
'@typescript-eslint/explicit-function-return-type': 0, // type inference on return type is useful
'@typescript-eslint/no-parameter-properties': 0,
'@typescript-eslint/typedef': 0,
'no-unused-expressions': 0, // short ciucuit if
'@typescript-eslint/no-non-null-assertion': 0, // can assert not null
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-non-null-asserted-optional-chain': 0,
'import/no-named-as-default-member': 0,
'import/no-named-as-default': 0,
'no-unused-expressions': 0, // short ciucuit if
'no-useless-escape': 0,
'max-lines': 0,
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'sort-imports-es6-autofix/sort-imports-es6': 'warn',
'@typescript-eslint/ban-ts-comment': 'off',
'no-useless-escape': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
]
},
settings: {
'import/resolver': {
typescript: {
project: 'tsconfig.json'
}
}
}
project: 'tsconfig.json',
},
},
},
};
29 changes: 20 additions & 9 deletions packages/eth-providers/src/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ export abstract class BaseProvider extends AbstractProvider {
#subscription: Promise<() => void> | undefined;
head$: Observable<Header>;
finalizedHead$: Observable<Header>;
best$ = new ReplaySubject<{ hash: string, number: number }>(1);
finalized$ = new ReplaySubject<{ hash: string, number: number }>(1);
best$ = new ReplaySubject<{ hash: string; number: number }>(1);
finalized$ = new ReplaySubject<{ hash: string; number: number }>(1);

readonly #async = new AsyncScheduler(AsyncAction);

Expand Down Expand Up @@ -479,7 +479,11 @@ export abstract class BaseProvider extends AbstractProvider {
const registry = await this.api.getBlockRegistry(u8aToU8a(blockHash));

if (!this.storages.get(registry)) {
const storage = decorateStorage(registry.registry, registry.metadata.asLatest, registry.metadata.version);
const storage = decorateStorage(
registry.registry,
registry.metadata.asLatest,
registry.metadata.version,
);
this.storages.set(registry, storage);
}

Expand All @@ -490,7 +494,11 @@ export abstract class BaseProvider extends AbstractProvider {
const entry = storage[section][method];
const key = entry(...args);

const outputType = unwrapStorageType(registry.registry, entry.meta.type, entry.meta.modifier.isOptional);
const outputType = unwrapStorageType(
registry.registry,
entry.meta.type,
entry.meta.modifier.isOptional,
);

const cacheKey = `${module}-${blockHash}-${args.join(',')}`;
const cached = this.storageCache.get(cacheKey);
Expand Down Expand Up @@ -961,7 +969,10 @@ export abstract class BaseProvider extends AbstractProvider {
const u8a = extrinsic.toU8a();
const apiAt = await this.api.at(await this.bestBlockHash);
const lenIncreaseAfterSignature = 100; // approximate length increase after signature
const feeDetails = await apiAt.call.transactionPaymentApi.queryFeeDetails(u8a, u8a.length + lenIncreaseAfterSignature);
const feeDetails = await apiAt.call.transactionPaymentApi.queryFeeDetails(
u8a,
u8a.length + lenIncreaseAfterSignature,
);
const { baseFee, lenFee, adjustedWeightFee } = feeDetails.inclusionFee.unwrap();

const nativeTxFee = BigNumber.from(
Expand Down Expand Up @@ -1223,10 +1234,10 @@ export abstract class BaseProvider extends AbstractProvider {
v2: boolean;
} => {
let substrateParams: {
gasLimit: bigint,
storageLimit: bigint,
validUntil: bigint,
tip: bigint,
gasLimit: bigint;
storageLimit: bigint;
validUntil: bigint;
tip: bigint;
};
let v2 = false;

Expand Down
14 changes: 13 additions & 1 deletion packages/eth-providers/src/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ export class AcalaJsonRpcProvider extends JsonRpcProvider {
}

// override the underlying _wrapTransaction to avoid tx replacement check
async _waitForTransaction(transactionHash: string, confirmations: number, timeout: number, replaceable: { data: string, from: string, nonce: number, to: string, value: BigNumber, startBlock: number }): Promise<TransactionReceipt> {
async _waitForTransaction(
transactionHash: string,
confirmations: number,
timeout: number,
replaceable: {
data: string;
from: string;
nonce: number;
to: string;
value: BigNumber;
startBlock: number;
}
): Promise<TransactionReceipt> {
const receipt = await this.getTransactionReceipt(transactionHash);

// Receipt is already good
Expand Down
2 changes: 1 addition & 1 deletion packages/eth-providers/src/utils/parseBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const getEffectiveGasPrice = async (
(dispatchInfo as any).weight as WeightV1;

const [paymentInfo, feeDetails] = await Promise.all([
apiAtParentBlock.call.transactionPaymentApi.queryInfo<RuntimeDispatchInfoV1 | RuntimeDispatchInfoV2>(u8a,u8a.length),
apiAtParentBlock.call.transactionPaymentApi.queryInfo<RuntimeDispatchInfoV1 | RuntimeDispatchInfoV2>(u8a, u8a.length), // eslint-disable-line
apiAtParentBlock.call.transactionPaymentApi.queryFeeDetails(u8a, u8a.length),
]);

Expand Down
4 changes: 2 additions & 2 deletions packages/eth-providers/src/utils/transactionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ export const decodeEthGas = ({
gasPrice,
gasLimit,
}: {
gasPrice: BigNumber,
gasLimit: BigNumber,
gasPrice: BigNumber;
gasLimit: BigNumber;
}) => {
const bbbcc = gasLimit.mod(GAS_MASK);
const encodedGasLimit = bbbcc.div(STORAGE_MASK); // bbb
Expand Down
2 changes: 1 addition & 1 deletion packages/eth-providers/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface HealthResult {
// listeners
listenersCount: {
newHead: number;
newFinalizedHead: number,
newFinalizedHead: number;
logs: number;
};
};
Expand Down
16 changes: 15 additions & 1 deletion packages/eth-rpc-adapter/src/__tests__/e2e/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,21 @@ export const log22_1 = {
logIndex: '0x1',
};

export const allLogs = [log6, log7, log8, log9, log10, log11, log12, log13, log14, log20_0, log20_1, log22_0, log22_1] as LogHexified[];
export const allLogs = [
log6,
log7,
log8,
log9,
log10,
log11,
log12,
log13,
log14,
log20_0,
log20_1,
log22_0,
log22_1,
] as LogHexified[];

export const ERC20_BYTECODE = '6060604052341561000f57600080fd5b604051610dd1380380610dd18339810160405280805190602001909190805182019190602001805190602001909190805182019190505083600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508360008190555082600390805190602001906100a79291906100e3565b5081600460006101000a81548160ff021916908360ff16021790555080600590805190602001906100d99291906100e3565b5050505050610188565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061012457805160ff1916838001178555610152565b82800160010185558215610152579182015b82811115610151578251825591602001919060010190610136565b5b50905061015f9190610163565b5090565b61018591905b80821115610181576000816000905550600101610169565b5090565b90565b610c3a806101976000396000f3006060604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014257806318160ddd1461019c57806323b872dd146101c557806327e235e31461023e578063313ce5671461028b5780635c658165146102ba57806370a082311461032657806395d89b4114610373578063a9059cbb14610401578063dd62ed3e1461045b575b600080fd5b34156100bf57600080fd5b6100c76104c7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101075780820151818401526020810190506100ec565b50505050905090810190601f1680156101345780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014d57600080fd5b610182600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610565565b604051808215151515815260200191505060405180910390f35b34156101a757600080fd5b6101af610657565b6040518082815260200191505060405180910390f35b34156101d057600080fd5b610224600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061065d565b604051808215151515815260200191505060405180910390f35b341561024957600080fd5b610275600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506108f7565b6040518082815260200191505060405180910390f35b341561029657600080fd5b61029e61090f565b604051808260ff1660ff16815260200191505060405180910390f35b34156102c557600080fd5b610310600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610922565b6040518082815260200191505060405180910390f35b341561033157600080fd5b61035d600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610947565b6040518082815260200191505060405180910390f35b341561037e57600080fd5b610386610990565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103c65780820151818401526020810190506103ab565b50505050905090810190601f1680156103f35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561040c57600080fd5b610441600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610a2e565b604051808215151515815260200191505060405180910390f35b341561046657600080fd5b6104b1600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610b87565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561055d5780601f106105325761010080835404028352916020019161055d565b820191906000526020600020905b81548152906001019060200180831161054057829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b600080600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015801561072e5750828110155b151561073957600080fd5b82600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555082600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156108865782600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055505b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a360019150509392505050565b60016020528060005260406000206000915090505481565b600460009054906101000a900460ff1681565b6002602052816000526040600020602052806000526040600020600091509150505481565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a265780601f106109fb57610100808354040283529160200191610a26565b820191906000526020600020905b815481529060010190602001808311610a0957829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410151515610a7e57600080fd5b81600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820df254047bc8f2904ad3e966b6db116d703bebd40efadadb5e738c836ffc8f58a0029';

Expand Down
3 changes: 2 additions & 1 deletion packages/eth-rpc-adapter/src/__tests__/e2e/endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ describe('endpoint', () => {
const queryEthBalance = async (addr): Promise<BigNumber> =>
BigNumber.from((await eth_getBalance([addr, 'latest'])).data.result);

const queryNativeBalance = async (addr: string) => (await queryEthBalance(addr)).div(10 ** (ETH_Digits - ACA_Digits));
const queryNativeBalance = async (addr: string) =>
(await queryEthBalance(addr)).div(10 ** (ETH_Digits - ACA_Digits));

const getTxFeeFromReceipt = async (txHash: string, toNative = false): Promise<bigint> => {
await sleep(789); // give cache/subquery a little bit time
Expand Down
8 changes: 4 additions & 4 deletions packages/eth-rpc-adapter/src/__tests__/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const eth_call = rpcGet('eth_call');
export const eth_blockNumber = rpcGet('eth_blockNumber');
export const eth_getBlockByNumber = rpcGet('eth_getBlockByNumber');
export const eth_getTransactionReceipt = rpcGet('eth_getTransactionReceipt');
export const eth_getLogs = rpcGet<{ data: { result: LogHexified[], error?: JsonRpcError } }>('eth_getLogs');
export const eth_getLogs = rpcGet<{ data: { result: LogHexified[]; error?: JsonRpcError } }>('eth_getLogs');
export const eth_getTransactionByHash = rpcGet('eth_getTransactionByHash');
export const eth_accounts = rpcGet('eth_accounts');
export const eth_sendRawTransaction = rpcGet('eth_sendRawTransaction');
Expand All @@ -57,9 +57,9 @@ export const eth_newBlockFilter = rpcGet('eth_newBlockFilter');
export const eth_getFilterChanges = rpcGet('eth_getFilterChanges');
export const eth_getFilterLogs = rpcGet<{
data: {
result: LogHexified[],
error?: JsonRpcError
}
result: LogHexified[];
error?: JsonRpcError;
};
}>('eth_getFilterLogs');
export const eth_uninstallFilter = rpcGet('eth_uninstallFilter');
export const net_listening = rpcGet('net_listening');
Expand Down
4 changes: 3 additions & 1 deletion packages/eth-rpc-adapter/src/utils/monitor-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const monitorRuntime = async (provider: EvmRpcProvider) => {

const runtimeVersion$ = provider.api.rx.rpc.state.subscribeRuntimeVersion();

const initialRuntimeVersion = await firstValueFrom(runtimeVersion$.pipe(map(runtime => runtime.specVersion.toNumber())));
const initialRuntimeVersion = await firstValueFrom(
runtimeVersion$.pipe(map(runtime => runtime.specVersion.toNumber()))
);

runtimeVersion$.subscribe(runtime => {
const version = runtime.specVersion.toNumber();
Expand Down