From 2f9fc2d450f8a783f3a45e1724ab3087daca4cb3 Mon Sep 17 00:00:00 2001 From: cjepson Date: Mon, 15 Feb 2016 11:52:14 -0500 Subject: [PATCH] Add JSON RPC handling for per transaction VoteBits manipulation This adds the JSON handling for the per ticket manipulation of the VoteBits field in wallet. --- dcrjson/dcrwalletextcmds.go | 42 ++++++++++++++++++++++++++++++---- dcrjson/dcrwalletextresults.go | 7 ++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/dcrjson/dcrwalletextcmds.go b/dcrjson/dcrwalletextcmds.go index 5013f20043..a07faacb13 100644 --- a/dcrjson/dcrwalletextcmds.go +++ b/dcrjson/dcrwalletextcmds.go @@ -124,6 +124,23 @@ type GetTicketsCmd struct { IncludeImmature bool } +// NewGetTicketsCmd returns a new instance which can be used to issue a +// gettickets JSON-RPC command. +func NewGetTicketsCmd(includeImmature bool) *GetTicketsCmd { + return &GetTicketsCmd{includeImmature} +} + +// GetTicketVotesBitsCmd defines the getticketsvotebits JSON-RPC command. +type GetTicketVoteBitsCmd struct { + TxHash string +} + +// NewGetTicketVoteBitsCmd returns a new instance which can be used to issue +// a getticketvotebits JSON-RPC command. +func NewGetTicketVoteBitsCmd(txHash string) *GetTicketVoteBitsCmd { + return &GetTicketVoteBitsCmd{TxHash: txHash} +} + // GetWalletFeeCmd defines the getwalletfee JSON-RPC command. type GetWalletFeeCmd struct{} @@ -134,11 +151,6 @@ func NewGetWalletFeeCmd() *GetWalletFeeCmd { return &GetWalletFeeCmd{} } -// NewGetTicketsCmd creates a new GetTicketsCmd. -func NewGetTicketsCmd(includeImmature bool) *GetTicketsCmd { - return &GetTicketsCmd{includeImmature} -} - // ImportScriptCmd is a type for handling custom marshaling and // unmarshaling of importscript JSON wallet extension commands. type ImportScriptCmd struct { @@ -361,6 +373,24 @@ func NewSetTicketMaxPriceCmd(max float64) *SetTicketMaxPriceCmd { } } +// SetTicketVoteBitsCmd is a type handling custom marshaling and +// unmarshaling of setticketvotebits JSON RPC commands. +type SetTicketVoteBitsCmd struct { + TxHash string + VoteBits uint16 + VoteBitsExt *string +} + +// NewSetTicketVoteBitsCmd creates a new instance of the setticketvotebits +// command. +func NewSetTicketVoteBitsCmd(txHash string, voteBits uint16, voteBitsExt *string) *SetTicketVoteBitsCmd { + return &SetTicketVoteBitsCmd{ + TxHash: txHash, + VoteBits: voteBits, + VoteBitsExt: voteBitsExt, + } +} + // SignRawTransactionsCmd defines the signrawtransactions JSON-RPC command. type SignRawTransactionsCmd struct { RawTxs []string @@ -390,6 +420,7 @@ func init() { MustRegisterCmd("getseed", (*GetSeedCmd)(nil), flags) MustRegisterCmd("getticketmaxprice", (*GetTicketMaxPriceCmd)(nil), flags) MustRegisterCmd("gettickets", (*GetTicketsCmd)(nil), flags) + MustRegisterCmd("getticketvotebits", (*GetTicketVoteBitsCmd)(nil), flags) MustRegisterCmd("importscript", (*ImportScriptCmd)(nil), flags) MustRegisterCmd("notifynewtickets", (*NotifyNewTicketsCmd)(nil), flags) MustRegisterCmd("notifyspentandmissedtickets", @@ -406,5 +437,6 @@ func init() { MustRegisterCmd("sendtossgen", (*SendToSSGenCmd)(nil), flags) MustRegisterCmd("sendtossrtx", (*SendToSSRtxCmd)(nil), flags) MustRegisterCmd("setticketmaxprice", (*SetTicketMaxPriceCmd)(nil), flags) + MustRegisterCmd("setticketvotebits", (*SetTicketVoteBitsCmd)(nil), flags) MustRegisterCmd("signrawtransactions", (*SignRawTransactionsCmd)(nil), flags) } diff --git a/dcrjson/dcrwalletextresults.go b/dcrjson/dcrwalletextresults.go index f2a55c21f3..5e82e76684 100644 --- a/dcrjson/dcrwalletextresults.go +++ b/dcrjson/dcrwalletextresults.go @@ -46,6 +46,13 @@ type GetTicketsResult struct { Hashes []string `json:"hashes"` } +// GetTicketVoteBitsResult models the data returned from the getticketvotebits +// command. +type GetTicketVoteBitsResult struct { + VoteBits uint16 `json:"votebits"` + VoteBitsExt string `json:"votebitsext"` +} + // GetWalletFeeResult models the data returned from the getwalletfee command type GetWalletFeeResult struct { Fee float64 `json:"fee"`