Skip to content

Commit

Permalink
multi: add listtickets json rpc command
Browse files Browse the repository at this point in the history
listtickets cmd return detailed info about ticket details, spender
and state
  • Loading branch information
kLkA committed Oct 2, 2018
1 parent 6f3a8e3 commit f273423
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 1 deletion.
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
34 changes: 34 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,39 @@ 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
n, err := w.NetworkBackend()
connected := err == nil
if connected {
chainClient, err := chain.RPCClientFromBackend(n)
if err == nil {
err := chainClient.Ping()
if err != nil {
log.Warnf("Ping failed on connected daemon client: %v", err)
connected = false
}
}
}
if !connected {
return nil, errRPCClientNotConnected
}

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
2 changes: 2 additions & 0 deletions spv/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/blake256 v1.0.0 h1:6gUgI5MHdz9g0TdrgKqXsoDX+Zjxmm1Sc6OsoGru50I=
github.com/dchest/blake256 v1.0.0/go.mod h1:xXNWCE1jsAP8DAjP+rKw2MbeqLczjI3TRx2VK+9OEYY=
github.com/dchest/siphash v1.2.0/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
github.com/decred/base58 v1.0.0 h1:BVi1FQCThIjZ0ehG+I99NJ51o0xcc9A/fDKhmJxY6+w=
github.com/decred/base58 v1.0.0/go.mod h1:LLY1p5e3g91byL/UO1eiZaYd+uRoVRarybgcoymu9Ks=
github.com/decred/dcrd v1.2.1-0.20180801202239-0761de129164 h1:wYjHNfbzWlLpFuqlVVNtXRmqrEETEDv7KWEf7psUWnc=
Expand Down Expand Up @@ -70,6 +71,7 @@ github.com/decred/dcrd/dcrutil v1.1.1/go.mod h1:Jsttr0pEvzPAw+qay1kS1/PsbZYPyhlu
github.com/decred/dcrd/gcs v1.0.0/go.mod h1:5uHIPAzn4SdGP2/FhVBK2YdAoKmufds3ZI8yNzojUCM=
github.com/decred/dcrd/gcs v1.0.1 h1:MpJXLskT41+JDaD3RLdlSlF2vlu1sxPpZgiRI7FVTWw=
github.com/decred/dcrd/gcs v1.0.1/go.mod h1:YwutGzusSdJM79CJtxCo9t7WRCvnkLtWSD19TPo1i9g=
github.com/decred/dcrd/gcs v1.0.2/go.mod h1:eLCvrzUsWro48TlTyrmFcZAZqnllYFz0vEv5VZtufF4=
github.com/decred/dcrd/hdkeychain v1.0.0 h1:YZPNvvFYME29nnjLl1c4v+Wusrx4BzUCYdRYmUdRnPI=
github.com/decred/dcrd/hdkeychain v1.0.0/go.mod h1:ZLzIMYN4rLNQPdy2I5FYtdYevIKwmUVo1Sz9x909kYc=
github.com/decred/dcrd/hdkeychain v1.1.0 h1:6bFdL672dCmtg/JEzb3Jw0dTRO2jLxcA7BK2J+JaoUM=
Expand Down

0 comments on commit f273423

Please sign in to comment.