update sth
This commit is contained in:
parent
e1464ee599
commit
0915d5f153
@ -212,6 +212,7 @@ export const AllChains = [
|
|||||||
type: 'Mainnet',
|
type: 'Mainnet',
|
||||||
rpc: 'https://endpoints.omniatech.io/v1/arbitrum/one/public|https://rpc.ankr.com/arbitrum',
|
rpc: 'https://endpoints.omniatech.io/v1/arbitrum/one/public|https://rpc.ankr.com/arbitrum',
|
||||||
id: 42161,
|
id: 42161,
|
||||||
|
network: 'ARBITRUM',
|
||||||
symbol: 'ETH',
|
symbol: 'ETH',
|
||||||
explorerurl: 'https://arbiscan.io/',
|
explorerurl: 'https://arbiscan.io/',
|
||||||
},
|
},
|
||||||
@ -260,6 +261,7 @@ export const AllChains = [
|
|||||||
type: 'Testnet',
|
type: 'Testnet',
|
||||||
rpc: 'https://goerli-rollup.arbitrum.io/rpc|https://endpoints.omniatech.io/v1/arbitrum/goerli/public',
|
rpc: 'https://goerli-rollup.arbitrum.io/rpc|https://endpoints.omniatech.io/v1/arbitrum/goerli/public',
|
||||||
id: 421613,
|
id: 421613,
|
||||||
|
network: 'AGOR',
|
||||||
symbol: 'AGOR',
|
symbol: 'AGOR',
|
||||||
explorerurl: 'https://goerli-rollup-explorer.arbitrum.io',
|
explorerurl: 'https://goerli-rollup-explorer.arbitrum.io',
|
||||||
},
|
},
|
||||||
|
@ -12,15 +12,18 @@ class ChainController extends BaseController {
|
|||||||
@router('post /chain/req')
|
@router('post /chain/req')
|
||||||
async addChainRequest(req, res) {
|
async addChainRequest(req, res) {
|
||||||
// data是一个数组!!
|
// data是一个数组!!
|
||||||
const { data, type, taskId, force, max } = req.params
|
const { data, source, cb, taskId, force, max } = req.params
|
||||||
console.log(`income chain request:: taskId: ${taskId}, type: ${type}`)
|
console.log(`income chain request:: taskId: ${taskId}, source: ${source}, cb: ${cb}`)
|
||||||
console.log(JSON.stringify(data))
|
console.log(JSON.stringify(data))
|
||||||
let maxTryCount = max !== undefined ? parseInt(max) : parseInt(process.env.CHAIN_MAX_TRY)
|
let maxTryCount = max !== undefined ? parseInt(max) : parseInt(process.env.CHAIN_MAX_TRY)
|
||||||
let chainTask: DocumentType<ChainTaskClass> = await ChainTask.insertOrUpdate({ taskId }, { type, taskData: data })
|
let chainTask: DocumentType<ChainTaskClass> = await ChainTask.insertOrUpdate(
|
||||||
|
{ taskId },
|
||||||
|
{ source, taskData: data, cb },
|
||||||
|
)
|
||||||
|
|
||||||
if ((!chainTask.newRecord && force) || chainTask.newRecord) {
|
if ((!chainTask.newRecord && force) || chainTask.newRecord) {
|
||||||
for (let sub of data) {
|
for (let sub of data) {
|
||||||
let subType = sub.type || type
|
let subType = sub.type
|
||||||
let subTask = new RequestTask({
|
let subTask = new RequestTask({
|
||||||
taskId,
|
taskId,
|
||||||
chainTaskId: chainTask.id,
|
chainTaskId: chainTask.id,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { BlockChain } from 'chain/BlockChain'
|
import { BlockChain } from 'chain/BlockChain'
|
||||||
|
import { ZError } from 'common/ZError'
|
||||||
import BaseController from 'common/base.controller'
|
import BaseController from 'common/base.controller'
|
||||||
import { role, router } from 'decorators/router'
|
import { role, router } from 'decorators/router'
|
||||||
import { PriceSvr } from 'service/price.service'
|
|
||||||
|
|
||||||
class TokenController extends BaseController {
|
class TokenController extends BaseController {
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@ -24,12 +24,9 @@ class TokenController extends BaseController {
|
|||||||
@router('post /chain/estimate_gas')
|
@router('post /chain/estimate_gas')
|
||||||
async calcGasPrice(req, res) {
|
async calcGasPrice(req, res) {
|
||||||
let { gas } = req.params
|
let { gas } = req.params
|
||||||
if (!gas)
|
if (!gas) {
|
||||||
gas = await new BlockChain().web3.eth.estimateGas({
|
throw new ZError(10, 'gas is required')
|
||||||
from: '0x84f165521886642D24c55FACc886ab5986AD2d8b',
|
}
|
||||||
to: '0x84f165521886642D24c55FACc886ab5986AD2d8b',
|
|
||||||
value: '0',
|
|
||||||
})
|
|
||||||
let data = new BlockChain().generateGasShow(gas)
|
let data = new BlockChain().generateGasShow(gas)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,12 @@ export class ChainTaskClass extends BaseModule {
|
|||||||
@prop({ type: mongoose.Schema.Types.Mixed })
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
||||||
public taskData: any
|
public taskData: any
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public source: string
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public cb: string
|
||||||
|
|
||||||
@prop({ enum: TaskStatus, default: TaskStatus.NOTSTART })
|
@prop({ enum: TaskStatus, default: TaskStatus.NOTSTART })
|
||||||
public status: TaskStatus
|
public status: TaskStatus
|
||||||
|
|
||||||
@ -98,6 +104,7 @@ export class ChainTaskClass extends BaseModule {
|
|||||||
successCount: record.successCount,
|
successCount: record.successCount,
|
||||||
errorCount: record.errorCount,
|
errorCount: record.errorCount,
|
||||||
hashList,
|
hashList,
|
||||||
|
cb: record.cb,
|
||||||
})
|
})
|
||||||
// logger.log(result)
|
// logger.log(result)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -13,7 +13,11 @@ export class InfoSvr {
|
|||||||
reportTaskResult(data: any) {
|
reportTaskResult(data: any) {
|
||||||
data.sign = calcHash(data)
|
data.sign = calcHash(data)
|
||||||
logger.info('report to info svr: ' + JSON.stringify(data))
|
logger.info('report to info svr: ' + JSON.stringify(data))
|
||||||
let url = `${process.env.INFO_SVR_HOST}${REPORT_TASK_URI}`
|
let url = data.cb
|
||||||
|
delete data.cb
|
||||||
|
if (!url) {
|
||||||
|
url = `${process.env.INFO_SVR_HOST}${REPORT_TASK_URI}`
|
||||||
|
}
|
||||||
let reqConfig: any = {
|
let reqConfig: any = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url,
|
url,
|
||||||
|
@ -27,7 +27,8 @@ export class PriceSvr {
|
|||||||
const key = `crypto_usd|${eth}`
|
const key = `crypto_usd|${eth}`
|
||||||
let data = this.priceMap.get(key)
|
let data = this.priceMap.get(key)
|
||||||
if (!data || data.expired < Date.now() || refresh) {
|
if (!data || data.expired < Date.now() || refresh) {
|
||||||
const url = `https://min-api.cryptocompare.com/data/price?fsym=${eth}&tsyms=${usd}`
|
const key = process.env.CRYPTOCOMPARE_API_KEY
|
||||||
|
const url = `https://min-api.cryptocompare.com/data/price?fsym=${eth}&tsyms=${usd}&api_key=${key}`
|
||||||
let priceData = await axios.get(url).then(res => res.data)
|
let priceData = await axios.get(url).then(res => res.data)
|
||||||
let price = priceData[usd] * 100 + ''
|
let price = priceData[usd] * 100 + ''
|
||||||
this.priceMap.set(key, { price, expired: Date.now() + 1000 * 60 })
|
this.priceMap.set(key, { price, expired: Date.now() + 1000 * 60 })
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
import xlsx from 'node-xlsx'
|
|
||||||
|
|
||||||
export function excelToJson(filePath: string) {
|
|
||||||
console.log('excel2json: ' + filePath)
|
|
||||||
const workSheetsFromFile = xlsx.parse(filePath)
|
|
||||||
if (!workSheetsFromFile || workSheetsFromFile.length === 0) {
|
|
||||||
throw new Error('excelToJson: no sheet found')
|
|
||||||
}
|
|
||||||
const sheet = workSheetsFromFile[0]
|
|
||||||
const header = (sheet.data[0] as string[]).map(item => item.toLowerCase())
|
|
||||||
let arr = []
|
|
||||||
for (let i = 1, l = sheet.data.length; i < l; i++) {
|
|
||||||
let row = sheet.data[i] as []
|
|
||||||
if (row.length === 0) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
let obj = {}
|
|
||||||
for (let j = 0, k = header.length; j < k; j++) {
|
|
||||||
obj[header[j]] = row[j]
|
|
||||||
}
|
|
||||||
arr.push(obj)
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user