Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[ACCESS_KEY_HEADER]: accessKey,
[SECRET_HEADER]: secret,
},
})
return new Promise((resolve, reject) => {
ws.on('error', error => {
error.message += '[newChainlinkNode] Error on opening websocket:'
reject(error)
})
ws.on('open', () => resolve(ws))
})
}
const jsonClient = new jayson.Client(null, null)
export const createRPCRequest = (
method: string,
params?: jayson.RequestParamsLike,
) => jsonClient.request(method, params)
// helper function that sends a message and only resolves once the
// rsponse is received
export const sendSingleMessage = (
ws: WebSocket,
request: string | object,
): Promise =>
new Promise(resolve => {
const requestData: string =
typeof request === 'object' ? JSON.stringify(request) : request
ws.send(requestData)
ws.on('message', async (data: string) => {
function createJsonRpcClient(url, { logger }) {
let params = {
host: url.hostname,
port: url.port,
path: url.pathname,
}
if (url.protocol === 'https:') {
return jayson.Client.https(params)
} else if (url.protocol === 'http:') {
return jayson.Client.http(params)
} else {
logger.error(
`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`
)
logger.note(
'The Graph Node URL must be of the following format: http(s)://host[:port]/[path]'
)
return null
}
}
.option('--api-key ', 'key corresponding to the subgraph name')
app.parse()
if (!args.node || !args.subgraphName) {
args.help()
}
let compiler = app.compilerFromArgs()
let requestUrl = new URL(args.node)
if (!requestUrl.port) {
requestUrl.port = '8020'
}
let client = jayson.Client.http(requestUrl)
client.options.headers = { Authorization: 'Bearer ' + args.apiKey }
let logger = new Logger(0, { verbosity: args.verbosity })
let deploySubgraph = ipfsHash => {
logger.status('Deploying to Graph node:', requestUrl)
logger.info('')
client.request(
'subgraph_deploy',
{ name: args.subgraphName, ipfs_hash: ipfsHash },
function(requestError, jsonRpcError, res) {
if (requestError) {
logger.fatal('HTTP error deploying the subgraph:', requestError.code)
}
if (jsonRpcError) {
logger.fatal('Error deploying the subgraph:', jsonRpcError.message)
const createJsonRpcClient = url => {
let params = {
host: url.hostname,
port: url.port,
path: url.pathname,
}
if (url.protocol === 'https:') {
return jayson.Client.https(params)
} else if (url.protocol === 'http:') {
return jayson.Client.http(params)
} else {
toolbox.print.error(
`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`
)
toolbox.print.error(
'The Graph Node URL must be of the following format: http(s)://host[:port]/[path]'
)
return null
}
}