implemented estimatesmartfee method
This commit is contained in:
parent
85beeb938c
commit
a929f27d5c
@ -81,6 +81,23 @@ type resGetBlockThin struct {
|
||||
Result bchain.ThinBlock `json:"result"`
|
||||
}
|
||||
|
||||
// estimatesmartfee
|
||||
|
||||
type cmdEstimateSmartFee struct {
|
||||
Method string `json:"method"`
|
||||
Params struct {
|
||||
Blocks int `json:"nblocks"`
|
||||
} `json:"params"`
|
||||
}
|
||||
|
||||
type resEstimateSmartFee struct {
|
||||
Error *bchain.RPCError `json:"error"`
|
||||
Result struct {
|
||||
Feerate float64 `json:"feerate"`
|
||||
Blocks int `json:"blocks"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// GetBlock returns block with given hash.
|
||||
func (b *BCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
|
||||
var err error
|
||||
@ -174,6 +191,25 @@ func (b *BCashRPC) GetBlockFull(hash string) (*bchain.Block, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
}
|
||||
|
||||
// EstimateSmartFee returns fee estimation.
|
||||
func (b *BCashRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) {
|
||||
glog.V(1).Info("rpc: estimatesmartfee ", blocks)
|
||||
|
||||
res := resEstimateSmartFee{}
|
||||
req := cmdEstimateSmartFee{Method: "estimatesmartfee"}
|
||||
req.Params.Blocks = blocks
|
||||
// conservative param is omitted
|
||||
err := b.Call(&req, &res)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if res.Error != nil {
|
||||
return 0, res.Error
|
||||
}
|
||||
return res.Result.Feerate, nil
|
||||
}
|
||||
|
||||
func isErrBlockNotFound(err *bchain.RPCError) bool {
|
||||
return err.Message == "Block not found" ||
|
||||
err.Message == "Block height out of range"
|
||||
|
||||
@ -141,6 +141,21 @@
|
||||
return socket.send({ method, params }, f);
|
||||
}
|
||||
|
||||
function estimateFee() {
|
||||
var blocks = document.getElementById('estimateFeeBlocks').value.trim();
|
||||
estimateTxFee(parseInt(blocks), function (result) {
|
||||
console.log('estimateFee sent successfully');
|
||||
console.log(result);
|
||||
document.getElementById('estimateFeeResult').innerText = JSON.stringify(result).replace(/,/g, ", ");
|
||||
});
|
||||
}
|
||||
|
||||
function estimateTxFee(blocks, f) {
|
||||
const method = 'estimateFee';
|
||||
const params = [blocks];
|
||||
return socket.send({ method, params }, f);
|
||||
}
|
||||
|
||||
function getInfo() {
|
||||
lookupSyncStatus(function (result) {
|
||||
console.log('getInfo sent successfully');
|
||||
@ -324,6 +339,19 @@
|
||||
<div class="col" id="estimateSmartFeeResult">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input class="btn btn-secondary" type="button" value="estimateFee" onclick="estimateFee()">
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<input type="text" class="form-control" id="estimateFeeBlocks" value="20">
|
||||
</div>
|
||||
<div class="col"></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" id="estimateFeeResult">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input class="btn btn-secondary" type="button" value="getInfo" onclick="getInfo()">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user