lnd: modify the rpcServer's methods to use the new wallet API's
This commit is contained in:
parent
a28cf3fdf8
commit
abf658a719
46
rpcserver.go
46
rpcserver.go
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/lightningnetwork/lnd/lndc"
|
"github.com/lightningnetwork/lnd/lndc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcd/txscript"
|
"github.com/roasbeef/btcd/txscript"
|
||||||
"github.com/roasbeef/btcd/wire"
|
"github.com/roasbeef/btcd/wire"
|
||||||
@ -96,7 +97,7 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64) (*wire.ShaHash
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.server.lnwallet.SendOutputs(outputs, defaultAccount, 1)
|
return r.server.lnwallet.SendOutputs(outputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCoins executes a request to send coins to a particular address. Unlike
|
// SendCoins executes a request to send coins to a particular address. Unlike
|
||||||
@ -136,23 +137,19 @@ func (r *rpcServer) SendMany(ctx context.Context,
|
|||||||
func (r *rpcServer) NewAddress(ctx context.Context,
|
func (r *rpcServer) NewAddress(ctx context.Context,
|
||||||
in *lnrpc.NewAddressRequest) (*lnrpc.NewAddressResponse, error) {
|
in *lnrpc.NewAddressRequest) (*lnrpc.NewAddressResponse, error) {
|
||||||
|
|
||||||
r.server.lnwallet.KeyGenMtx.Lock()
|
|
||||||
defer r.server.lnwallet.KeyGenMtx.Unlock()
|
|
||||||
|
|
||||||
// Translate the gRPC proto address type to the wallet controller's
|
// Translate the gRPC proto address type to the wallet controller's
|
||||||
// available address types.
|
// available address types.
|
||||||
var addrType waddrmgr.AddressType
|
var addrType lnwallet.AddressType
|
||||||
switch in.Type {
|
switch in.Type {
|
||||||
case lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH:
|
case lnrpc.NewAddressRequest_WITNESS_PUBKEY_HASH:
|
||||||
addrType = waddrmgr.WitnessPubKey
|
addrType = lnwallet.WitnessPubKey
|
||||||
case lnrpc.NewAddressRequest_NESTED_PUBKEY_HASH:
|
case lnrpc.NewAddressRequest_NESTED_PUBKEY_HASH:
|
||||||
addrType = waddrmgr.NestedWitnessPubKey
|
addrType = lnwallet.NestedWitnessPubKey
|
||||||
case lnrpc.NewAddressRequest_PUBKEY_HASH:
|
case lnrpc.NewAddressRequest_PUBKEY_HASH:
|
||||||
addrType = waddrmgr.PubKeyHash
|
addrType = lnwallet.PubKeyHash
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := r.server.lnwallet.NewAddress(defaultAccount,
|
addr, err := r.server.lnwallet.NewAddress(addrType, false)
|
||||||
addrType)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -378,35 +375,14 @@ func (r *rpcServer) ListPeers(ctx context.Context,
|
|||||||
func (r *rpcServer) WalletBalance(ctx context.Context,
|
func (r *rpcServer) WalletBalance(ctx context.Context,
|
||||||
in *lnrpc.WalletBalanceRequest) (*lnrpc.WalletBalanceResponse, error) {
|
in *lnrpc.WalletBalanceRequest) (*lnrpc.WalletBalanceResponse, error) {
|
||||||
|
|
||||||
var balance float64
|
balance, err := r.server.lnwallet.ConfirmedBalance(1, in.WitnessOnly)
|
||||||
|
if err != nil {
|
||||||
if in.WitnessOnly {
|
return nil, err
|
||||||
witnessOutputs, err := r.server.lnwallet.ListUnspentWitness(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to convert from BTC to satoshi here otherwise, and
|
|
||||||
// incorrect sum will be returned.
|
|
||||||
var outputSum btcutil.Amount
|
|
||||||
for _, witnessOutput := range witnessOutputs {
|
|
||||||
outputSum += btcutil.Amount(witnessOutput.Amount * 1e8)
|
|
||||||
}
|
|
||||||
|
|
||||||
balance = outputSum.ToBTC()
|
|
||||||
} else {
|
|
||||||
// TODO(roasbeef): make num confs a param
|
|
||||||
outputSum, err := r.server.lnwallet.CalculateBalance(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
balance = outputSum.ToBTC()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcsLog.Debugf("[walletbalance] balance=%v", balance)
|
rpcsLog.Debugf("[walletbalance] balance=%v", balance)
|
||||||
|
|
||||||
return &lnrpc.WalletBalanceResponse{balance}, nil
|
return &lnrpc.WalletBalanceResponse{float64(balance)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PendingChannels returns a list of all the channels that are currently
|
// PendingChannels returns a list of all the channels that are currently
|
||||||
|
Loading…
Reference in New Issue
Block a user