channeldb: move node ID/addr funds to node.go
This commit is contained in:
parent
3e3948a04f
commit
6155fd5d01
@ -1 +1,54 @@
|
||||
package channeldb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
var (
|
||||
idBucket = []byte("i")
|
||||
)
|
||||
|
||||
// PutIdKey saves the hash160 of the public key used for our identity within
|
||||
// the Lightning Network.
|
||||
func (d *DB) PutIdKey(pkh []byte) error {
|
||||
return d.db.Update(func(tx *bolt.Tx) error {
|
||||
// Get the bucket dedicated to storing the meta-data for open
|
||||
// channels.
|
||||
bucket, err := tx.CreateBucketIfNotExists(idBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return bucket.Put(identityKey, pkh)
|
||||
})
|
||||
}
|
||||
|
||||
// GetIdKey returns the hash160 of the public key used for out identity within
|
||||
// the Lightning Network as a p2pkh bitcoin address.
|
||||
func (d *DB) GetIdAdr() (*btcutil.AddressPubKeyHash, error) {
|
||||
pkh := make([]byte, ripemd160.Size)
|
||||
err := d.db.View(func(tx *bolt.Tx) error {
|
||||
// Get the bucket dedicated to storing the meta-data for open
|
||||
// channels.
|
||||
bucket := tx.Bucket(idBucket)
|
||||
if bucket == nil {
|
||||
return fmt.Errorf("id bucket not created")
|
||||
}
|
||||
|
||||
pkBytes := bucket.Get(identityKey)
|
||||
copy(pkh, pkBytes)
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Infof("identity key has length %d", len(pkh))
|
||||
return btcutil.NewAddressPubKeyHash(pkh, ActiveNetParams)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user