trying to store id pkh. Doesn't work; wallet creation never completes

This commit is contained in:
Tadge Dryja 2015-12-31 11:29:00 -04:00 committed by Olaoluwa Osuntokun
parent e70c6aa367
commit 8504362c5e
3 changed files with 21 additions and 14 deletions

View File

@ -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...

View File

@ -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

View File

@ -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)