Skip to content

Commit

Permalink
Add ticketvwap and txfeeinfo RPC server commands (#145)
Browse files Browse the repository at this point in the history
Two new commands were added to the daemon RPC server. They are:

ticketvwap: Calculate the volume weighted average price of tickets.
txfeeinfo: Get the transaction fee information for regular transactions
  in blocks, the mempool, and a height range

The previous "ticketfeeinfo" command logic was also refactored for
portability.
  • Loading branch information
cjepson authored and alexlyp committed Apr 29, 2016
1 parent 7fd213b commit 29f116c
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 80 deletions.
40 changes: 37 additions & 3 deletions dcrjson/dcrdextcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ func NewRebroadcastWinnersCmd() *RebroadcastWinnersCmd {

// TicketFeeInfoCmd defines the ticketsfeeinfo JSON-RPC command.
type TicketFeeInfoCmd struct {
Blocks uint32
Windows uint32
Blocks *uint32
Windows *uint32
}

// NewTicketFeeInfoCmd returns a new instance which can be used to issue a
// JSON-RPC ticket fee info command.
func NewTicketFeeInfoCmd(blocks uint32, windows uint32) *TicketFeeInfoCmd {
func NewTicketFeeInfoCmd(blocks *uint32, windows *uint32) *TicketFeeInfoCmd {
return &TicketFeeInfoCmd{
Blocks: blocks,
Windows: windows,
Expand All @@ -178,6 +178,38 @@ func NewTicketsForAddressCmd(addr string) *TicketsForAddressCmd {
return &TicketsForAddressCmd{addr}
}

// TicketVWAPCmd defines the ticketvwap JSON-RPC command.
type TicketVWAPCmd struct {
Start *uint32
End *uint32
}

// NewTicketVWAPCmd returns a new instance which can be used to issue a
// JSON-RPC ticket volume weight average price command.
func NewTicketVWAPCmd(start *uint32, end *uint32) *TicketVWAPCmd {
return &TicketVWAPCmd{
Start: start,
End: end,
}
}

// TxFeeInfoCmd defines the ticketsfeeinfo JSON-RPC command.
type TxFeeInfoCmd struct {
Blocks *uint32
RangeStart *uint32
RangeEnd *uint32
}

// NewTxFeeInfoCmd returns a new instance which can be used to issue a
// JSON-RPC ticket fee info command.
func NewTxFeeInfoCmd(blocks *uint32, start *uint32, end *uint32) *TxFeeInfoCmd {
return &TxFeeInfoCmd{
Blocks: blocks,
RangeStart: start,
RangeEnd: end,
}
}

func init() {
// No special flags for commands in this file.
flags := UsageFlag(0)
Expand All @@ -197,4 +229,6 @@ func init() {
MustRegisterCmd("rebroadcastwinners", (*RebroadcastWinnersCmd)(nil), flags)
MustRegisterCmd("ticketfeeinfo", (*TicketFeeInfoCmd)(nil), flags)
MustRegisterCmd("ticketsforaddress", (*TicketsForAddressCmd)(nil), flags)
MustRegisterCmd("ticketvwap", (*TicketVWAPCmd)(nil), flags)
MustRegisterCmd("txfeeinfo", (*TxFeeInfoCmd)(nil), flags)
}
38 changes: 28 additions & 10 deletions dcrjson/dcrdextresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ type Ticket struct {
Owner string `json:"owner"`
}

// TicketFeeInfoMempool is ticket fee information about the mempool.
type TicketFeeInfoMempool struct {
// FeeInfoBlock is ticket fee information about a block.
type FeeInfoBlock struct {
Height uint32 `json:"height"`
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Expand All @@ -49,9 +50,8 @@ type TicketFeeInfoMempool struct {
StdDev float64 `json:"stddev"`
}

// TicketFeeInfoBlock is ticket fee information about a block.
type TicketFeeInfoBlock struct {
Height uint32 `json:"height"`
// FeeInfoMempool is ticket fee information about the mempool.
type FeeInfoMempool struct {
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Expand All @@ -60,8 +60,18 @@ type TicketFeeInfoBlock struct {
StdDev float64 `json:"stddev"`
}

// TicketFeeInfoWindow is ticket fee information about an adjustment window.
type TicketFeeInfoWindow struct {
// FeeInfoRange is ticket fee information about a range.
type FeeInfoRange struct {
Number uint32 `json:"number"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
Median float64 `json:"median"`
StdDev float64 `json:"stddev"`
}

// FeeInfoWindow is ticket fee information about an adjustment window.
type FeeInfoWindow struct {
StartHeight uint32 `json:"startheight"`
EndHeight uint32 `json:"endheight"`
Number uint32 `json:"number"`
Expand All @@ -75,13 +85,21 @@ type TicketFeeInfoWindow struct {
// TicketFeeInfoResult models the data returned from the ticketfeeinfo command.
// command.
type TicketFeeInfoResult struct {
FeeInfoMempool TicketFeeInfoMempool `json:"feeinfomempool"`
FeeInfoBlocks []TicketFeeInfoBlock `json:"feeinfoblocks"`
FeeInfoWindows []TicketFeeInfoWindow `json:"feeinfowindows"`
FeeInfoMempool FeeInfoMempool `json:"feeinfomempool"`
FeeInfoBlocks []FeeInfoBlock `json:"feeinfoblocks"`
FeeInfoWindows []FeeInfoWindow `json:"feeinfowindows"`
}

// TicketsForAddressResult models the data returned from the ticketforaddress
// command.
type TicketsForAddressResult struct {
Tickets []string `json:"tickets"`
}

// TxFeeInfoResult models the data returned from the ticketfeeinfo command.
// command.
type TxFeeInfoResult struct {
FeeInfoMempool FeeInfoMempool `json:"feeinfomempool"`
FeeInfoBlocks []FeeInfoBlock `json:"feeinfoblocks"`
FeeInfoRange FeeInfoRange `json:"feeinforange"`
}
Loading

0 comments on commit 29f116c

Please sign in to comment.