mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-25 02:20:24 +00:00
c0cd668c64
* Layed out components for custom nodes. * Outline of custom nodes. Still missing various features and error handling. * Persist custom nodes to local storage. * Make custom nodes removable. * Add latest block functions, call it when switching nodes. * Initialize correct node, move node utils into utils file. * Fix names * Send headers along with rpc requests. * Remove custom network options for now. * PR feedback. * One last log. * Fix tests. * Headers in batch too. * Switch to node when you add it. * Reduce hackery. * Clean up linter and tsc. * Fix latest block hex conversion. * Unit tests. * Fix missing property. * Fix Modal title typing.
74 lines
1.5 KiB
TypeScript
74 lines
1.5 KiB
TypeScript
import { Token } from 'config/data';
|
|
import ERC20 from 'libs/erc20';
|
|
import {
|
|
CallRequest,
|
|
EstimateGasRequest,
|
|
GetBalanceRequest,
|
|
GetTokenBalanceRequest,
|
|
GetTransactionCountRequest,
|
|
SendRawTxRequest,
|
|
GetCurrentBlockRequest,
|
|
} from './types';
|
|
import { hexEncodeData } from './utils';
|
|
import { TxObj } from '../INode';
|
|
export default class RPCRequests {
|
|
public sendRawTx(signedTx: string): SendRawTxRequest | any {
|
|
return {
|
|
method: 'eth_sendRawTransaction',
|
|
params: [signedTx]
|
|
};
|
|
}
|
|
|
|
public estimateGas(transaction): EstimateGasRequest | any {
|
|
return {
|
|
method: 'eth_estimateGas',
|
|
params: [transaction]
|
|
};
|
|
}
|
|
|
|
public getBalance(address: string): GetBalanceRequest | any {
|
|
return {
|
|
method: 'eth_getBalance',
|
|
params: [hexEncodeData(address), 'pending']
|
|
};
|
|
}
|
|
|
|
public ethCall(txObj: TxObj): CallRequest | any {
|
|
return {
|
|
method: 'eth_call',
|
|
params: [txObj, 'pending']
|
|
};
|
|
}
|
|
|
|
public getTransactionCount(
|
|
address: string
|
|
): GetTransactionCountRequest | any {
|
|
return {
|
|
method: 'eth_getTransactionCount',
|
|
params: [address, 'pending']
|
|
};
|
|
}
|
|
|
|
public getTokenBalance(
|
|
address: string,
|
|
token: Token
|
|
): GetTokenBalanceRequest | any {
|
|
return {
|
|
method: 'eth_call',
|
|
params: [
|
|
{
|
|
to: token.address,
|
|
data: ERC20.balanceOf(address)
|
|
},
|
|
'pending'
|
|
]
|
|
};
|
|
}
|
|
|
|
public getCurrentBlock(): GetCurrentBlockRequest | any {
|
|
return {
|
|
method: 'eth_blockNumber',
|
|
};
|
|
}
|
|
}
|