chainlink外部适配器[请求失败,状态代码400]

nwsw7zdq  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(252)

我正在尝试学习chainlink外部适配器,我对这一切都是新手。
是否有可能获得以下方面的帮助?我的适配器代码不工作,并告诉我使用的参数无效。
我试图在coinpaprika上点击以下api:
https://api.coinpaprika.com/v1/price-converter?base_currency_id=link-chainlink和quote\u currency\u id=usdt系带和金额=1
这是我在nodejs中的适配器代码

const customError = (data) => {
  if (data.Response === 'Error') return true
  return false
}

const customParams = {
  base: ['base', 'from', 'coin'],
  quote: ['quote', 'to', 'market'],
  amount: ['amount', 'qty', 'num'],
  endpoint: false
}

const createRequest = (input, callback) => {
  const validator = new Validator(callback, input, customParams)
  const jobRunID = validator.validated.id
  const endpoint = validator.validated.data.endpoint || 'price-converter'
  const url = `https://api.coinpaprika.com/v1/${endpoint}`
  const base_currency_id = validator.validated.data.base.toUpperCase()
  const quote_currency_id = validator.validated.data.quote.toUpperCase()
  const amount = validator.validated.data.amount.toUpperCase()

  const params = {
    base_currency_id,
    quote_currency_id,
    amount
  }

  const config = {
    url,
    params
  }

  Requester.request(config, customError)
    .then(response => {
      response.data.result = Requester.validateResultNumber(response.data, [amount])
      callback(response.status, Requester.success(jobRunID, response))
    })
    .catch(error => {
      callback(500, Requester.errored(jobRunID, error))
    })
}

这是我的电话: curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "base": "chainlink", "quote": "usdt-tether","amount": "1" } }' 这是我得到的服务器错误输出

id: 0,
  data: { base: 'chainlink', quote: 'usdt-tether', amount: '1' }
}
{"message":"Caught error. Retrying: \"Request failed with status code 400\"","level":"warn","timestamp":"2021-07-25T09:06:44.560Z"}
{"message":"Caught error. Retrying: \"Request failed with status code 400\"","level":"warn","timestamp":"2021-07-25T09:06:45.696Z"}
{"message":"Could not reach endpoint: \"Request failed with status code 400\"","level":"error","timestamp":"2021-07-25T09:06:45.800Z"}
Result:  {
  jobRunID: 0,
  status: 'errored',
  error: AdapterError: AdapterError: Request failed with status code 400
      at Function.errored (/Users/xxxx/CL-EA-NodeJS-Template/node_modules/@chainlink/external-adapter/src/requester.js:90:14)
      at /Users/pocondui/CL-EA-NodeJS-Template/index.js:42:31
      at processTicksAndRejections (internal/process/task_queues.js:95:5),
  statusCode: 500

更新
看起来我使用了错误的curl参数,应该是link-chainlink而不是chainlink

POST Data:  {
  id: 0,
  data: { from: 'link-chainlink', to: 'usdt-tether', qty: '1' }
}
{"message":"Received response: {\"base_currency_id\":\"link-chainlink\",\"base_currency_name\":\"Chainlink\",\"base_price_last_updated\":\"2021-07-25T10:40:07Z\",\"quote_currency_id\":\"usdt-tether\",\"quote_currency_name\":\"Tether\",\"quote_price_last_updated\":\"2021-07-25T10:40:07Z\",\"amount\":1,\"price\":16.917664107956217}","level":"info","timestamp":"2021-07-25T10:41:07.797Z"}
{"message":"Result could not be found in path","level":"error","timestamp":"2021-07-25T10:41:07.797Z"}
Result:  {
  jobRunID: 0,
  status: 'errored',
  error: AdapterError: AdapterError: Result could not be found in path
      at Function.errored (/Users/pocondui/CL-EA-NodeJS-Template/node_modules/@chainlink/external-adapter/src/requester.js:90:14)
      at /Users/pocondui/CL-EA-NodeJS-Template/index.js:42:31
      at processTicksAndRejections (internal/process/task_queues.js:95:5),
  statusCode: 500

现在我需要弄清楚如何正确地传递结果

zy1mlcev

zy1mlcev1#

我修好了。2个问题传递了错误的参数,结果是错误的
将其更改为:

response.data.result = Requester.validateResultNumber(response.data, ['price'])

相关问题