38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { BlockChain } from 'chain/BlockChain'
|
|
import BaseController from 'common/base.controller'
|
|
import { role, router } from 'decorators/router'
|
|
import { PriceSvr } from 'service/price.service'
|
|
|
|
class TokenController extends BaseController {
|
|
@role('anon')
|
|
@router('post /chain/estimate_transfer_gas')
|
|
async calcTransPrice(req, res) {
|
|
const { address } = req.params
|
|
const bc = new BlockChain()
|
|
const account = bc.currentAccount
|
|
let gas = await bc.erc20Reactor.transfer({
|
|
address: address + '',
|
|
to: account,
|
|
amount: 0,
|
|
estimate: true,
|
|
})
|
|
let data = bc.generateGasShow(gas)
|
|
return data
|
|
}
|
|
|
|
@role('anon')
|
|
@router('post /chain/estimate_gas')
|
|
async calcGasPrice(req, res) {
|
|
let { gas } = req.params
|
|
if (!gas)
|
|
gas = await new BlockChain().web3.eth.estimateGas({
|
|
from: '0x84f165521886642D24c55FACc886ab5986AD2d8b',
|
|
to: '0x84f165521886642D24c55FACc886ab5986AD2d8b',
|
|
value: '0',
|
|
})
|
|
let data = new BlockChain().generateGasShow(gas)
|
|
return data
|
|
}
|
|
}
|
|
export default TokenController
|