From f64c92ef555b1c4d6eccdd66c70c0ea79222d0a7 Mon Sep 17 00:00:00 2001 From: "mati108@gmail.com" <34651529+matbenitez@users.noreply.github.com> Date: Wed, 13 Feb 2019 17:24:17 -0300 Subject: [PATCH] Updating to axios and new sing method on key vault --- Exchange/ExchangeAPI.js | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/Exchange/ExchangeAPI.js b/Exchange/ExchangeAPI.js index 2ad5eddfd..3dde860f9 100644 --- a/Exchange/ExchangeAPI.js +++ b/Exchange/ExchangeAPI.js @@ -7,7 +7,7 @@ */ const _ = require('lodash') const isValidOrder = require('./exchangeUtils').isValidOrder - const graphqlClient = require('graphql-client') + const axios = require('axios') const appRoot = require('app-root-path') const auth = require(`${appRoot}/utils/auth`) @@ -55,37 +55,38 @@ function createKeyVaultAPIClient(authToken) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] createKeyVaultAPIClient -> Entering function."); } - const keyVaultAPI = graphqlClient({ - url: global.GATEWAY_ENDPOINT, - headers: { - Authorization: 'Bearer ' + authToken - } - }); - + const keyVaultAPI = {} keyVaultAPI.signTransaction = function (transaction, next) { - let variables = { - botId: bot.codeName, - transaction: transaction - } + axios({ + url: global.GATEWAY_ENDPOINT, + method: 'post', + data: { + query: ` + mutation keyVault_SignTransaction($keyId: String!, $cloneId: String!, $transaction: String!){ + keyVault_SignTransaction(keyId: $keyId, cloneId: $cloneId, transaction: $transaction){ + key, + signature, + date + } + } + `, + variables: { + keyId: process.env.KEY_ID, + cloneId: process.env.CLONE_ID, + transaction: transaction + } + }, + headers: { + authorization: 'Bearer ' + authToken + } - keyVaultAPI.query(` - mutation($botId: String, $transaction: String!){ - keyVault_SignTransaction(botId: $botId, transaction: $transaction){ - key, - signature, - date - } - }`, variables, function (req, res) { - if (res.status === 401) { - next(undefined, 'Error from graphql: Not authorized'); - } }).then(res => { if (res.errors) { next(undefined, 'Error from graphql: ' + res.errors); } else { let signature = { - Key: res.data.keyVault_SignTransaction.key, - Sign: res.data.keyVault_SignTransaction.signature + Key: res.data.data.keyVault_SignTransaction.key, + Sign: res.data.data.keyVault_SignTransaction.signature } next(signature) }