Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers'
import { ChainId, createLookupTableResolver } from '@masknet/web3-shared-evm'
import { BobaInterceptor } from './interceptors'
import type { Interceptor } from './types'

const getInterceptor = createLookupTableResolver<ChainId, Interceptor | null>(
{
[ChainId.Mainnet]: null,
[ChainId.Ropsten]: null,
[ChainId.Kovan]: null,
[ChainId.Rinkeby]: null,
[ChainId.Gorli]: null,
[ChainId.BSC]: null,
[ChainId.BSCT]: null,
[ChainId.Matic]: null,
[ChainId.Mumbai]: null,
[ChainId.Arbitrum]: null,
[ChainId.Arbitrum_Rinkeby]: null,
[ChainId.xDai]: null,
[ChainId.Celo]: null,
[ChainId.Fantom]: null,
[ChainId.Aurora]: null,
[ChainId.Avalanche]: null,
[ChainId.Boba]: new BobaInterceptor(),
[ChainId.Optimistic]: null,
},
null,
)

export function encodePayload(chainId: ChainId, payload: JsonRpcPayload) {
const interceptor = getInterceptor(chainId)
return interceptor?.encode?.(payload) ?? payload
}

export function decodeResponse(chainId: ChainId, error: Error | null, response?: JsonRpcResponse) {
const interceptor = getInterceptor(chainId)
return interceptor?.decode?.(error, response) ?? [error, response]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers'
import type { Interceptor } from '../types'

export class BobaInterceptor implements Interceptor {
encode(payload: JsonRpcPayload): JsonRpcPayload {
throw new Error('Method not implemented.')
}
decode(error: Error | null, response?: JsonRpcResponse): [Error | null, JsonRpcResponse] {
throw new Error('Method not implemented.')
}
getPayloadHash(payload: JsonRpcPayload) {}
getPayloadNonce(payload: JsonRpcPayload) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Boba'
4 changes: 4 additions & 0 deletions packages/web3-shared/evm/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ export enum EthereumMethodType {
MASK_REPLACE_TRANSACTION = 'mask_replaceTransaction',
MASK_LOGIN_FORTMATIC = 'mask_loginFortmatic',
MASK_LOGOUT_FORTMATIC = 'mask_logoutFortmatic',

// optimistic, boba
ROLLUP_GET_INFO = 'rollup_getInfo',
ROLLUP_GAS_PRICES = 'rollup_gasPrices',
}

export enum EthereumErrorType {
Expand Down