Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit cfa066a

Browse files
chrisdukakisth0br0
authored andcommitted
fix promise in isPromotable()
1 parent 66c2493 commit cfa066a

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

lib/api/api.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -639,31 +639,35 @@ api.prototype.sendTransfer = function(seed, depth, minWeightMagnitude, transfers
639639
* @param {object} params
640640
* @param callback
641641
*
642-
* @returns
642+
* @returns {array} transaction objects
643643
*/
644644
api.prototype.promoteTransaction = function(tail, depth, minWeightMagnitude, transfer, params, callback) {
645645
var self = this;
646646
if (!inputValidator.isHash(tail)) {
647647
return callback(errors.invalidTrytes());
648648
}
649649

650-
if (!self.isPromotable(tail)) {
650+
self.isPromotable(tail).then(function (isPromotable) {
651+
if (!isPromotable) {
651652
return callback(errors.inconsistentSubtangle(tail));
652-
}
653+
}
653654

654-
if (params.interrupt === true) {
655-
return callback(null, tail);
656-
}
655+
if (params.interrupt === true) {
656+
return callback(null, tail);
657+
}
657658

658-
self.sendTransfer(transfer[0].address, depth, minWeightMagnitude, transfer, {reference: tail}, function(err, res) {
659-
if (err == null && params.delay > 0) {
660-
setTimeout (function() {
661-
self.promoteTransaction(tail, depth, minWeightMagnitude, transfer, params, callback);
662-
}, params.delay);
663-
} else {
664-
return callback(err, res);
665-
}
666-
});
659+
self.sendTransfer(transfer[0].address, depth, minWeightMagnitude, transfer, {reference: tail}, function(err, res) {
660+
if (err == null && params.delay > 0) {
661+
setTimeout (function() {
662+
self.promoteTransaction(tail, depth, minWeightMagnitude, transfer, params, callback);
663+
}, params.delay);
664+
} else {
665+
return callback(err, res);
666+
}
667+
});
668+
}).catch(function (err) {
669+
callback(err)
670+
})
667671
}
668672

669673
/**
@@ -1949,6 +1953,9 @@ api.prototype.isPromotable = function(tail) {
19491953

19501954
var promise = new Promise(function(res, rej) {
19511955
self.sendCommand(command, function(err, isConsistent) {
1956+
if (err) {
1957+
rej(err)
1958+
}
19521959
res(isConsistent.state);
19531960
});
19541961
});

0 commit comments

Comments
 (0)