Skip to content

Commit

Permalink
Move address definitions to payments package
Browse files Browse the repository at this point in the history
The wallet.NetworkBackend interface is now able to use dcrwallet's own
Address interface rather than using dcrutil in the definition.  This
required moving the interfaces and several implementations to be moved
from the wallet package to a new payments package to avoid a package
import cycle.

The old wallet.KnownAddress interface is renamed to wallet.Address
since it is no longer confused with the previous wallet.Address
interface (which becomes a payments interface).
  • Loading branch information
jrick committed Sep 9, 2020
1 parent 7806b30 commit ae020c8
Show file tree
Hide file tree
Showing 30 changed files with 1,141 additions and 823 deletions.
11 changes: 6 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"decred.org/dcrwallet/errors"
"decred.org/dcrwallet/internal/cfgutil"
"decred.org/dcrwallet/internal/netparams"
"decred.org/dcrwallet/payments"
"decred.org/dcrwallet/version"
"decred.org/dcrwallet/wallet"
"decred.org/dcrwallet/wallet/txrules"
Expand Down Expand Up @@ -93,7 +94,7 @@ type config struct {
EnableVoting bool `long:"enablevoting" description:"Automatically create votes and revocations"`
PurchaseAccount string `long:"purchaseaccount" description:"Account to autobuy tickets from"`
PoolAddress *cfgutil.AddressFlag `long:"pooladdress" description:"VSP fee address"`
poolAddress dcrutil.Address
poolAddress payments.Address
PoolFees float64 `long:"poolfees" description:"VSP fee percentage (1.00 equals 1.00% fee)"`
GapLimit uint32 `long:"gaplimit" description:"Allowed unused address gap between used addresses of accounts"`
StakePoolColdExtKey string `long:"stakepoolcoldextkey" description:"xpub:maxindex for fee addresses (VSP-only option)"`
Expand Down Expand Up @@ -163,7 +164,7 @@ type config struct {
type ticketBuyerOptions struct {
BalanceToMaintainAbsolute *cfgutil.AmountFlag `long:"balancetomaintainabsolute" description:"Amount of funds to keep in wallet when purchasing tickets"`
VotingAddress *cfgutil.AddressFlag `long:"votingaddress" description:"Purchase tickets with voting rights assigned to this address"`
votingAddress dcrutil.Address
votingAddress payments.Address
Limit uint `long:"limit" description:"Buy no more than specified number of tickets per block (0 disables limit)"`
VotingAccount string `long:"votingaccount" description:"Account used to derive addresses specifying voting rights"`
}
Expand Down Expand Up @@ -345,15 +346,15 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
StakePoolColdExtKey: defaultStakePoolColdExtKey,
AllowHighFees: defaultAllowHighFees,
RelayFee: cfgutil.NewAmountFlag(txrules.DefaultRelayFeePerKb),
PoolAddress: cfgutil.NewAddressFlag(),
PoolAddress: new(cfgutil.AddressFlag),
AccountGapLimit: defaultAccountGapLimit,
DisableCoinTypeUpgrades: defaultDisableCoinTypeUpgrades,
CircuitLimit: defaultCircuitLimit,

// Ticket Buyer Options
TBOpts: ticketBuyerOptions{
BalanceToMaintainAbsolute: cfgutil.NewAmountFlag(defaultBalanceToMaintainAbsolute),
VotingAddress: cfgutil.NewAddressFlag(),
VotingAddress: new(cfgutil.AddressFlag),
},
}

Expand Down Expand Up @@ -468,7 +469,7 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
// Check that no addresses were created for the wrong network
for _, a := range []struct {
flag *cfgutil.AddressFlag
addr *dcrutil.Address
addr *payments.Address
}{
{cfg.PoolAddress, &cfg.poolAddress},
{cfg.TBOpts.VotingAddress, &cfg.TBOpts.votingAddress},
Expand Down
16 changes: 6 additions & 10 deletions internal/cfgutil/address.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
// Copyright (c) 2015-2016 The btcsuite developers
// Copyright (c) 2016 The Decred developers
// Copyright (c) 2016-2020 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package cfgutil

import (
"decred.org/dcrwallet/payments"
"github.com/decred/dcrd/dcrutil/v3"
)

// AddressFlag contains a dcrutil.Address and implements the flags.Marshaler and
// Unmarshaler interfaces so it can be used as a config struct field.
// AddressFlag implements the flags.Marshaler and Unmarshaler interfaces
// and returns parsed addresses from the configured values (if any).
type AddressFlag struct {
str string
}

// NewAddressFlag creates an AddressFlag with a default dcrutil.Address.
func NewAddressFlag() *AddressFlag {
return new(AddressFlag)
}

// MarshalFlag satisfies the flags.Marshaler interface.
func (a *AddressFlag) MarshalFlag() (string, error) {
return a.str, nil
Expand All @@ -33,9 +29,9 @@ func (a *AddressFlag) UnmarshalFlag(addr string) error {

// Address decodes the address flag for the network described by params.
// If the flag is the empty string, this returns a nil address.
func (a *AddressFlag) Address(params dcrutil.AddressParams) (dcrutil.Address, error) {
func (a *AddressFlag) Address(params dcrutil.AddressParams) (payments.Address, error) {
if a.str == "" {
return nil, nil
}
return dcrutil.DecodeAddress(a.str, params)
return payments.DecodeAddress(a.str, params)
}
9 changes: 3 additions & 6 deletions internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"

"decred.org/dcrwallet/errors"
"decred.org/dcrwallet/payments"
"decred.org/dcrwallet/wallet"
_ "decred.org/dcrwallet/wallet/drivers/bdb" // driver loaded during init
"github.com/decred/dcrd/chaincfg/v3"
Expand Down Expand Up @@ -51,9 +52,8 @@ type Loader struct {
// StakeOptions contains the various options necessary for stake mining.
type StakeOptions struct {
VotingEnabled bool
AddressReuse bool
VotingAddress dcrutil.Address
PoolAddress dcrutil.Address
VotingAddress payments.Address
PoolAddress payments.Address
PoolFees float64
StakePoolColdExtKey string
}
Expand Down Expand Up @@ -170,7 +170,6 @@ func (l *Loader) CreateWatchingOnlyWallet(ctx context.Context, extendedPubKey st
DB: db,
PubPassphrase: pubPass,
VotingEnabled: so.VotingEnabled,
AddressReuse: so.AddressReuse,
VotingAddress: so.VotingAddress,
PoolAddress: so.PoolAddress,
PoolFees: so.PoolFees,
Expand Down Expand Up @@ -261,7 +260,6 @@ func (l *Loader) CreateNewWallet(ctx context.Context, pubPassphrase, privPassphr
DB: db,
PubPassphrase: pubPassphrase,
VotingEnabled: so.VotingEnabled,
AddressReuse: so.AddressReuse,
VotingAddress: so.VotingAddress,
PoolAddress: so.PoolAddress,
PoolFees: so.PoolFees,
Expand Down Expand Up @@ -321,7 +319,6 @@ func (l *Loader) OpenExistingWallet(ctx context.Context, pubPassphrase []byte) (
DB: db,
PubPassphrase: pubPassphrase,
VotingEnabled: so.VotingEnabled,
AddressReuse: so.AddressReuse,
VotingAddress: so.VotingAddress,
PoolAddress: so.PoolAddress,
PoolFees: so.PoolFees,
Expand Down
2 changes: 1 addition & 1 deletion internal/rpc/jsonrpc/marshaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func addressArrayMarshaler(n int, s func(i int) string) json.Marshaler {
})
}

func knownAddressMarshaler(addrs []wallet.KnownAddress) json.Marshaler {
func walletAddressMarshaler(addrs []wallet.Address) json.Marshaler {
return addressArrayMarshaler(len(addrs), func(i int) string {
return addrs[i].String()
})
Expand Down
Loading

0 comments on commit ae020c8

Please sign in to comment.