htlcswitch/test: create genID function
This commit is contained in:
parent
cf98e99001
commit
dcf7a8b871
@ -92,27 +92,28 @@ var (
|
|||||||
|
|
||||||
var idSeqNum uint64
|
var idSeqNum uint64
|
||||||
|
|
||||||
func genIDs() (lnwire.ChannelID, lnwire.ChannelID, lnwire.ShortChannelID,
|
// genID generates a unique tuple to identify a test channel.
|
||||||
lnwire.ShortChannelID) {
|
func genID() (lnwire.ChannelID, lnwire.ShortChannelID) {
|
||||||
|
id := atomic.AddUint64(&idSeqNum, 1)
|
||||||
id := atomic.AddUint64(&idSeqNum, 2)
|
|
||||||
|
|
||||||
var scratch [8]byte
|
var scratch [8]byte
|
||||||
|
|
||||||
binary.BigEndian.PutUint64(scratch[:], id)
|
binary.BigEndian.PutUint64(scratch[:], id)
|
||||||
hash1, _ := chainhash.NewHash(bytes.Repeat(scratch[:], 4))
|
hash1, _ := chainhash.NewHash(bytes.Repeat(scratch[:], 4))
|
||||||
|
|
||||||
binary.BigEndian.PutUint64(scratch[:], id+1)
|
|
||||||
hash2, _ := chainhash.NewHash(bytes.Repeat(scratch[:], 4))
|
|
||||||
|
|
||||||
chanPoint1 := wire.NewOutPoint(hash1, uint32(id))
|
chanPoint1 := wire.NewOutPoint(hash1, uint32(id))
|
||||||
chanPoint2 := wire.NewOutPoint(hash2, uint32(id+1))
|
|
||||||
|
|
||||||
chanID1 := lnwire.NewChanIDFromOutPoint(chanPoint1)
|
chanID1 := lnwire.NewChanIDFromOutPoint(chanPoint1)
|
||||||
chanID2 := lnwire.NewChanIDFromOutPoint(chanPoint2)
|
|
||||||
|
|
||||||
aliceChanID := lnwire.NewShortChanIDFromInt(id)
|
aliceChanID := lnwire.NewShortChanIDFromInt(id)
|
||||||
bobChanID := lnwire.NewShortChanIDFromInt(id + 1)
|
|
||||||
|
return chanID1, aliceChanID
|
||||||
|
}
|
||||||
|
|
||||||
|
// genIDs generates ids for two test channels.
|
||||||
|
func genIDs() (lnwire.ChannelID, lnwire.ChannelID, lnwire.ShortChannelID,
|
||||||
|
lnwire.ShortChannelID) {
|
||||||
|
|
||||||
|
chanID1, aliceChanID := genID()
|
||||||
|
chanID2, bobChanID := genID()
|
||||||
|
|
||||||
return chanID1, chanID2, aliceChanID, bobChanID
|
return chanID1, chanID2, aliceChanID, bobChanID
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user