diff --git a/internal/rpc/jsonrpc/config.go b/internal/rpc/jsonrpc/config.go index 62ac3fed8..b1939695f 100644 --- a/internal/rpc/jsonrpc/config.go +++ b/internal/rpc/jsonrpc/config.go @@ -22,6 +22,7 @@ type Options struct { MixBranch uint32 MixChangeAccount string TicketSplitAccount string + VotingAccount string VSPHost string VSPPubKey string diff --git a/internal/rpc/jsonrpc/methods.go b/internal/rpc/jsonrpc/methods.go index cd837ecfc..90867ecd6 100644 --- a/internal/rpc/jsonrpc/methods.go +++ b/internal/rpc/jsonrpc/methods.go @@ -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, @@ -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 @@ -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, @@ -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 { diff --git a/rpcserver.go b/rpcserver.go index 6734337bd..3d2189b3b 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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{}, }