2017-09-24 19:06:28 -07:00
|
|
|
import { Token } from 'config/data';
|
2017-09-19 20:47:08 -04:00
|
|
|
import ERC20 from 'libs/erc20';
|
2017-09-24 19:06:28 -07:00
|
|
|
import {
|
2017-09-19 20:47:08 -04:00
|
|
|
CallRequest,
|
2017-09-24 19:06:28 -07:00
|
|
|
EstimateGasRequest,
|
2017-09-19 20:47:08 -04:00
|
|
|
GetBalanceRequest,
|
|
|
|
GetTokenBalanceRequest,
|
|
|
|
GetTransactionCountRequest,
|
2017-11-18 13:33:53 -07:00
|
|
|
SendRawTxRequest,
|
2017-11-28 19:17:26 -05:00
|
|
|
GetCurrentBlockRequest
|
2017-09-19 20:47:08 -04:00
|
|
|
} from './types';
|
2017-09-24 19:06:28 -07:00
|
|
|
import { hexEncodeData } from './utils';
|
2017-10-16 19:48:03 -04:00
|
|
|
import { TxObj } from '../INode';
|
2017-09-19 20:47:08 -04:00
|
|
|
export default class RPCRequests {
|
2017-11-28 19:17:26 -05:00
|
|
|
public getNetVersion() {
|
|
|
|
return { method: 'net_version' };
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public sendRawTx(signedTx: string): SendRawTxRequest | any {
|
2017-09-19 20:47:08 -04:00
|
|
|
return {
|
|
|
|
method: 'eth_sendRawTransaction',
|
|
|
|
params: [signedTx]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public estimateGas(transaction): EstimateGasRequest | any {
|
2017-09-19 20:47:08 -04:00
|
|
|
return {
|
|
|
|
method: 'eth_estimateGas',
|
|
|
|
params: [transaction]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public getBalance(address: string): GetBalanceRequest | any {
|
2017-09-19 20:47:08 -04:00
|
|
|
return {
|
|
|
|
method: 'eth_getBalance',
|
|
|
|
params: [hexEncodeData(address), 'pending']
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-16 19:48:03 -04:00
|
|
|
public ethCall(txObj: TxObj): CallRequest | any {
|
2017-09-19 20:47:08 -04:00
|
|
|
return {
|
|
|
|
method: 'eth_call',
|
2017-10-16 19:48:03 -04:00
|
|
|
params: [txObj, 'pending']
|
2017-09-19 20:47:08 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public getTransactionCount(
|
|
|
|
address: string
|
|
|
|
): GetTransactionCountRequest | any {
|
2017-09-19 20:47:08 -04:00
|
|
|
return {
|
|
|
|
method: 'eth_getTransactionCount',
|
|
|
|
params: [address, 'pending']
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public getTokenBalance(
|
|
|
|
address: string,
|
|
|
|
token: Token
|
|
|
|
): GetTokenBalanceRequest | any {
|
2017-09-19 20:47:08 -04:00
|
|
|
return {
|
|
|
|
method: 'eth_call',
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
to: token.address,
|
|
|
|
data: ERC20.balanceOf(address)
|
|
|
|
},
|
|
|
|
'pending'
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
2017-11-18 13:33:53 -07:00
|
|
|
|
|
|
|
public getCurrentBlock(): GetCurrentBlockRequest | any {
|
|
|
|
return {
|
2017-11-28 19:17:26 -05:00
|
|
|
method: 'eth_blockNumber'
|
2017-11-18 13:33:53 -07:00
|
|
|
};
|
|
|
|
}
|
2017-09-19 20:47:08 -04:00
|
|
|
}
|