diff --git a/bchain/coins/bch/bcashrpc.go b/bchain/coins/bch/bcashrpc.go index 222a7b78..cb23030e 100644 --- a/bchain/coins/bch/bcashrpc.go +++ b/bchain/coins/bch/bcashrpc.go @@ -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" diff --git a/static/test.html b/static/test.html index 99097265..45c27e86 100644 --- a/static/test.html +++ b/static/test.html @@ -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 @@
+
+
+ +
+
+ +
+
+
+
+
+
+