lnwire: add new 32-byte persistent/pending channel ID's

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.
This commit is contained in:
Olaoluwa Osuntokun
2017-04-16 15:19:39 -07:00
parent 1bb225a9bd
commit 8147151fbf
4 changed files with 200 additions and 59 deletions

View File

@@ -0,0 +1,39 @@
package lnwire
import (
"reflect"
"testing"
"github.com/davecgh/go-spew/spew"
)
func TestShortChannelIDEncoding(t *testing.T) {
var testCases = []ShortChannelID{
{
BlockHeight: (1 << 24) - 1,
TxIndex: (1 << 24) - 1,
TxPosition: (1 << 16) - 1,
},
{
BlockHeight: 2304934,
TxIndex: 2345,
TxPosition: 5,
},
{
BlockHeight: 9304934,
TxIndex: 2345,
TxPosition: 5233,
},
}
for _, testCase := range testCases {
chanInt := testCase.ToUint64()
newChanID := NewShortChanIDFromInt(chanInt)
if !reflect.DeepEqual(testCase, newChanID) {
t.Fatalf("chan ID's don't match: expected %v got %v",
spew.Sdump(testCase), spew.Sdump(newChanID))
}
}
}