mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
8147151fbf
This commit does to things: moves the prior ShortChannelID struct into a new short_channel_id.go file, and also implements the new ChannelID’s currently used within he specification. These new ID’s are 32-bytes in length and used during initial channel funding as well as during normal channel updates. During initial channel funding, the ID is to be a random 32-byte string, while once normal channel operation has began, the ID is to be (txid XOR index), where index is the index of the funding outpoint.
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package lnwire
|
|
|
|
// ShortChannelID represent the set of data which is needed to retrieve all
|
|
// necessary data to validate the channel existence.
|
|
type ShortChannelID struct {
|
|
// BlockHeight is the height of the block where funding transaction
|
|
// located.
|
|
//
|
|
// NOTE: This field is limited to 3 bytes.
|
|
BlockHeight uint32
|
|
|
|
// TxIndex is a position of funding transaction within a block.
|
|
//
|
|
// NOTE: This field is limited to 3 bytes.
|
|
TxIndex uint32
|
|
|
|
// TxPosition indicating transaction output which pays to the channel.
|
|
TxPosition uint16
|
|
}
|
|
|
|
// NewShortChanIDFromInt returns a new ShortChannelID which is the decoded
|
|
// version of the compact channel ID encoded within the uint64. The format of
|
|
// the compact channel ID is as follows: 3 bytes for the block height, 3 bytes
|
|
// for the transaction index, and 2 bytes for the output index.
|
|
func NewShortChanIDFromInt(chanID uint64) ShortChannelID {
|
|
return ShortChannelID{
|
|
BlockHeight: uint32(chanID >> 40),
|
|
TxIndex: uint32(chanID>>16) & 0xFFFFFF,
|
|
TxPosition: uint16(chanID),
|
|
}
|
|
}
|
|
|
|
// ToUint64 converts the ShortChannelID into a compact format encoded within a
|
|
// uint64 (8 bytes).
|
|
func (c *ShortChannelID) ToUint64() uint64 {
|
|
// TODO(roasbeef): explicit error on overflow?
|
|
return ((uint64(c.BlockHeight) << 40) | (uint64(c.TxIndex) << 16) |
|
|
(uint64(c.TxPosition)))
|
|
}
|