Skip to content

Commit

Permalink
Add EstimateFee func to wallet.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKrawisz committed Sep 8, 2016
1 parent c39e353 commit d20626f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,43 @@ func (c *Client) GetInfo() (*btcjson.InfoWalletResult, error) {
return c.GetInfoAsync().Receive()
}

// FutureEstimateFeeResult is a future promise to deliver the result of a
// EstimateFeeAsync RPC invocation (or an applicable error).
type FutureEstimateFeeResult chan *response

// Receive waits for the response promised by the future and returns the info
// provided by the server.
func (r FutureEstimateFeeResult) Receive() (float64, error) {
res, err := receiveFuture(r)
if err != nil {
return -1, err
}

// Unmarshal result as a getinfo result object.
var fee float64
err = json.Unmarshal(res, &fee)
if err != nil {
return -1, err
}

return fee, nil
}

// EstimateFeeAsync returns an instance of a type that can be used to get the result
// of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See EstimateFee for the blocking version and more details.
func (c *Client) EstimateFeeAsync(numBlocks int64) FutureEstimateFeeResult {
cmd := btcjson.NewEstimateFeeCmd(numBlocks)
return c.sendCmd(cmd)
}

// EstimateFee provides an estimated fee in bitcoins per kilobyte.
func (c *Client) EstimateFee(numBlocks int64) (float64, error) {
return c.EstimateFeeAsync(numBlocks).Receive()
}

// TODO(davec): Implement
// backupwallet (NYI in btcwallet)
// encryptwallet (Won't be supported by btcwallet since it's always encrypted)
Expand Down

0 comments on commit d20626f

Please sign in to comment.