diff --git a/channeldb/channel.go b/channeldb/channel.go index 9aa2bebc..2d423f57 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -99,31 +99,30 @@ type OpenChannel struct { // These don't really belong here but not sure which other file to put them yet. // PutIdKey saves the private key used for -func (c *DB) PutIdKey(priv *btcec.PrivateKey) error { +func (c *DB) PutIdKey(pkh []byte) error { return c.namespace.Update(func(tx walletdb.Tx) error { // Get the bucket dedicated to storing the meta-data for open // channels. rootBucket := tx.RootBucket() - return rootBucket.Put(identityKey, priv.Serialize()) + return rootBucket.Put(identityKey, pkh) }) } // GetIdKey returns the IdKey -func (c *DB) GetIdKey() (*btcec.PrivateKey, error) { - var privbytes []byte +func (c *DB) GetIdAdr() (*btcutil.AddressPubKeyHash, error) { + var pkh []byte err := c.namespace.View(func(tx walletdb.Tx) error { // Get the bucket dedicated to storing the meta-data for open // channels. rootBucket := tx.RootBucket() - privbytes = rootBucket.Get(identityKey) + pkh = rootBucket.Get(identityKey) return nil }) if err != nil { return nil, err } - - priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), privbytes) - return priv, nil + fmt.Printf("identity key has length %d\n", len(pkh)) + return btcutil.NewAddressPubKeyHash(pkh, ActiveNetParams) } // PutOpenChannel... diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 0548f18f..b387e0c8 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -285,7 +285,7 @@ func NewLightningWallet(config *Config) (*LightningWallet, error) { if err != nil { return nil, err } - priv, err := adrs[0].(waddrmgr.ManagedPubKeyAddress).PrivKey() + idPubkeyHash := adrs[0].Address().ScriptAddress() if err != nil { return nil, err } @@ -294,11 +294,11 @@ func NewLightningWallet(config *Config) (*LightningWallet, error) { return nil, err } cdb := channeldb.New(wallet.Manager, lnNamespace) - err = cdb.PutIdKey(priv) + err = cdb.PutIdKey(idPubkeyHash) if err != nil { return nil, err } - fmt.Printf("stored private identity key in channeldb\n") + fmt.Printf("stored identity key pubkey hash in channeldb\n") } // Wallet has been created and been initialized at this point, open it diff --git a/rpcserver.go b/rpcserver.go index 295b6dd3..88af5983 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -76,13 +76,21 @@ func (r *rpcServer) TCPListen(ctx context.Context, // LnListen listens on the default port for incoming connections //ignore args and launch listener goroutine - priv, err := r.lnwallet.ChannelDB.GetIdKey() + adr, err := r.lnwallet.ChannelDB.GetIdAdr() if err != nil { return nil, err } - fmt.Printf("got a private key. %x\n", priv.Serialize()) - + fmt.Printf("got ID address: %s\n", adr.String()) + adr2, err := r.lnwallet.Manager.Address(adr) + if err != nil { + return nil, err + } + priv, err := adr2.(waddrmgr.ManagedPubKeyAddress).PrivKey() + if err != nil { + return nil, err + } + fmt.Printf("got privkey %x\n", priv.Serialize()) // go TCPListener() resp := new(lnrpc.TCPListenResponse)