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

mempool fee histogram #7

Merged
merged 1 commit into from
May 12, 2021
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
.coverage
coverage.xml
htmlcov
build
dist
*.egg-info
*.swp
11 changes: 11 additions & 0 deletions obelisk/mempool_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@ def get_mempool_fee_estimates():
return None

return json.load(res)


def get_fee_histogram():
conn = HTTPSConnection("mempool.space")
conn.request("GET", "/api/mempool")
res = conn.getresponse()

if res.status != 200:
return None

return json.load(res)["fee_histogram"]
14 changes: 11 additions & 3 deletions obelisk/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from obelisk.errors_jsonrpc import JsonRPCError
from obelisk.errors_libbitcoin import ZMQError
from obelisk.mempool_api import get_mempool_fee_estimates
from obelisk.mempool_api import get_mempool_fee_estimates, get_fee_histogram
from obelisk.merkle import merkle_branch, merkle_branch_and_root
from obelisk.util import (
bh2u,
Expand Down Expand Up @@ -698,8 +698,16 @@ async def get_fee_histogram(self, writer, query): # pylint: disable=W0613
Return a histogram of the fee rates paid by transactions in the
memory pool, weighted by transaction size.
"""
# TODO: Help wanted
return {"result": [[0, 0]]}
# NOTE: This solution is using the mempool.space API.
# Let's try to eventually solve it with some internal logic.
if self.chain == "testnet":
return {"result": [[0, 0]]}

fee_hist = get_fee_histogram()
if not fee_dict:
return {"result": [[0, 0]]}

return {"result": fee_hist}

async def add_peer(self, writer, query): # pylint: disable=W0613
"""Method: server.add_peer
Expand Down