@@ -3811,6 +3811,9 @@ func (s *Server) setDisapprovePercent(ctx context.Context, icmd interface{}) (in
38113811
38123812// setTreasuryPolicy saves the voting policy for treasury spends by a particular
38133813// key, and optionally, setting the key policy used by a specific ticket.
3814+ //
3815+ // If a VSP host is configured in the application settings, the voting
3816+ // preferences will also be set with the VSP.
38143817func (s * Server ) setTreasuryPolicy (ctx context.Context , icmd interface {}) (interface {}, error ) {
38153818 cmd := icmd .(* types.SetTreasuryPolicyCmd )
38163819 w , ok := s .walletLoader .LoadedWallet ()
@@ -3854,6 +3857,16 @@ func (s *Server) setTreasuryPolicy(ctx context.Context, icmd interface{}) (inter
38543857 }
38553858
38563859 err = w .SetTreasuryKeyPolicy (ctx , pikey , policy , ticketHash )
3860+ if err != nil {
3861+ return nil , err
3862+ }
3863+
3864+ // Update voting preferences on VSPs if required.
3865+ policyMap := map [string ]string {
3866+ cmd .Key : cmd .Policy ,
3867+ }
3868+ err = s .updateVSPVoteChoices (ctx , w , ticketHash , nil , nil , policyMap )
3869+
38573870 return nil , err
38583871}
38593872
@@ -3929,6 +3942,9 @@ func (s *Server) tspendPolicy(ctx context.Context, icmd interface{}) (interface{
39293942
39303943// setTSpendPolicy saves the voting policy for a particular tspend transaction
39313944// hash, and optionally, setting the tspend policy used by a specific ticket.
3945+ //
3946+ // If a VSP host is configured in the application settings, the voting
3947+ // preferences will also be set with the VSP.
39323948func (s * Server ) setTSpendPolicy (ctx context.Context , icmd interface {}) (interface {}, error ) {
39333949 cmd := icmd .(* types.SetTSpendPolicyCmd )
39343950 w , ok := s .walletLoader .LoadedWallet ()
@@ -3975,6 +3991,15 @@ func (s *Server) setTSpendPolicy(ctx context.Context, icmd interface{}) (interfa
39753991 }
39763992
39773993 err = w .SetTSpendPolicy (ctx , hash , policy , ticketHash )
3994+ if err != nil {
3995+ return nil , err
3996+ }
3997+
3998+ // Update voting preferences on VSPs if required.
3999+ policyMap := map [string ]string {
4000+ cmd .Hash : cmd .Policy ,
4001+ }
4002+ err = s .updateVSPVoteChoices (ctx , w , ticketHash , nil , policyMap , nil )
39784003 return nil , err
39794004}
39804005
@@ -4635,34 +4660,42 @@ func (s *Server) setVoteChoice(ctx context.Context, icmd interface{}) (interface
46354660 ticketHash = hash
46364661 }
46374662
4638- choice := wallet.AgendaChoice {
4639- AgendaID : cmd .AgendaID ,
4640- ChoiceID : cmd .ChoiceID ,
4663+ choice := []wallet.AgendaChoice {
4664+ {
4665+ AgendaID : cmd .AgendaID ,
4666+ ChoiceID : cmd .ChoiceID ,
4667+ },
46414668 }
4642- _ , err := w .SetAgendaChoices (ctx , ticketHash , choice )
4669+ _ , err := w .SetAgendaChoices (ctx , ticketHash , choice ... )
46434670 if err != nil {
46444671 return nil , err
46454672 }
46464673
46474674 // Update voting preferences on VSPs if required.
4675+ err = s .updateVSPVoteChoices (ctx , w , ticketHash , choice , nil , nil )
4676+ return nil , err
4677+ }
4678+
4679+ func (s * Server ) updateVSPVoteChoices (ctx context.Context , w * wallet.Wallet , ticketHash * chainhash.Hash ,
4680+ choices []wallet.AgendaChoice , tspendPolicy map [string ]string , treasuryPolicy map [string ]string ) error {
46484681 if ticketHash != nil {
46494682 vspHost , err := w .VSPHostForTicket (ctx , ticketHash )
46504683 if err != nil {
46514684 if errors .Is (err , errors .NotExist ) {
46524685 // Ticket is not registered with a VSP, nothing more to do here.
4653- return nil , nil
4686+ return nil
46544687 }
4655- return nil , err
4688+ return err
46564689 }
46574690 vspClient , err := loader .LookupVSP (vspHost )
46584691 if err != nil {
4659- return nil , err
4692+ return err
46604693 }
4661- err = vspClient .SetVoteChoice (ctx , ticketHash , choice )
4662- return nil , err
4694+ err = vspClient .SetVoteChoice (ctx , ticketHash , choices , tspendPolicy , treasuryPolicy )
4695+ return err
46634696 }
46644697 var firstErr error
4665- err = w .ForUnspentUnexpiredTickets (ctx , func (hash * chainhash.Hash ) error {
4698+ err : = w .ForUnspentUnexpiredTickets (ctx , func (hash * chainhash.Hash ) error {
46664699 vspHost , err := w .VSPHostForTicket (ctx , hash )
46674700 if err != nil && firstErr == nil {
46684701 if errors .Is (err , errors .NotExist ) {
@@ -4679,16 +4712,16 @@ func (s *Server) setVoteChoice(ctx context.Context, icmd interface{}) (interface
46794712 }
46804713 // Never return errors here, so all tickets are tried.
46814714 // The first error will be returned to the user.
4682- err = vspClient .SetVoteChoice (ctx , hash , choice )
4715+ err = vspClient .SetVoteChoice (ctx , hash , choices , tspendPolicy , treasuryPolicy )
46834716 if err != nil && firstErr == nil {
46844717 firstErr = err
46854718 }
46864719 return nil
46874720 })
46884721 if err != nil {
4689- return nil , err
4722+ return err
46904723 }
4691- return nil , firstErr
4724+ return firstErr
46924725}
46934726
46944727// signMessage signs the given message with the private key for the given
0 commit comments