Skip to content

Commit

Permalink
hotfix: mempool.space mainnet urls (#18)
Browse files Browse the repository at this point in the history
* hotfix: mempool.space mainnet urls
* fix mempool polling
  • Loading branch information
dni authored Nov 27, 2023
1 parent 1afd448 commit 0139ac3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions boltz_client/boltz.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class BoltzConfig:
network_liquid: str = "liquidv1"
pairs: list = field(default_factory=lambda: ["BTC/BTC", "L-BTC/BTC"])
api_url: str = "https://boltz.exchange/api"
mempool_url: str = "https://mempool.space/api/v1"
mempool_liquid_url: str = "https://liquid.network/api/v1"
mempool_url: str = "https://mempool.space/api"
mempool_liquid_url: str = "https://liquid.network/api"
referral_id: str = "dni"


Expand Down
11 changes: 11 additions & 0 deletions boltz_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,21 @@ def show_pairs():
click.echo(json.dumps(data))


@click.command()
def get_fees():
"""
show mempool recommended fees
"""
client = BoltzClient(config)
fees = client.mempool.get_fees()
click.echo(fees)


def main():
"""main function"""
command_group.add_command(swap_status)
command_group.add_command(show_pairs)
command_group.add_command(get_fees)
command_group.add_command(create_swap)
command_group.add_command(refund_swap)
command_group.add_command(create_reverse_swap)
Expand Down
17 changes: 11 additions & 6 deletions boltz_client/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def find_output(self, tx, address: str) -> Optional[LockupData]:
txid=tx["txid"],
script_pub_key=vout["scriptpubkey_address"],
vout_cnt=i,
vout_amount=vout["value"],
vout_amount=vout.get("value") or 0,
status=status,
)
return None
Expand Down Expand Up @@ -136,10 +136,13 @@ def get_txs_from_address(self, address: str):

async def get_tx_from_txid(self, txid: str, address: str) -> LockupData:
while True:
tx = self.get_tx(txid)
output = self.find_output(tx, address)
if output:
return output
try:
tx = self.get_tx(txid)
output = self.find_output(tx, address)
if output:
return output
except MempoolApiException:
pass
await asyncio.sleep(3)

async def get_tx_from_address(self, address: str) -> LockupData:
Expand All @@ -152,9 +155,11 @@ async def get_tx_from_address(self, address: str) -> LockupData:
return lockup_tx

def get_fees(self) -> int:
# mempool.space quirk, needed for regtest
api_url = self._api_url.replace("/v1", "")
data = self.request(
"get",
f"{self._api_url}/fees/recommended",
f"{api_url}/v1/fees/recommended",
headers={"Content-Type": "application/json"},
)
return int(data["halfHourFee"])
Expand Down
5 changes: 4 additions & 1 deletion boltz_client/onchain_wally.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ def create_liquid_tx(
lasset_hex = "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"
confidential_addr_prefix = "ert"
confidential_addr_family = "el"
wif_net = wally.WALLY_ADDRESS_VERSION_WIF_TESTNET
elif receive_address.startswith("tex") or receive_address.startswith("tlq"):
lasset_hex = "144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49"
confidential_addr_prefix = "tex"
confidential_addr_family = "tlq"
wif_net = wally.WALLY_ADDRESS_VERSION_WIF_TESTNET
elif receive_address.startswith("ex") or receive_address.startswith("lq"):
lasset_hex = "6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d"
confidential_addr_prefix = "ex"
confidential_addr_family = "lq"
wif_net = wally.WALLY_ADDRESS_VERSION_WIF_MAINNET
else:
raise ValueError(f"Unknown prefix: {receive_address[:3]}")

Expand All @@ -62,7 +65,7 @@ def create_liquid_tx(
preimage = bytes.fromhex(preimage_hex)
private_key = wally.wif_to_bytes(
privkey_wif,
wally.WALLY_ADDRESS_VERSION_WIF_TESTNET,
wif_net,
wally.WALLY_WIF_FLAG_COMPRESSED,
) # type: ignore

Expand Down

0 comments on commit 0139ac3

Please sign in to comment.