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 Jun 8, 2018
1 parent dcd6305 commit 324fb19
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 6 deletions.
13 changes: 10 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
name = "github.com/btcsuite/websocket"

[[constraint]]
branch = "master"
branch = "add_listalltickets_rpc_method"
name = "github.com/decred/dcrd"
source = "github.com/klka/dcrd"

[[constraint]]
branch = "master"
Expand Down
31 changes: 31 additions & 0 deletions internal/rpchelp/helpdescs_en_US.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,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 @@ -685,6 +715,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 @@ -55,6 +55,7 @@ var Methods = []struct {
{"listreceivedbyaccount", []interface{}{(*[]dcrjson.ListReceivedByAccountResult)(nil)}},
{"listreceivedbyaddress", []interface{}{(*[]dcrjson.ListReceivedByAddressResult)(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 @@ -94,6 +94,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 @@ -1677,6 +1678,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 *dcrrpcclient.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, errClientNotConnected
}

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
Loading

0 comments on commit 324fb19

Please sign in to comment.