Skip to content

Commit

Permalink
added --send-pubkey/--no-send-pubky
Browse files Browse the repository at this point in the history
  • Loading branch information
valcanobacon committed Apr 15, 2024
1 parent fe308a6 commit ad42c86
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "BoostCLI"
version = "0.6.1"
version = "0.7.0"
authors = [{email = "[email protected]" }]
description = "BoostCLI"
requires-python = ">=3.7"
Expand Down
19 changes: 16 additions & 3 deletions src/cli/commands/boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
)
@click.option("--message", help="The message to include in the Boost")
@click.option("--sender-name", help="The name indicating who sent the Boost")
@click.option(
"--send-pubkey/--no-send-pubkey",
default=None,
help="Include your pubkey to allow recipient to boost back",
)
@click.option(
"--support-app/--no-support-app",
default=True,
Expand All @@ -70,7 +75,7 @@
@click.option(
"-y", "--yes", is_flag=True, help="Bypasses message and confirmation prompts"
)
def boost(ctx, search_term, amount, message, sender_name, support_app, yes):
def boost(ctx, search_term, amount, message, sender_name, send_pubkey, support_app, yes):
"""
BoostCLI will try to find the Podcast by the given SEARCH_TERM which
can one of many different things: Feed URL, Podcast Index Feed ID,
Expand All @@ -87,7 +92,7 @@ def boost(ctx, search_term, amount, message, sender_name, support_app, yes):
console_error: Console = ctx.obj["console_error"]
feed_service: FeedService = ctx.obj["feed_service"]
pi_service: Optional[PodcastIndexService] = ctx.obj.get("podcast_index_service")
lighting_service: LightningService = ctx.obj["lightning_service"]
lightning_service: LightningService = ctx.obj["lightning_service"]

pv = find_podcast_value(console, feed_service, pi_service, search_term)
if pv is None:
Expand Down Expand Up @@ -172,6 +177,13 @@ def boost(ctx, search_term, amount, message, sender_name, support_app, yes):
Text("Sender name", "bold cyan"), default=0, show_default=False
)

pubkey=None
if send_pubkey is None and not yes:
if Confirm.ask("Send pubkey to allow replay?", default=0, show_default=False):
pubkey=lightning_service.get_info().identity_pubkey
elif send_pubkey:
pubkey=lightning_service.get_info().identity_pubkey

if message is None and not yes:
message = click.edit("Write message... 300 characters max")
message = message[:300]
Expand All @@ -182,6 +194,7 @@ def boost(ctx, search_term, amount, message, sender_name, support_app, yes):
message=message,
sender_name=sender_name,
sender_app_name="BoostCLI",
pubkey=pubkey,
)

table = Table(expand=True, box=None)
Expand Down Expand Up @@ -243,7 +256,7 @@ def boost(ctx, search_term, amount, message, sender_name, support_app, yes):
)

with progress:
payments = lighting_service.pay_boost_invoice(boost_invoice)
payments = lightning_service.pay_boost_invoice(boost_invoice)
for i, payment in enumerate(payments):
dest = pv.destinations[i]

Expand Down
5 changes: 5 additions & 0 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ class ValueForValue:
timestamp: Optional[int] = None
custom_key: Optional[int] = None
custom_value: Optional[bytes] = None
pubkey: Optional[str] = None


@dataclass
class BoostInvoice:
amount: int
podcast_value: PodcastValue
pubkey: Optional[str]
fees: List[ValueForValue] = field(init=False, default_factory=lambda: [])
payments: List[ValueForValue] = field(init=False, default_factory=lambda: [])
amount_fees: int = field(init=False, default=0)
Expand All @@ -72,11 +74,13 @@ def create(
message: str,
sender_name: str,
sender_app_name: str,
pubkey: Optional[str],
) -> "BoostInvoice":

invoice = BoostInvoice(
amount=amount,
podcast_value=podcast_value,
pubkey=pubkey,
)

for destination in invoice.podcast_value.destinations:
Expand All @@ -100,6 +104,7 @@ def create(
sender_app_name=sender_app_name,
custom_key=destination.custom_key,
custom_value=destination.custom_value,
pubkey=pubkey,
)
)

Expand Down
1 change: 1 addition & 0 deletions src/services/lightning_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def value_to_record(value: ValueForValue):
"itemID": value.podcast_index_item_id,
"ts": value.timestamp,
"value_msat_total": value.amount_msats_total,
"pubkey": value.pubkey,
}
value = json.dumps({k: v for k, v in value.items() if v is not None})
value = value.encode("utf8")
Expand Down

0 comments on commit ad42c86

Please sign in to comment.