diff --git a/mock.go b/mock.go index e339bf87..a254f4ba 100644 --- a/mock.go +++ b/mock.go @@ -226,6 +226,11 @@ func (m *mockWalletController) NewAddress(addrType lnwallet.AddressType, m.rootKey.PubKey().SerializeCompressed(), &chaincfg.MainNetParams) return addr, nil } +func (*mockWalletController) LastUnusedAddress(addrType lnwallet.AddressType) ( + btcutil.Address, error) { + return nil, nil +} + func (*mockWalletController) IsOurAddress(a btcutil.Address) bool { return false } diff --git a/rpcserver.go b/rpcserver.go index f4fc68b9..4cacd106 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -932,17 +932,42 @@ func (r *rpcServer) NewAddress(ctx context.Context, // Translate the gRPC proto address type to the wallet controller's // available address types. - var addrType lnwallet.AddressType + var ( + addr btcutil.Address + err error + ) switch in.Type { case lnrpc.AddressType_WITNESS_PUBKEY_HASH: - addrType = lnwallet.WitnessPubKey - case lnrpc.AddressType_NESTED_PUBKEY_HASH: - addrType = lnwallet.NestedWitnessPubKey - } + addr, err = r.server.cc.wallet.NewAddress( + lnwallet.WitnessPubKey, false, + ) + if err != nil { + return nil, err + } - addr, err := r.server.cc.wallet.NewAddress(addrType, false) - if err != nil { - return nil, err + case lnrpc.AddressType_NESTED_PUBKEY_HASH: + addr, err = r.server.cc.wallet.NewAddress( + lnwallet.NestedWitnessPubKey, false, + ) + if err != nil { + return nil, err + } + + case lnrpc.AddressType_UNUSED_WITNESS_PUBKEY_HASH: + addr, err = r.server.cc.wallet.LastUnusedAddress( + lnwallet.WitnessPubKey, + ) + if err != nil { + return nil, err + } + + case lnrpc.AddressType_UNUSED_NESTED_PUBKEY_HASH: + addr, err = r.server.cc.wallet.LastUnusedAddress( + lnwallet.NestedWitnessPubKey, + ) + if err != nil { + return nil, err + } } rpcsLog.Infof("[newaddress] addr=%v", addr.String())