Skip to content

Commit

Permalink
Added getticketsvotebits functionality to the legacy RPC
Browse files Browse the repository at this point in the history
The new command getticketsvotebits has been added to the legacy RPC.
The command allows the caller to pass a list of tickets to the RPC and
get a list of voteBits data in return.
  • Loading branch information
cjepson committed Mar 1, 2016
1 parent ee276f6 commit 12ff153
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
18 changes: 18 additions & 0 deletions internal/rpchelp/helpdescs_en_US.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ var helpDescsEnUS = map[string]string{
"gettickets--synopsis": "Returning the hashes of the tickets currently owned by wallet.",
"gettickets-includeimmature": "If true include immature tickets in the results.",

// GetTicketVoteBits help.
"getticketvotebits--synopsis": "Retrieve the intended voteBits for any given ticket",
"getticketvotebits-txhash": "The hash of the ticket",
"getticketvotebitsresult-votebitsdata": "The voteBits and extended voteBits for this ticket",
"votebitsdata-votebits": "The voteBits for this ticket",
"votebitsdata-votebitsext": "The extended voteBits for this ticket",

// GetTicketsVoteBits help.
"getticketsvotebits--synopsis": "Retrieve the intended voteBits for any given list of tickets",
"getticketsvotebits-txhashes": "The list of ticket hashes",
"getticketsvotebitsresult-votebitslist": "The voteBits and extended voteBits for all tickets passed",

// GetTicketMaxPrice help.
"getticketmaxprice--synopsis": "Returns the max price the wallet will pay for a ticket.",
"getticketmaxprice--result0": "Max price wallet will spend on a ticket.",
Expand Down Expand Up @@ -380,6 +392,12 @@ var helpDescsEnUS = map[string]string{
"setticketmaxprice--synopsis": "Set the max price user is willing to pay for a ticket.",
"setticketmaxprice-max": "The max price (in dcr).",

// SetTicketVoteBits
"setticketvotebits--synopsis": "Set the voteBits to be used when voting for any given ticket",
"setticketvotebits-txhash": "The hash of the ticket",
"setticketvotebits-votebits": "The voteBits to set for the ticket",
"setticketvotebits-votebitsext": "The extended voteBits to set for the ticket",

// SetTxFeeCmd help.
"settxfee--synopsis": "Modify the increment used each time more fee is required for an authored transaction.",
"settxfee-amount": "The new fee increment valued in decred",
Expand Down
3 changes: 3 additions & 0 deletions internal/rpchelp/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ var Methods = []struct {
{"sendtossrtx", returnsString},
{"sendtosstx", returnsString},
{"sendtossgen", returnsString},
{"getticketvotebits", []interface{}{(*dcrjson.GetTicketVoteBitsResult)(nil)}},
{"getticketsvotebits", []interface{}{(*dcrjson.GetTicketsVoteBitsResult)(nil)}},
{"setticketvotebits", nil},
{"getstakeinfo", []interface{}{(*dcrjson.GetStakeInfoResult)(nil)}},
{"getticketfee", returnsNumber},
{"setticketfee", returnsBool},
Expand Down
49 changes: 45 additions & 4 deletions rpc/legacyrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var rpcHandlers = map[string]struct {
"getticketmaxprice": {handler: GetTicketMaxPrice},
"gettickets": {handlerWithChain: GetTickets},
"getticketvotebits": {handler: GetTicketVoteBits},
"getticketsvotebits": {handler: GetTicketsVoteBits},
"gettransaction": {handler: GetTransaction},
"getwalletfee": {handler: GetWalletFee},
"help": {handler: HelpNoChainRPC, handlerWithChain: HelpWithChainRPC},
Expand Down Expand Up @@ -1392,17 +1393,57 @@ func GetTicketVoteBits(icmd interface{}, w *wallet.Wallet) (interface{}, error)
}
if !set {
return &dcrjson.GetTicketVoteBitsResult{
VoteBits: w.VoteBits,
VoteBitsExt: "",
dcrjson.VoteBitsData{
VoteBits: w.VoteBits,
VoteBitsExt: "",
},
}, nil
}

return &dcrjson.GetTicketVoteBitsResult{
VoteBits: voteBits,
VoteBitsExt: "",
dcrjson.VoteBitsData{
VoteBits: voteBits,
VoteBitsExt: "",
},
}, nil
}

// GetTicketsVoteBits fetches the per-ticket voteBits for a given array of ticket
// hashes. If the voteBits are unset, it returns the default voteBits.
// Otherwise, it returns the voteBits it finds. Missing tickets return an
// error.
func GetTicketsVoteBits(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
cmd := icmd.(*dcrjson.GetTicketsVoteBitsCmd)
ticketsLen := len(cmd.TxHashes)
ticketHashes := make([]*chainhash.Hash, 0, ticketsLen)
for _, thStr := range cmd.TxHashes {
h, err := chainhash.NewHashFromStr(thStr)
if err != nil {
return nil, err
}
ticketHashes = append(ticketHashes, h)
}

voteBitsData := make([]dcrjson.VoteBitsData, 0, ticketsLen)
for _, th := range ticketHashes {
set, voteBits, err := w.StakeMgr.SStxVoteBits(th)
if err != nil {
return nil, err
}
var vbr dcrjson.VoteBitsData
if !set {
vbr.VoteBits = w.VoteBits
vbr.VoteBitsExt = ""
} else {
vbr.VoteBits = voteBits
vbr.VoteBitsExt = ""
}
voteBitsData = append(voteBitsData, vbr)
}

return &dcrjson.GetTicketsVoteBitsResult{VoteBitsList: voteBitsData}, nil
}

// GetTransaction handles a gettransaction request by returning details about
// a single transaction saved by wallet.
func GetTransaction(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
Expand Down
5 changes: 4 additions & 1 deletion rpc/legacyrpc/rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func helpDescsEnUS() map[string]string {
"sendtossrtx": "sendtossrtx \"fromaccount\" \"tickethash\" (\"comment\")\n\nSend to SS Revocation transaction\n\nArguments:\n1. fromaccount (string, required) The account to spend a stake ticket from (default=\"default\")\n2. tickethash (string, required) Hash of the ticket to be revoked\n3. comment (string, optional) Unused\n\nResult:\n\"value\" (string) txid of the resulting transaction\n",
"sendtosstx": "sendtosstx \"fromaccount\" amounts [{\"txid\":\"value\",\"vout\":n,\"tree\":n,\"amt\":n},...] [{\"addr\":\"value\",\"commitamt\":n,\"changeaddr\":\"value\",\"changeamt\":n},...] (minconf=1 \"comment\")\n\nSend to SStx\n\nArguments:\n1. fromaccount (string, required) The account sent from\n2. amounts (object, required) Amounts to send\n{\n \"Key\": Value, (object) Unused\n ...\n}\n3. inputs (array of object, required) Inputs for the tx\n[{\n \"txid\": \"value\", (string) Txid to use\n \"vout\": n, (numeric) Vout for the input tx\n \"tree\": n, (numeric) Input tree\n \"amt\": n, (numeric) Amount\n},...]\n4. couts (array of object, required) Couts for the tx\n[{\n \"addr\": \"value\", (string) Address to use\n \"commitamt\": n, (numeric) Amount to commit\n \"changeaddr\": \"value\", (string) Change address to use\n \"changeamt\": n, (numeric) Change amount\n},...]\n5. minconf (numeric, optional, default=1) Minimum number of block confirmations required\n6. comment (string, optional) Unused\n\nResult:\n\"value\" (string) txid of the resulting transaction\n",
"sendtossgen": "sendtossgen \"fromaccount\" \"tickethash\" \"blockhash\" height votebits (\"comment\")\n\nGenerate a vote tx\n\nArguments:\n1. fromaccount (string, required) The account to use (default=\"default\")\n2. tickethash (string, required) Hash of the ticket used for vote\n3. blockhash (string, required) Hash for the block being voted on\n4. height (numeric, required) Blockheight for vote\n5. votebits (numeric, required) Votebits to set\n6. comment (string, optional) Unused\n\nResult:\n\"value\" (string) txid of the resulting transaction\n",
"getticketvotebits": "getticketvotebits \"txhash\"\n\nRetrieve the intended voteBits for any given ticket\n\nArguments:\n1. txhash (string, required) The hash of the ticket\n\nResult:\n{\n \"votebitsdata\": { (object) The voteBits and extended voteBits for this ticket\n \"votebits\": n, (numeric) The voteBits for this ticket\n \"votebitsext\": \"value\", (string) The extended voteBits for this ticket\n }, \n} \n",
"getticketsvotebits": "getticketsvotebits [\"txhash\",...]\n\nRetrieve the intended voteBits for any given list of tickets\n\nArguments:\n1. txhashes (array of string, required) The list of ticket hashes\n\nResult:\n{\n \"votebitslist\": [{ (array of object) The voteBits and extended voteBits for all tickets passed\n \"votebits\": n, (numeric) The voteBits for this ticket\n \"votebitsext\": \"value\", (string) The extended voteBits for this ticket\n },...], \n} \n",
"setticketvotebits": "setticketvotebits \"txhash\" votebits (\"votebitsext\")\n\nSet the voteBits to be used when voting for any given ticket\n\nArguments:\n1. txhash (string, required) The hash of the ticket\n2. votebits (numeric, required) The voteBits to set for the ticket\n3. votebitsext (string, optional) The extended voteBits to set for the ticket\n\nResult:\nNothing\n",
"getstakeinfo": "getstakeinfo\n\nReturns statistics about staking from the wallet.\n\nArguments:\nNone\n\nResult:\n{\n \"poolsize\": n, (numeric) Number of live tickets in the ticket pool.\n \"difficulty\": n.nnn, (numeric) Current stake difficulty.\n \"allmempooltix\": n, (numeric) Number of tickets currently in the mempool\n \"ownmempooltix\": n, (numeric) Number of tickets submitted by this wallet currently in mempool\n \"immature\": n, (numeric) Number of tickets from this wallet that are in the blockchain but which are not yet mature\n \"live\": n, (numeric) Number of mature, active tickets owned by this wallet\n \"proportionlive\": n.nnn, (numeric) (Live / PoolSize)\n \"voted\": n, (numeric) Number of votes cast by this wallet\n \"totalsubsidy\": n.nnn, (numeric) Total amount of coins earned by stake mining\n \"missed\": n, (numeric) Number of missed tickets (failing to vote or expired)\n \"proportionmissed\": n.nnn, (numeric) (Missed / (Missed + Voted))\n \"revoked\": n, (numeric) Number of missed tickets that were missed and then revoked\n} \n",
"getticketfee": "getticketfee\n\nGet the current fee increment used for an authored stake transaction.\n\nArguments:\nNone\n\nResult:\nn.nnn (numeric) The current fee\n",
"setticketfee": "setticketfee fee\n\nModify the increment used each time more fee is required for an authored stake transaction.\n\nArguments:\n1. fee (numeric, required) The new fee increment valued in decred\n\nResult:\ntrue|false (boolean) The boolean 'true'\n",
Expand All @@ -74,4 +77,4 @@ var localeHelpDescs = map[string]func() map[string]string{
"en_US": helpDescsEnUS,
}

var requestUsages = "addmultisigaddress nrequired [\"key\",...] (\"account\")\ncreatemultisig nrequired [\"key\",...]\ndumpprivkey \"address\"\ngetaccount \"address\"\ngetaccountaddress \"account\"\ngetaddressesbyaccount \"account\"\ngetbalance (\"account\" minconf=1 \"balancetype\")\ngetbestblockhash\ngetblockcount\ngetinfo\ngetmasterpubkey\ngetmultisigoutinfo \"hash\" index\ngetseed\ngetnewaddress (\"account\" verbose=false)\ngetrawchangeaddress (\"account\" verbose=false)\ngetreceivedbyaccount \"account\" (minconf=1)\ngetreceivedbyaddress \"address\" (minconf=1)\ngettickets includeimmature\ngetticketmaxprice\ngettransaction \"txid\" (includewatchonly=false)\nhelp (\"command\")\nimportprivkey \"privkey\" (\"label\" rescan=true)\nimportscript \"hex\"\nkeypoolrefill (newsize=100)\nlistaccounts (minconf=1)\nlistlockunspent\nlistreceivedbyaccount (minconf=1 includeempty=false includewatchonly=false)\nlistreceivedbyaddress (minconf=1 includeempty=false includewatchonly=false)\nlistsinceblock (\"blockhash\" targetconfirmations=1 includewatchonly=false)\nlisttransactions (\"account\" count=10 from=0 includewatchonly=false)\nlistunspent (minconf=1 maxconf=9999999 [\"address\",...])\nlockunspent unlock [{\"txid\":\"value\",\"vout\":n,\"tree\":n},...]\nredeemmultisigout \"hash\" index tree (\"address\")\nredeemmultisigouts \"fromscraddress\" (\"toaddress\" number)\nsendfrom \"fromaccount\" \"toaddress\" amount (minconf=1 \"comment\" \"commentto\")\nsendmany \"fromaccount\" {\"address\":amount,...} (minconf=1 \"comment\")\nsendtoaddress \"address\" amount (\"comment\" \"commentto\")\nsendtomultisig \"fromaccount\" amount [\"pubkey\",...] (nrequired=1 minconf=1 \"comment\")\nsetticketmaxprice max\nsettxfee amount\nsignmessage \"address\" \"message\"\nsignrawtransaction \"rawtx\" ([{\"txid\":\"value\",\"vout\":n,\"tree\":n,\"scriptpubkey\":\"value\",\"redeemscript\":\"value\"},...] [\"privkey\",...] flags=\"ALL\")\nsignrawtransactions [\"rawtx\",...] (send=true)\nvalidateaddress \"address\"\nverifymessage \"address\" \"signature\" \"message\"\nwalletlock\nwalletpassphrase \"passphrase\" timeout\nwalletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\ncreatenewaccount \"account\"\nexportwatchingwallet (\"account\" download=false)\ngetbestblock\ngetunconfirmedbalance (\"account\")\nlistaddresstransactions [\"address\",...] (\"account\")\nlistalltransactions (\"account\")\nrenameaccount \"oldaccount\" \"newaccount\"\nwalletislocked\npurchaseticket \"fromaccount\" spendlimit (minconf=1 \"ticketaddress\" \"comment\")\nsendtossrtx \"fromaccount\" \"tickethash\" (\"comment\")\nsendtosstx \"fromaccount\" amounts [{\"txid\":\"value\",\"vout\":n,\"tree\":n,\"amt\":n},...] [{\"addr\":\"value\",\"commitamt\":n,\"changeaddr\":\"value\",\"changeamt\":n},...] (minconf=1 \"comment\")\nsendtossgen \"fromaccount\" \"tickethash\" \"blockhash\" height votebits (\"comment\")\ngetstakeinfo\ngetticketfee\nsetticketfee fee"
var requestUsages = "addmultisigaddress nrequired [\"key\",...] (\"account\")\ncreatemultisig nrequired [\"key\",...]\ndumpprivkey \"address\"\ngetaccount \"address\"\ngetaccountaddress \"account\"\ngetaddressesbyaccount \"account\"\ngetbalance (\"account\" minconf=1 \"balancetype\")\ngetbestblockhash\ngetblockcount\ngetinfo\ngetmasterpubkey\ngetmultisigoutinfo \"hash\" index\ngetseed\ngetnewaddress (\"account\" verbose=false)\ngetrawchangeaddress (\"account\" verbose=false)\ngetreceivedbyaccount \"account\" (minconf=1)\ngetreceivedbyaddress \"address\" (minconf=1)\ngettickets includeimmature\ngetticketmaxprice\ngettransaction \"txid\" (includewatchonly=false)\nhelp (\"command\")\nimportprivkey \"privkey\" (\"label\" rescan=true)\nimportscript \"hex\"\nkeypoolrefill (newsize=100)\nlistaccounts (minconf=1)\nlistlockunspent\nlistreceivedbyaccount (minconf=1 includeempty=false includewatchonly=false)\nlistreceivedbyaddress (minconf=1 includeempty=false includewatchonly=false)\nlistsinceblock (\"blockhash\" targetconfirmations=1 includewatchonly=false)\nlisttransactions (\"account\" count=10 from=0 includewatchonly=false)\nlistunspent (minconf=1 maxconf=9999999 [\"address\",...])\nlockunspent unlock [{\"txid\":\"value\",\"vout\":n,\"tree\":n},...]\nredeemmultisigout \"hash\" index tree (\"address\")\nredeemmultisigouts \"fromscraddress\" (\"toaddress\" number)\nsendfrom \"fromaccount\" \"toaddress\" amount (minconf=1 \"comment\" \"commentto\")\nsendmany \"fromaccount\" {\"address\":amount,...} (minconf=1 \"comment\")\nsendtoaddress \"address\" amount (\"comment\" \"commentto\")\nsendtomultisig \"fromaccount\" amount [\"pubkey\",...] (nrequired=1 minconf=1 \"comment\")\nsetticketmaxprice max\nsettxfee amount\nsignmessage \"address\" \"message\"\nsignrawtransaction \"rawtx\" ([{\"txid\":\"value\",\"vout\":n,\"tree\":n,\"scriptpubkey\":\"value\",\"redeemscript\":\"value\"},...] [\"privkey\",...] flags=\"ALL\")\nsignrawtransactions [\"rawtx\",...] (send=true)\nvalidateaddress \"address\"\nverifymessage \"address\" \"signature\" \"message\"\nwalletlock\nwalletpassphrase \"passphrase\" timeout\nwalletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\ncreatenewaccount \"account\"\nexportwatchingwallet (\"account\" download=false)\ngetbestblock\ngetunconfirmedbalance (\"account\")\nlistaddresstransactions [\"address\",...] (\"account\")\nlistalltransactions (\"account\")\nrenameaccount \"oldaccount\" \"newaccount\"\nwalletislocked\npurchaseticket \"fromaccount\" spendlimit (minconf=1 \"ticketaddress\" \"comment\")\nsendtossrtx \"fromaccount\" \"tickethash\" (\"comment\")\nsendtosstx \"fromaccount\" amounts [{\"txid\":\"value\",\"vout\":n,\"tree\":n,\"amt\":n},...] [{\"addr\":\"value\",\"commitamt\":n,\"changeaddr\":\"value\",\"changeamt\":n},...] (minconf=1 \"comment\")\nsendtossgen \"fromaccount\" \"tickethash\" \"blockhash\" height votebits (\"comment\")\ngetticketvotebits \"txhash\"\ngetticketsvotebits [\"txhash\",...]\nsetticketvotebits \"txhash\" votebits (\"votebitsext\")\ngetstakeinfo\ngetticketfee\nsetticketfee fee"

0 comments on commit 12ff153

Please sign in to comment.