2017-09-25 02:06:28 +00:00
|
|
|
import { Token } from 'config/data';
|
2017-09-20 00:47:08 +00:00
|
|
|
import ERC20 from 'libs/erc20';
|
|
|
|
import RPCRequests from '../rpc/requests';
|
2017-09-25 02:06:28 +00:00
|
|
|
import {
|
2017-09-20 00:47:08 +00:00
|
|
|
CallRequest,
|
2017-09-25 02:06:28 +00:00
|
|
|
EstimateGasRequest,
|
2017-09-20 00:47:08 +00:00
|
|
|
GetBalanceRequest,
|
|
|
|
GetTokenBalanceRequest,
|
|
|
|
GetTransactionCountRequest,
|
|
|
|
SendRawTxRequest
|
|
|
|
} from './types';
|
|
|
|
|
|
|
|
export default class EtherscanRequests extends RPCRequests {
|
2017-09-25 02:06:28 +00:00
|
|
|
public sendRawTx(signedTx: string): SendRawTxRequest {
|
2017-09-20 00:47:08 +00:00
|
|
|
return {
|
|
|
|
module: 'proxy',
|
|
|
|
method: 'eth_sendRawTransaction',
|
|
|
|
hex: signedTx
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public estimateGas(transaction): EstimateGasRequest {
|
2017-09-20 00:47:08 +00:00
|
|
|
return {
|
|
|
|
module: 'proxy',
|
|
|
|
method: 'eth_estimateGas',
|
|
|
|
to: transaction.to,
|
|
|
|
value: transaction.value,
|
|
|
|
data: transaction.data,
|
|
|
|
from: transaction.from
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public getBalance(address: string): GetBalanceRequest {
|
2017-09-20 00:47:08 +00:00
|
|
|
return {
|
|
|
|
module: 'account',
|
|
|
|
action: 'balance',
|
|
|
|
tag: 'latest',
|
|
|
|
address
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public ethCall(transaction): CallRequest {
|
2017-09-20 00:47:08 +00:00
|
|
|
return {
|
|
|
|
module: 'proxy',
|
|
|
|
action: 'eth_call',
|
|
|
|
to: transaction.to,
|
|
|
|
data: transaction.data
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public getTransactionCount(address: string): GetTransactionCountRequest {
|
2017-09-20 00:47:08 +00:00
|
|
|
return {
|
|
|
|
module: 'proxy',
|
|
|
|
action: 'eth_getTransactionCount',
|
|
|
|
tag: 'latest',
|
|
|
|
address
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public getTokenBalance(
|
|
|
|
address: string,
|
|
|
|
token: Token
|
|
|
|
): GetTokenBalanceRequest {
|
2017-09-20 00:47:08 +00:00
|
|
|
return this.ethCall({
|
|
|
|
to: token.address,
|
|
|
|
data: ERC20.balanceOf(address)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|