chain: refactor getLocks.

This commit is contained in:
Christopher Jeffrey 2017-07-09 14:49:14 -07:00
parent 8a1eb9f5e1
commit 18c1476de9
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -2266,7 +2266,6 @@ Chain.prototype.getLocks = async function getLocks(prev, tx, view, flags) {
let disableFlag = consensus.SEQUENCE_DISABLE_FLAG;
let typeFlag = consensus.SEQUENCE_TYPE_FLAG;
let hasFlag = flags & common.lockFlags.VERIFY_SEQUENCE;
let nextHeight = this.height + 1;
let minHeight = -1;
let minTime = -1;
@ -2274,28 +2273,29 @@ Chain.prototype.getLocks = async function getLocks(prev, tx, view, flags) {
return [minHeight, minTime];
for (let input of tx.inputs) {
let coinHeight, coinTime, entry;
let height, time, entry;
if (input.sequence & disableFlag)
continue;
coinHeight = view.getHeight(input);
height = view.getHeight(input);
if (coinHeight === -1)
coinHeight = nextHeight;
if (height === -1)
height = this.height + 1;
if ((input.sequence & typeFlag) === 0) {
coinHeight += (input.sequence & mask) - 1;
minHeight = Math.max(minHeight, coinHeight);
height += (input.sequence & mask) - 1;
minHeight = Math.max(minHeight, height);
continue;
}
entry = await prev.getAncestor(Math.max(coinHeight - 1, 0));
height = Math.max(height - 1, 0);
entry = await prev.getAncestor(height);
assert(entry, 'Database is corrupt.');
coinTime = await entry.getMedianTime();
coinTime += ((input.sequence & mask) << granularity) - 1;
minTime = Math.max(minTime, coinTime);
time = await entry.getMedianTime();
time += ((input.sequence & mask) << granularity) - 1;
minTime = Math.max(minTime, time);
}
return [minHeight, minTime];