Skip to content
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
1 change: 1 addition & 0 deletions internal/rpc/jsonrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Options struct {
MixBranch uint32
MixChangeAccount string
TicketSplitAccount string
VotingAccount string

VSPHost string
VSPPubKey string
Expand Down
30 changes: 21 additions & 9 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -3343,16 +3343,28 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
var mixedAccount uint32
var mixedAccountBranch uint32
var mixedSplitAccount uint32
// Use purchasing account as change account by default (overridden below if
// mixing is enabled).
// Use purchasing account as voting and change account by default
// (overridden below if mixing is enabled, or voting account is set).
var changeAccount = account
var votingAccount = account

if s.cfg.MixingEnabled {
// Mixed ticketbuying must use the mixed account as the voting
// account. Do not permit configurations which specify a
// different voting account.
if s.cfg.VotingAccount != "" && s.cfg.VotingAccount != s.cfg.MixAccount {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
"Mixing enabled, but configured voting account %q does "+
"not match mixed account %q", s.cfg.VotingAccount,
s.cfg.MixAccount)
}

mixedAccount, err = w.AccountNumber(ctx, s.cfg.MixAccount)
if err != nil {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
"Mixing enabled, but error on mixed account: %v", err)
}
votingAccount = mixedAccount
mixedAccountBranch = s.cfg.MixBranch
if mixedAccountBranch != 0 && mixedAccountBranch != 1 {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
Expand All @@ -3368,6 +3380,12 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
"Mixing enabled, but error on changeAccount: %v", err)
}
} else if s.cfg.VotingAccount != "" {
votingAccount, err = w.AccountNumber(ctx, s.cfg.VotingAccount)
if err != nil {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
"Voting account %q: %v", s.cfg.VotingAccount, err)
}
}

var vspClient *wallet.VSPClient
Expand All @@ -3391,6 +3409,7 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
request := &wallet.PurchaseTicketsRequest{
Count: numTickets,
SourceAccount: account,
VotingAccount: votingAccount,
MinConf: minConf,
Expiry: expiry,
DontSignTx: dontSignTx,
Expand All @@ -3404,13 +3423,6 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {

VSPClient: vspClient,
}
// Use the mixed account as voting account if mixing is enabled,
// otherwise use the source account.
if s.cfg.MixingEnabled {
request.VotingAccount = mixedAccount
} else {
request.VotingAccount = account
}

ticketsResponse, err := w.PurchaseTickets(ctx, n, request)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,10 @@ func startRPCServers(ctx context.Context, walletLoader *loader.Loader) (*grpc.Se
MixAccount: cfg.mixedAccount,
MixBranch: cfg.mixedBranch,
MixChangeAccount: cfg.ChangeAccount,
TicketSplitAccount: cfg.TicketSplitAccount,
VotingAccount: cfg.TBOpts.VotingAccount,
VSPHost: cfg.VSPOpts.URL,
VSPPubKey: cfg.VSPOpts.PubKey,
TicketSplitAccount: cfg.TicketSplitAccount,
Dial: cfg.dial,
Loggers: rpcLoggers{},
}
Expand Down
Loading