Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
context[name] = (...args) => {
// Do some arg enforcement
expectCorrectArgs(args, inputs);
// Encode ethereum function call transaction
const encodedTransaction = abiLib.rawEncode(name, buildArgArray(inputs, 'type'), args);
return Observable.create(observer => {
ethClient.sendTransaction({
from: '0xe0743179eaeb698e5e738ec388b0e44fbda8a492',
data: encodedTransaction.toString('hex'),
gas: 1000000,
}).then(
res => {
const txHash = res;
observer.next({
txHash,
});
pollWithPromise(ethClient.getTransactionReceipt, 2000, txHash)
.then(
res => {
observer.next(res);
observer.complete();
module.exports = function ({ config, db, logger }) {
Observable
.create(o => {
const watcher = chokidar
.watch(config.scanner.paths, Object.assign({
alwaysStat: true,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 1000
}
}, config.scanner))
.on('error', err => logger.error({ err }))
.on('add', (path, stat) => o.next([ path, stat ]))
.on('change', (path, stat) => o.next([ path, stat ]))
.on('unlink', (path, stat) => o.next([ path ]))
return () => watcher.close()
})
// TODO (perf) groupBy + mergeMap with concurrency.
create(abi, params) {
return Observable.create(observer => {
const ethClient = this[ETH_CLIENT];
ethClient.sendTransaction(params)
.then(
res => {
const txHash = res;
observer.next({
txHash,
});
pollWithPromise(ethClient.getTransactionReceipt, 2000, txHash)
.then(
res => {
const { contractAddress } = res;
const contract = new Contract(ethClient, abi, contractAddress);
observer.next(contract);
observer.complete();
module.exports = function ({ config, db, logger }) {
Observable
.create(o => {
const watcher = chokidar
.watch(config.scanner.paths, {
alwaysStat: true,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 100
},
...config.scanner
})
.on('error', err => logger.error({ err }))
.on('add', (path, stat) => o.next([ path, stat ]))
.on('change', (path, stat) => o.next([ path, stat ]))
.on('unlink', (path, stat) => o.next([ path ]))
return () => watcher.cancel()
})
export function pollForFilterChanges(ethClient, filterId) {
return Observable.create(observer => {
let pollTimeoutId;
const pollFunc = () =>
getFilterChanges(ethClient, filterId)
.then(
({ result }) => {
clearTimeout(pollTimeoutId);
observer.next(result);
pollTimeoutId = setTimeout(pollFunc, FILTER_CHANGES_POLL_MS);
},
err => observer.error(err)
);
pollFunc();
});
};
return function(...args: any[]) {
return Observable.create((subscriber: Subscriber) => {
let cancelled = false;
function handler(...handlerArgs: any[]) {
if (cancelled) return;
if (handlerArgs.length <= 1) {
subscriber.next(handlerArgs[0]);
} else {
subscriber.next(handlerArgs);
}
subscriber.complete();
}
args.push(handler);
func.apply(null, args);
return function() { cancelled = true; };
export function pollWithObservable(func, pollTimeoutMS, ...args) {
return Observable.create(observer => {
let pollTimeoutId;
const pollFunc = () =>
func(...args).then(
res => {
clearTimeout(pollTimeoutId);
observer.next(res);
pollTimeoutId = setTimeout(pollFunc, pollTimeoutMS);
},
err => observer.error(err)
);
pollFunc();
});
};