lnd.xprv/lnwire/channel_id.go
Olaoluwa Osuntokun d884efea29
lnwire+lnd: Make Logging Messages Great Again
This commit modifies the login of sent/recv’d wire messages in trace
mode in order utilize the more detailed, and automatically generated
logging statements using pure spew.Sdump.

In order to avoid the spammy messages due to spew printing the
btcec.S256() curve paramter within wire messages with public keys, we
introduce a new logging function to unset the curve paramter to it
isn’t printed in its entirety. To insure we don’t run into any panics
as a result of a nil pointer defense, we now copy the public keys
during the funding process so we don’t run into a panic due to
modifying a pointer to the same object.
2017-01-14 17:52:18 -08:00

40 lines
1.3 KiB
Go

package lnwire
// ChannelID represent the set of data which is needed to retrieve all
// necessary data to validate the channel existence.
type ChannelID 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
}
// NewChanIDFromInt returns a new ChannelID 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 NewChanIDFromInt(chanID uint64) ChannelID {
return ChannelID{
BlockHeight: uint32(chanID >> 40),
TxIndex: uint32(chanID>>16) & 0xFFFFFF,
TxPosition: uint16(chanID),
}
}
// ToUint64 converts the ChannelID into a compact format encoded within a
// uint64 (8 bytes).
func (c *ChannelID) ToUint64() uint64 {
// TODO(roasbeef): explicit error on overflow?
return ((uint64(c.BlockHeight) << 40) | (uint64(c.TxIndex) << 16) |
(uint64(c.TxPosition)))
}