Skip to content

Commit

Permalink
dcrjson: add estimatesmartfee
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi committed May 11, 2018
1 parent cc6993e commit 6adfdf6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
32 changes: 31 additions & 1 deletion dcrjson/chainsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,43 @@ type EstimateFeeCmd struct {
NumBlocks int64
}

// NewEstimateFeeCmd returns a new instance which can be used to issue a
// NewEstimateFeeCmd returns a new instance which can be used to issue an
// estimatefee JSON-RPC command.
func NewEstimateFeeCmd(numBlocks int64) *EstimateFeeCmd {
return &EstimateFeeCmd{
NumBlocks: numBlocks,
}
}

// EstimateSmartFeeMode defines estimation mode to be used with
// the estimatesmartfee command.
type EstimateSmartFeeMode string

const (
// EstimateSmartFeeEconomical returns an
// economical result.
EstimateSmartFeeEconomical EstimateSmartFeeMode = "economical"

// EstimateSmartFeeConservative potentially returns
// a conservative result.
EstimateSmartFeeConservative = "conservative"
)

// EstimateSmartFeeCmd defines the estimatesmartfee JSON-RPC command.
type EstimateSmartFeeCmd struct {
Confirmations int64
Mode EstimateSmartFeeMode
}

// NewEstimateSmartFeeCmd returns a new instance which can be used to issue an
// estimatesmartfee JSON-RPC command.
func NewEstimateSmartFeeCmd(confirmations int64, mode EstimateSmartFeeMode) *EstimateSmartFeeCmd {
return &EstimateSmartFeeCmd{
Confirmations: confirmations,
Mode: mode,
}
}

// GetAddedNodeInfoCmd defines the getaddednodeinfo JSON-RPC command.
type GetAddedNodeInfoCmd struct {
DNS bool
Expand Down Expand Up @@ -758,6 +787,7 @@ func init() {
MustRegisterCmd("decoderawtransaction", (*DecodeRawTransactionCmd)(nil), flags)
MustRegisterCmd("decodescript", (*DecodeScriptCmd)(nil), flags)
MustRegisterCmd("estimatefee", (*EstimateFeeCmd)(nil), flags)
MustRegisterCmd("estimatesmartfee", (*EstimateSmartFeeCmd)(nil), flags)
MustRegisterCmd("getaddednodeinfo", (*GetAddedNodeInfoCmd)(nil), flags)
MustRegisterCmd("getbestblockhash", (*GetBestBlockHashCmd)(nil), flags)
MustRegisterCmd("getblock", (*GetBlockCmd)(nil), flags)
Expand Down
11 changes: 11 additions & 0 deletions dcrjson/chainsvrcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ func TestChainSvrCmds(t *testing.T) {
marshalled: `{"jsonrpc":"1.0","method":"decodescript","params":["00"],"id":1}`,
unmarshalled: &dcrjson.DecodeScriptCmd{HexScript: "00"},
},
{
name: "estimatesmartfee",
newCmd: func() (interface{}, error) {
return dcrjson.NewCmd("estimatesmartfee", 6, dcrjson.EstimateSmartFeeConservative)
},
staticCmd: func() interface{} {
return dcrjson.NewEstimateSmartFeeCmd(6, dcrjson.EstimateSmartFeeConservative)
},
marshalled: `{"jsonrpc":"1.0","method":"estimatesmartfee","params":[6,"conservative"],"id":1}`,
unmarshalled: &dcrjson.EstimateSmartFeeCmd{Confirmations: 6, Mode: dcrjson.EstimateSmartFeeConservative},
},
{
name: "getaddednodeinfo",
newCmd: func() (interface{}, error) {
Expand Down
8 changes: 8 additions & 0 deletions dcrjson/chainsvrresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ type DecodeScriptResult struct {
P2sh string `json:"p2sh,omitempty"`
}

// EstimateSmartFeeResult models the data returned from the estimatesmartfee
// command.
type EstimateSmartFeeResult struct {
FeeRate float64 `json:"feerate"`
Errors []string `json:"errors"`
Blocks int64 `json:"blocks"`
}

// GetAddedNodeInfoResultAddr models the data of the addresses portion of the
// getaddednodeinfo command.
type GetAddedNodeInfoResultAddr struct {
Expand Down

0 comments on commit 6adfdf6

Please sign in to comment.