From 6adfdf6bdcd1596e985c288768b9bb6ad8d0b281 Mon Sep 17 00:00:00 2001 From: David Hill Date: Fri, 11 May 2018 13:46:39 -0400 Subject: [PATCH] dcrjson: add estimatesmartfee --- dcrjson/chainsvrcmds.go | 32 +++++++++++++++++++++++++++++++- dcrjson/chainsvrcmds_test.go | 11 +++++++++++ dcrjson/chainsvrresults.go | 8 ++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/dcrjson/chainsvrcmds.go b/dcrjson/chainsvrcmds.go index dae03df9eb..510e17462e 100644 --- a/dcrjson/chainsvrcmds.go +++ b/dcrjson/chainsvrcmds.go @@ -107,7 +107,7 @@ 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{ @@ -115,6 +115,35 @@ func NewEstimateFeeCmd(numBlocks int64) *EstimateFeeCmd { } } +// 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 @@ -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) diff --git a/dcrjson/chainsvrcmds_test.go b/dcrjson/chainsvrcmds_test.go index e404c2ce35..10c1734c18 100644 --- a/dcrjson/chainsvrcmds_test.go +++ b/dcrjson/chainsvrcmds_test.go @@ -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) { diff --git a/dcrjson/chainsvrresults.go b/dcrjson/chainsvrresults.go index cff6ae7e1d..cae40212cf 100644 --- a/dcrjson/chainsvrresults.go +++ b/dcrjson/chainsvrresults.go @@ -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 {