blockchain: add new LockTimeToSequence function
This commit adds a new function to the package: `LockTimeToSequence`. The function is a simple utility function which aides the caller to mapping a targeted time or block based relative lock-time to the appropriate sequence number.
This commit is contained in:
parent
1914200080
commit
de709f28f6
1 changed files with 18 additions and 0 deletions
|
@ -828,6 +828,24 @@ func (b *BlockChain) calcSequenceLock(tx *btcutil.Tx, utxoView *UtxoViewpoint,
|
|||
return sequenceLock, nil
|
||||
}
|
||||
|
||||
// LockTimeToSequence converts the passed relative locktime to a sequence
|
||||
// number in accordance to BIP-68.
|
||||
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
||||
// * (Compatibility)
|
||||
func LockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
||||
// If we're expressing the relative lock time in blocks, then the
|
||||
// corresponding sequence number is simply the desired input age.
|
||||
if !isSeconds {
|
||||
return locktime
|
||||
}
|
||||
|
||||
// Set the 22nd bit which indicates the lock time is in seconds, then
|
||||
// shift the locktime over by 9 since the time granularity is in
|
||||
// 512-second intervals (2^9). This results in a max lock-time of
|
||||
// 33,553,920 seconds, or 1.1 years.
|
||||
return wire.SequenceLockTimeIsSeconds | uint32(locktime>>wire.SequenceLockTimeGranularity)
|
||||
}
|
||||
|
||||
// getReorganizeNodes finds the fork point between the main chain and the passed
|
||||
// node and returns a list of block nodes that would need to be detached from
|
||||
// the main chain and a list of block nodes that would need to be attached to
|
||||
|
|
Loading…
Reference in a new issue