Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move address definitions to payments package #1820

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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