Skip to content

Commit

Permalink
multi: add listtickets json rpc command
Browse files Browse the repository at this point in the history
listtickets return detailed info about ticket details, spender
and status.
  • Loading branch information
kLkA committed Oct 6, 2018
1 parent 6f3a8e3 commit 5fb3f09
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dcrwallet
vendor
*~
.vscode
.idea/
31 changes: 31 additions & 0 deletions internal/rpchelp/helpdescs_en_US.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,36 @@ var helpDescsEnUS = map[string]string{
"listsinceblockresult-transactions": "JSON array of objects containing verbose details of the each transaction",
"listsinceblockresult-lastblock": "Hash of the latest-synced block to be used in later calls to listsinceblock",

// ListTicketCmd help.
"listtickets--synopsis": "List all ticket details with related spender and state info",

// ListTicketsResult help.
"listticketsresult-status": "Status of ticket",
"listticketsresult-ticket": "Ticket tx details",
"listticketsresult-spender": "Spender tx details",

// ListTicketsTransactionSummary
"listticketstransactionsummary-type": "Lists all tickets, including unmined tickets",
"listticketstransactionsummary-hash": "Hash of the transaction",
"listticketstransactionsummary-transaction": "Serialized string of the transaction",
"listticketstransactionsummary-myinputs": "Inputs of tx details",
"listticketstransactionsummary-myoutputs": "Outputs of tx details",
"listticketstransactionsummary-fee": "Total input value minus the total output value for sent transactions",
"listticketstransactionsummary-timestamp": "Timestamp of tx",

// ListTicketsTransactionSummaryInput
"listticketstransactionsummaryinput-index": "Index of input in list of all tx inputs",
"listticketstransactionsummaryinput-previousaccount": "Input account",
"listticketstransactionsummaryinput-previousamount": "Input amount",

// ListTicketsTransactionSummaryOutput
"listticketstransactionsummaryoutput-index": "Index of input in list of all tx outputs",
"listticketstransactionsummaryoutput-account": "Output account",
"listticketstransactionsummaryoutput-internal": "Flag if address was create for internal use",
"listticketstransactionsummaryoutput-amount": "Output amount",
"listticketstransactionsummaryoutput-address": "Address receiving amount",
"listticketstransactionsummaryoutput-outputscript": "Pkscript to receive amount",

// ListTransactionsResult help.
"listtransactionsresult-account": "DEPRECATED -- Unset",
"listtransactionsresult-address": "Payment address for a transaction output",
Expand Down Expand Up @@ -688,6 +718,7 @@ var helpDescsEnUS = map[string]string{
"purchaseticket-nosplittransaction": "Use ticket purchase change outputs instead of a split transaction",
"purchaseticket-comment": "Unused",
"purchaseticket-ticketfee": "The transaction fee rate (DCR/kB) to use (overrides fees set by the wallet config or settxfee RPC)",
"purchaseticket-ticketchange": "Currently unused",

// SetTicketFeeCmd help.
"setticketfee--synopsis": "Modify the fee per kB of the serialized tx size used each time more fee is required for an authored stake transaction.",
Expand Down
1 change: 1 addition & 0 deletions internal/rpchelp/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var Methods = []struct {
{"listreceivedbyaddress", []interface{}{(*[]dcrjson.ListReceivedByAddressResult)(nil)}},
{"listscripts", []interface{}{(*dcrjson.ListScriptsResult)(nil)}},
{"listsinceblock", []interface{}{(*dcrjson.ListSinceBlockResult)(nil)}},
{"listtickets", []interface{}{(*dcrjson.ListTicketsResult)(nil)}},
{"listtransactions", returnsLTRArray},
{"listunspent", []interface{}{(*dcrjson.ListUnspentResult)(nil)}},
{"lockunspent", returnsBool},
Expand Down
25 changes: 25 additions & 0 deletions rpc/legacyrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ var handlers = map[string]handler{
"listreceivedbyaddress": {fn: listReceivedByAddress},
"listsinceblock": {fn: listSinceBlock},
"listscripts": {fn: listScripts},
"listtickets": {fn: listTickets},
"listtransactions": {fn: listTransactions},
"listunspent": {fn: listUnspent},
"lockunspent": {fn: lockUnspent},
Expand Down Expand Up @@ -1701,6 +1702,30 @@ func listAccounts(s *Server, icmd interface{}) (interface{}, error) {
return accountBalances, nil
}

// listTickets handles a listtickets request by returning a list
// of tickets containing ticket, spender details and state
func listTickets(s *Server, icmd interface{}) (interface{}, error) {
w, ok := s.walletLoader.LoadedWallet()
if !ok {
return nil, errUnloadedWallet
}

var chainClient *rpcclient.Client
if n, ok := s.walletLoader.NetworkBackend(); ok {
client, err := chain.RPCClientFromBackend(n)
if err == nil {
chainClient = client
}
}

tickets, err := w.ListTickets(chainClient)
if err != nil {
return nil, err
}

return tickets, nil
}

// listLockUnspent handles a listlockunspent request by returning an slice of
// all locked outpoints.
func listLockUnspent(s *Server, icmd interface{}) (interface{}, error) {
Expand Down
1 change: 1 addition & 0 deletions rpc/legacyrpc/rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func helpDescsEnUS() map[string]string {
"listreceivedbyaddress": "listreceivedbyaddress (minconf=1 includeempty=false includewatchonly=false)\n\nReturns a JSON array of objects listing wallet payment addresses and their total received amounts.\n\nArguments:\n1. minconf (numeric, optional, default=1) Minimum number of block confirmations required before a transaction is considered\n2. includeempty (boolean, optional, default=false) Unused\n3. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n[{\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) The payment address\n \"amount\": n.nnn, (numeric) Total amount received by the payment address valued in decred\n \"confirmations\": n, (numeric) Number of block confirmations of the most recent transaction relevant to the address\n \"txids\": [\"value\",...], (array of string) Transaction hashes of all transactions involving this address\n \"involvesWatchonly\": true|false, (boolean) Unset\n},...]\n",
"listscripts": "listscripts\n\nList all scripts that have been added to wallet\n\nArguments:\nNone\n\nResult:\n{\n \"scripts\": [{ (array of object) A list of the imported scripts\n \"hash160\": \"value\", (string) The script hash\n \"address\": \"value\", (string) The script address\n \"redeemscript\": \"value\", (string) The redeem script\n },...], \n} \n",
"listsinceblock": "listsinceblock (\"blockhash\" targetconfirmations=1 includewatchonly=false)\n\nReturns a JSON array of objects listing details of all wallet transactions after some block.\n\nArguments:\n1. blockhash (string, optional) Hash of the parent block of the first block to consider transactions from, or unset to list all transactions\n2. targetconfirmations (numeric, optional, default=1) Minimum number of block confirmations of the last block in the result object. Must be 1 or greater. Note: The transactions array in the result object is not affected by this parameter\n3. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n{\n \"transactions\": [{ (array of object) JSON array of objects containing verbose details of the each transaction\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in decred\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"txid\": \"value\", (string) The hash of the transaction\n \"txtype\": \"value\", (string) The type of tx (regular tx, stake tx)\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n },...], \n \"lastblock\": \"value\", (string) Hash of the latest-synced block to be used in later calls to listsinceblock\n} \n",
"listtickets": "listtickets\n\nList all ticket details with related spender and state info\n\nArguments:\nNone\n\nResult:\n{\n \"ticket\": { (object) Ticket tx details\n \"hash\": \"value\", (string) Hash of the transaction\n \"transaction\": \"value\", (string) Serialized string of the transaction\n \"myinputs\": [{ (array of object) Inputs of tx details\n \"index\": n, (numeric) Index of input in list of all tx inputs\n \"previousaccount\": n, (numeric) Input account\n \"previousamount\": n.nnn, (numeric) Input amount\n },...], \n \"myoutputs\": [{ (array of object) Outputs of tx details\n \"index\": n, (numeric) Index of input in list of all tx outputs\n \"account\": n, (numeric) Output account\n \"internal\": true|false, (boolean) Flag if address was create for internal use\n \"amount\": n.nnn, (numeric) Output amount\n \"address\": unknown, (value) Address receiving amount\n \"outputscript\": \"value\", (string) Pkscript to receive amount\n },...], \n \"fee\": n.nnn, (numeric) Total input value minus the total output value for sent transactions\n \"timestamp\": n, (numeric) Timestamp of tx\n \"type\": n, (numeric) Lists all tickets, including unmined tickets\n }, \n \"spender\": { (object) Spender tx details\n \"hash\": \"value\", (string) Hash of the transaction\n \"transaction\": \"value\", (string) Serialized string of the transaction\n \"myinputs\": [{ (array of object) Inputs of tx details\n \"index\": n, (numeric) Index of input in list of all tx inputs\n \"previousaccount\": n, (numeric) Input account\n \"previousamount\": n.nnn, (numeric) Input amount\n },...], \n \"myoutputs\": [{ (array of object) Outputs of tx details\n \"index\": n, (numeric) Index of input in list of all tx outputs\n \"account\": n, (numeric) Output account\n \"internal\": true|false, (boolean) Flag if address was create for internal use\n \"amount\": n.nnn, (numeric) Output amount\n \"address\": unknown, (value) Address receiving amount\n \"outputscript\": \"value\", (string) Pkscript to receive amount\n },...], \n \"fee\": n.nnn, (numeric) Total input value minus the total output value for sent transactions\n \"timestamp\": n, (numeric) Timestamp of tx\n \"type\": n, (numeric) Lists all tickets, including unmined tickets\n }, \n \"status\": \"value\", (string) Status of ticket\n} \n",
"listtransactions": "listtransactions (\"account\" count=10 from=0 includewatchonly=false)\n\nReturns a JSON array of objects containing verbose details for wallet transactions.\n\nArguments:\n1. account (string, optional) DEPRECATED -- Unused (must be unset or \"*\")\n2. count (numeric, optional, default=10) Maximum number of transactions to create results from\n3. from (numeric, optional, default=0) Number of transactions to skip before results are created\n4. includewatchonly (boolean, optional, default=false) Unused\n\nResult:\n[{\n \"account\": \"value\", (string) DEPRECATED -- Unset\n \"address\": \"value\", (string) Payment address for a transaction output\n \"amount\": n.nnn, (numeric) The value of the transaction output valued in decred\n \"blockhash\": \"value\", (string) The hash of the block this transaction is mined in, or the empty string if unmined\n \"blockindex\": n, (numeric) Unset\n \"blocktime\": n, (numeric) The Unix time of the block header this transaction is mined in, or 0 if unmined\n \"category\": \"value\", (string) The kind of transaction: \"send\" for sent transactions, \"immature\" for immature coinbase outputs, \"generate\" for mature coinbase outputs, or \"recv\" for all other received outputs. Note: A single output may be included multiple times under different categories\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"fee\": n.nnn, (numeric) The total input value minus the total output value for sent transactions\n \"generated\": true|false, (boolean) Whether the transaction output is a coinbase output\n \"involveswatchonly\": true|false, (boolean) Unset\n \"time\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"timereceived\": n, (numeric) The earliest Unix time this transaction was known to exist\n \"txid\": \"value\", (string) The hash of the transaction\n \"txtype\": \"value\", (string) The type of tx (regular tx, stake tx)\n \"vout\": n, (numeric) The transaction output index\n \"walletconflicts\": [\"value\",...], (array of string) Unset\n \"comment\": \"value\", (string) Unset\n \"otheraccount\": \"value\", (string) Unset\n},...]\n",
"listunspent": "listunspent (minconf=1 maxconf=9999999 [\"address\",...])\n\nReturns a JSON array of objects representing unlocked unspent outputs controlled by wallet keys.\n\nArguments:\n1. minconf (numeric, optional, default=1) Minimum number of block confirmations required before a transaction output is considered\n2. maxconf (numeric, optional, default=9999999) Maximum number of block confirmations required before a transaction output is excluded\n3. addresses (array of string, optional) If set, limits the returned details to unspent outputs received by any of these payment addresses\n\nResult:\n{\n \"txid\": \"value\", (string) The transaction hash of the referenced output\n \"vout\": n, (numeric) The output index of the referenced output\n \"tree\": n, (numeric) The tree the transaction comes from\n \"txtype\": n, (numeric) The type of the transaction\n \"address\": \"value\", (string) The payment address that received the output\n \"account\": \"value\", (string) The account associated with the receiving payment address\n \"scriptPubKey\": \"value\", (string) The output script encoded as a hexadecimal string\n \"redeemScript\": \"value\", (string) Unset\n \"amount\": n.nnn, (numeric) The amount of the output valued in decred\n \"confirmations\": n, (numeric) The number of block confirmations of the transaction\n \"spendable\": true|false, (boolean) Whether the output is entirely controlled by wallet keys/scripts (false for partially controlled multisig outputs or outputs to watch-only addresses)\n} \n",
"lockunspent": "lockunspent unlock [{\"amount\":n.nnn,\"txid\":\"value\",\"vout\":n,\"tree\":n},...]\n\nLocks or unlocks an unspent output.\nLocked outputs are not chosen for transaction inputs of authored transactions and are not included in 'listunspent' results.\nLocked outputs are volatile and are not saved across wallet restarts.\nIf unlock is true and no transaction outputs are specified, all locked outputs are marked unlocked.\n\nArguments:\n1. unlock (boolean, required) True to unlock outputs, false to lock\n2. transactions (array of object, required) Transaction outputs to lock or unlock\n[{\n \"amount\": n.nnn, (numeric) The the previous output amount\n \"txid\": \"value\", (string) The transaction hash of the referenced output\n \"vout\": n, (numeric) The output index of the referenced output\n \"tree\": n, (numeric) The tree to generate transaction for\n},...]\n\nResult:\ntrue|false (boolean) The boolean 'true'\n",
Expand Down
2 changes: 1 addition & 1 deletion spv/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/decred/dcrd/blockchain/stake v1.0.1
github.com/decred/dcrd/chaincfg/chainhash v1.0.1
github.com/decred/dcrd/dcrutil v1.1.1
github.com/decred/dcrd/gcs v1.0.1
github.com/decred/dcrd/gcs v1.0.2
github.com/decred/dcrd/txscript v1.0.1
github.com/decred/dcrd/wire v1.1.0
github.com/decred/dcrwallet/errors v1.0.0
Expand Down
Loading

0 comments on commit 5fb3f09

Please sign in to comment.