Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async asyncPutRouting(jobCategory: string, queueName: string): Promise {
this.dispatch(saveStarted(jobCategory));
try {
const path = '/api/routing/' + encodeURIComponent(jobCategory);
const response: Response = await fetch(path, {
method: 'PUT',
body: JSON.stringify({ queue_name: queueName })
});
if (!response.ok) {
throw new Error(`Request to ${path} failed with status code ${response.status}`);
}
} catch (err) {
console.error(err);
} finally {
this.dispatch(saveFinished(jobCategory, queueName));
history.push('/routing/' + encodeURIComponent(jobCategory));
this.asyncGetRouting(jobCategory);
}
}
public async asyncPutQueue(queueName: string, args: any): Promise {
this.dispatch(saveStarted(queueName));
try {
const path = '/api/queue/' + encodeURIComponent(queueName);
const response: Response = await fetch(path, {
method: 'PUT',
body: JSON.stringify(args)
});
if (!response.ok) {
throw new Error(`Request to ${path} failed with status code ${response.status}`);
}
} catch (err) {
console.error(err);
} finally {
this.dispatch(saveFinished(queueName));
history.push('/queue/' + encodeURIComponent(queueName));
this.asyncGetQueue(queueName);
}
}
contribute = function(from, wei_amount) {
callData = _cfContract.w3.contribute.getData();
log(FgMagenta, util.format('contribute() callData: %s', callData))
tx = {
from: from.accounts[0].address,
to: _cfContract.address,
gaz:1000000,
gazPrice:0,
value:wei_amount,
data: callData
}
stx = JSONbig.stringify(tx)
log(FgBlue, 'Sending Contract-Method Tx: ' + stx)
return from.api.sendTx(stx).then( (res) => {
log(FgGreen, 'Response: ' + res)
txHash = JSONbig.parse(res).txHash.replace("\"", "")
return txHash
})
.then( (txHash) => {
return sleep(2000).then(() => {
log(FgBlue, 'Requesting Receipt')
return from.api.getReceipt(txHash)
})
})
.then( (receipt) => {
log(FgGreen, 'Tx Receipt: ' + receipt)
const formattedData = data.map(row => {
const newRow = {};
for (const k in row) {
const val = row[k];
if (['string', 'number'].indexOf(typeof val) >= 0) {
newRow[k] = val;
} else {
newRow[k] = val === null ? null : JSONbig.stringify(val);
}
}
return newRow;
});
return formattedData;
function pr(stuff) {
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader("Pragma", "no-cache");
res.setHeader("Expires", 0);
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSONbig.stringify(stuff));
}
putMeta(env, metadata, callback) {
let taskParams = [];
for (let index in metadata.mappings) {
let types = metadata.mappings[index];
for (let type in types) {
let mapping = types[type];
taskParams.push([index, type, 'mapping', JSON.stringify(mapping, null, 2)]);
}
}
for (let index in metadata.settings) {
let setting = metadata.settings[index];
taskParams.push([index, null, 'settings', JSON.stringify(setting, null, 2)]);
}
async.map(taskParams, (item, callback) => {
log.debug('Writing %s for index [%s] type [%s]', item[2], item[0], item[1]);
this.archive.write(env.options.target.file, true, item[0], item[1], item[2], item[3], callback);
}, callback);
}
render() {
const { classes } = this.props;
return (
<div>
<div>
Current
{this.props.taskQueue.current !== null && this.renderListItem(this.props.taskQueue.current, false)}
Queue
{this.props.taskQueue.queue.map(n => this.renderListItem(n, true))}
{JSONBigInt.stringify(this.state.taskCfg, undefined, 2)}
</div>
)
}
}</div>
<dd><span>{job.url}</span></dd>
<dt>Status</dt>
<dd>{job.status}</dd>
<dt>Claimed at</dt>
<dd></dd>
<dt>Failed at</dt>
<dd></dd>
<dt>Tried</dt>
<dd>{job.failCount}</dd>
<dt>Payload</dt>
<dd><pre>{JSON.stringify(job.payload)}</pre></dd>
<dt>HTTP status</dt>
<dd><span>{job.result.code}</span></dd>
<dt>HTTP body</dt>
<dd><pre>{job.result.message}</pre></dd>
<div>
</div>
);
if (this.props.value.loadingCount !== 0) {
jobInfo = <div><div></div>;</div>
checkGoalReached = function() {
callData = cfContract.w3.checkGoalReached.getData();
log(FgMagenta, util.format('checkGoalReached() callData: %s', callData))
tx = {
from: demoNodes[0].accounts[0].Address,
gaz:1000000,
gazPrice:0,
value:0,
to: cfContract.address,
data: callData
}
stx = JSONbig.stringify(tx)
log(FgBlue, 'Calling Contract Method: ' + stx)
return demoNodes[0].api.call(stx).then( (res) => {
res = JSONbig.parse(res)
log(FgBlue, 'res: ' + res.Data)
hexRes = Buffer.from(res.Data).toString()
log(FgBlue, 'Hex res: ' + hexRes)
unpacked = cfContract.parseOutput('checkGoalReached', hexRes)
log(FgGreen, 'Parsed res: ' + unpacked.toString())
})
}
checkGoalReached = function(from) {
callData = _cfContract.w3.checkGoalReached.getData();
log(FgMagenta, util.format('checkGoalReached() callData: %s', callData))
tx = {
from: from.accounts[0].address,
value:0,
to: _cfContract.address,
data: callData
}
stx = JSONbig.stringify(tx)
log(FgBlue, 'Calling Contract Method: ' + stx)
return from.api.call(stx).then( (res) => {
res = JSONbig.parse(res)
log(FgBlue, 'res: ' + res.data)
hexRes = Buffer.from(res.data).toString()
unpacked = _cfContract.parseOutput('checkGoalReached', hexRes)
log(FgGreen, 'Parsed res: ' + unpacked.toString())
})
}