Skip to content

Commit 2d4fb37

Browse files
committed
Added get functions to the contract event callbacks.
1 parent 9b54b53 commit 2d4fb37

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

contracts/contract.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,25 @@ function Contract(addressOrName, contractInterface, signerOrProvider) {
246246
log.removeListener = function() {
247247
provider.removeListener(eventInfo.topics, handleEvent);
248248
}
249+
function poller(func, key) {
250+
return new Promise(function(resolve, reject) {
251+
function poll() {
252+
provider[func](log[key]).then(function(value) {
253+
if (value == null) {
254+
setTimeout(poll, 1000);
255+
return;
256+
}
257+
resolve(value);
258+
}, function(error) {
259+
reject(error);
260+
});
261+
}
262+
poll();
263+
});
264+
}
265+
log.getBlock = function() { return poller('getBlock', 'blockHash'); }
266+
log.getTransaction = function() { return poller('getTransaction', 'transactionHash'); }
267+
log.getTransactionReceipt = function() { return poller('getTransactionReceipt', 'transactionHash'); }
249268
log.eventSignature = eventInfo.signature;
250269

251270
eventCallback.apply(log, Array.prototype.slice.call(result));

0 commit comments

Comments
 (0)