add: eth_getCode support

This commit is contained in:
Andrei O 2022-11-22 14:07:42 +02:00
parent 152635b310
commit b324a6c7ba
No known key found for this signature in database
GPG Key ID: B961E5B68389457E
3 changed files with 21 additions and 2 deletions

View File

@ -56,7 +56,8 @@ const allowedMethods = {
'wallet_getPermissions': true,
'net_listening': true,
'eth_coinbase': true,
'wallet_addEthereumChain': true
'wallet_addEthereumChain': true,
'eth_getCode': true
}
window.addEventListener("message", (event) => {

View File

@ -1,6 +1,6 @@
import { getSelectedAccount, getSelectedNetwork, smallRandomString, getSettings, clearPk, openTab, getUrl, addToHistory, getNetworks, strToHex } from '@/utils/platform';
import { userApprove, userReject, rIdWin, rIdData } from '@/extension/userRequest'
import { signMsg, getBalance, getBlockNumber, estimateGas, sendTransaction, getGasPrice, getBlockByNumber, evmCall, getTxByHash, getTxReceipt, signTypedData } from '@/utils/wallet'
import { signMsg, getBalance, getBlockNumber, estimateGas, sendTransaction, getGasPrice, getBlockByNumber, evmCall, getTxByHash, getTxReceipt, signTypedData, getCode } from '@/utils/wallet'
import type { RequestArguments } from '@/extension/types'
import { rpcError } from '@/extension/rpcConstants'
import { updatePrices } from '@/utils/gecko'
@ -162,6 +162,18 @@ const mainListner = (message: RequestArguments, sender:any, sendResponse: (a: an
}
break
}
case 'eth_getCode': {
try {
sendResponse(await getCode(message?.params?.[0] as string))
} catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break
}
case 'eth_blockNumber': {
try {
sendResponse(await getBlockNumber())

View File

@ -70,6 +70,12 @@ export const getTxReceipt = async (hash: string) => {
return await provider.getTransactionReceipt(hash)
}
export const getCode = async (addr: string) => {
const network = await getSelectedNetwork()
const provider = new ethers.providers.JsonRpcProvider(network.rpc)
return await provider.getCode(addr)
}
export const sendTransaction = async ({ data= '', gas='0x0', to='', from='', value='0x0', gasPrice='0x0'}:
{to: string, from: string, data: string, value: string, gas: string, gasPrice: string},
gasEstimate: Promise<BigNumber> | null = null, pGasPrice : Promise<BigNumber> | null) => {