Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcrjson: add estimatesmartfee #1201

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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