Skip to content

Commit 73f6bde

Browse files
committed
cmd: update to new sphinx API
1 parent bc94cdd commit 73f6bde

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

cmd/main.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"os"
1010
"strings"
1111

12-
sphinx "github.com/lightningnetwork/lightning-onion"
1312
"github.com/btcsuite/btcd/btcec"
1413
"github.com/btcsuite/btcd/chaincfg"
14+
sphinx "github.com/lightningnetwork/lightning-onion"
1515
)
1616

1717
// main implements a simple command line utility that can be used in order to
@@ -25,7 +25,7 @@ func main() {
2525
if len(args) == 1 {
2626
fmt.Printf("Usage: %s (generate|decode) <private-keys>\n", args[0])
2727
} else if args[1] == "generate" {
28-
var route []*btcec.PublicKey
28+
var path sphinx.PaymentPath
2929
for i, hexKey := range args[2:] {
3030
binKey, err := hex.DecodeString(hexKey)
3131
if err != nil || len(binKey) != 33 {
@@ -37,23 +37,22 @@ func main() {
3737
panic(err)
3838
}
3939

40-
route = append(route, pubkey)
40+
path[i] = sphinx.OnionHop{
41+
NodePub: *pubkey,
42+
HopData: sphinx.HopData{
43+
Realm: [1]byte{0x00},
44+
ForwardAmount: uint64(i),
45+
OutgoingCltv: uint32(i),
46+
},
47+
}
48+
copy(path[i].HopData.NextAddress[:], bytes.Repeat([]byte{byte(i)}, 8))
49+
4150
fmt.Fprintf(os.Stderr, "Node %d pubkey %x\n", i, pubkey.SerializeCompressed())
4251
}
4352

4453
sessionKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), bytes.Repeat([]byte{'A'}, 32))
4554

46-
var hopsData []sphinx.HopData
47-
for i := 0; i < len(route); i++ {
48-
hopsData = append(hopsData, sphinx.HopData{
49-
Realm: 0x00,
50-
ForwardAmount: uint64(i),
51-
OutgoingCltv: uint32(i),
52-
})
53-
copy(hopsData[i].NextAddress[:], bytes.Repeat([]byte{byte(i)}, 8))
54-
}
55-
56-
msg, err := sphinx.NewOnionPacket(route, sessionKey, hopsData, assocData)
55+
msg, err := sphinx.NewOnionPacket(&path, sessionKey, assocData)
5756
if err != nil {
5857
log.Fatalf("Error creating message: %v", err)
5958
}

0 commit comments

Comments
 (0)