Skip to content

Commit

Permalink
feat: support eth_ filter methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Jan 8, 2024
1 parent 827b05a commit 7809b68
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
12 changes: 6 additions & 6 deletions packages/mask/entry-sdk/README.md
Expand Up @@ -54,12 +54,12 @@ The list is built from what [MetaMask supported](https://docs.metamask.io/wallet

## Filters

- [ ] eth_getFilterChanges
- [ ] eth_getFilterLogs
- [ ] eth_newBlockFilter
- [ ] eth_newFilter
- [ ] eth_newPendingTransactionFilter
- [ ] eth_uninstallFilter
- [x] eth_getFilterChanges
- [x] eth_getFilterLogs
- [x] eth_newBlockFilter
- [x] eth_newFilter
- [ ] eth_newPendingTransactionFilter (not supported by infura)
- [x] eth_uninstallFilter

## Deprecated methods

Expand Down
17 changes: 13 additions & 4 deletions packages/mask/entry-sdk/bridge/eth.ts
Expand Up @@ -10,9 +10,18 @@ import { maskSDK } from '../index.js'
import { sample } from 'lodash-es'
import { AsyncCall, JSONSerialization } from 'async-call-rpc/full'

const readonlyMethods: Record<EthereumMethodType, (params: unknown[] | undefined) => Promise<unknown>> = {} as any
for (const method of readonlyMethodType) {
readonlyMethods[method] = async (...params: unknown[]) => {
const PassthroughMethods = [
...readonlyMethodType,
EthereumMethodType.ETH_GET_FILTER_CHANGES,
EthereumMethodType.ETH_GET_FILTER_LOGS,
EthereumMethodType.ETH_NEW_BLOCK_FILTER,
EthereumMethodType.ETH_NEW_FILTER,
EthereumMethodType.ETH_UNINSTALL_FILTER,
]
type PassthroughMethods = (typeof PassthroughMethods)[number]
const passthroughMethods: Record<PassthroughMethods, (params: unknown[] | undefined) => Promise<unknown>> = {} as any
for (const method of PassthroughMethods) {
passthroughMethods[method] = async (...params: unknown[]) => {
return (await Services.Wallet.send({ jsonrpc: '2.0', method, params })).result
}
}
Expand Down Expand Up @@ -69,7 +78,7 @@ function getInteractiveClient(): Promise<InteractiveClient> {
// https://ethereum.github.io/execution-apis/api-documentation/
// https://docs.metamask.io/wallet/reference/eth_subscribe/
const methods = {
...readonlyMethods,
...passthroughMethods,

async eth_chainId() {
const chainId = await Services.Wallet.sdk_eth_chainId()
Expand Down
9 changes: 5 additions & 4 deletions packages/mask/entry-sdk/bridge/eth/validator.ts
Expand Up @@ -37,11 +37,12 @@ namespace _ {
export const decimal = z.number().min(0).max(36)
export const filter = z
.object({
fromBlock: unpadded_hex.nullish(),
toBlock: unpadded_hex.nullish(),
address: address.or(address.array()),
topics: z.any(),
fromBlock: unpadded_hex.nullish().nullable(),
toBlock: unpadded_hex.nullish().nullable(),
address: address.or(address.array()).nullable(),
topics: z.any().nullable(),
})
.partial()
.strict()
.describe('Filter')
export const filter_identifier = unpadded_hex.describe('FilterIdentifier')
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-shared/evm/src/types/index.ts
Expand Up @@ -212,7 +212,11 @@ export enum EthereumMethodType {
ETH_GET_TRANSACTION_RECEIPT = 'eth_getTransactionReceipt',
ETH_GET_TRANSACTION_COUNT = 'eth_getTransactionCount',
ETH_GET_FILTER_CHANGES = 'eth_getFilterChanges',
ETH_GET_FILTER_LOGS = 'eth_getFilterLogs',
ETH_NEW_BLOCK_FILTER = 'eth_newBlockFilter',
ETH_NEW_FILTER = 'eth_newFilter',
ETH_NEW_PENDING_TRANSACTION_FILTER = 'eth_newPendingTransactionFilter',
ETH_UNINSTALL_FILTER = 'eth_uninstallFilter',
ETH_ESTIMATE_GAS = 'eth_estimateGas',
ETH_CALL = 'eth_call',
ETH_SIGN = 'eth_sign',
Expand Down

0 comments on commit 7809b68

Please sign in to comment.