Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var checkConfirmation = function (existingReceipt, isPolling, err, blockHeader, sub) {
if (!err) {
// create fake unsubscribe
if (!sub) {
sub = {
unsubscribe: function () {
clearInterval(intervalId);
}
};
}
// if we have a valid receipt we don't need to send a request
return (existingReceipt ? promiEvent.resolve(existingReceipt) : _ethereumCall.getTransactionReceipt(result))
// catch error from requesting receipt
.catch(function (err) {
sub.unsubscribe();
promiseResolved = true;
utils._fireError({message: 'Failed to check for transaction receipt:', data: err}, defer.eventEmitter, defer.reject);
})
// if CONFIRMATION listener exists check for confirmations, by setting canUnsubscribe = false
.then(function(receipt) {
if (!receipt || !receipt.blockHash) {
throw new Error('Receipt missing or blockHash null');
}
// apply extra formatters
if (method.extraFormatters && method.extraFormatters.receiptFormatter) {
receipt = method.extraFormatters.receiptFormatter(receipt);
}
sendSignedTransaction(transaction: SignedTransaction) {
const promiEvent = new PromiEvent();
const txPromiEvent = this._web3.eth.sendSignedTransaction(transaction);
txPromiEvent.on('transactionHash', hash =>
promiEvent.eventEmitter.emit('transactionHash', hash),
);
txPromiEvent.on('receipt', receipt => {
try {
const decoded = this._decodeReceipt(receipt);
promiEvent.eventEmitter.emit('receipt', decoded);
} catch (error) {
promiEvent.eventEmitter.emit('error', error);
promiEvent.eventEmitter.emit('receipt', receipt);
}
});
txPromiEvent.on('confirmation', (confirmationNumber, receipt) => {
try {
function PromiEvent() {
const { resolve, reject, eventEmitter } = Web3PromiEvent.apply(
null,
arguments
);
const originalStackTrace = new Error().stack;
function rejectHijacker(e) {
try {
const stackTrace = originalStackTrace.replace(
/^Error: \n/,
e.stack.split("\n")[0]
);
e.hijackedStack = e.stack;
e.stack = stackTrace;
} catch (_) {