feat: add simple pay and receive commands#40
Conversation
|
Warning Review limit reached
More reviews will be available in 29 minutes and 41 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR introduces a unified ChangesUnified Payment Commands
Sequence DiagramsequenceDiagram
participant User as CLI User
participant Pay as pay command
participant Detect as detectDestinationType
participant Validate as rejectUnusedOpts
participant Router as destination router
participant PayInvoice as payInvoice
participant RequestInvoice as requestInvoiceFromLightningAddress
participant PayKeysend as payKeysend
participant PayCrypto as payCrypto
User->>Pay: pay <destination> [--amount] [--currency] [--network] ...
Pay->>Detect: analyze destination string
Detect-->>Pay: type: invoice|lightning-address|keysend|crypto
Pay->>Validate: check that provided flags match type
alt options valid
Validate-->>Pay: options approved
Pay->>Router: route by destination type
alt type is BOLT-11 invoice
Router->>PayInvoice: payInvoice(invoice, amount?)
PayInvoice-->>Pay: success, preimage
else type is lightning-address
Router->>RequestInvoice: requestInvoiceFromLightningAddress(address, amount, metadata)
RequestInvoice-->>Router: fetched invoice
Router->>PayInvoice: payInvoice(invoice, metadata)
PayInvoice-->>Pay: success, preimage
else type is keysend pubkey
Router->>PayKeysend: payKeysend(pubkey, amount, tlv_records?)
PayKeysend-->>Pay: success
else type is EVM address
Router->>PayCrypto: payCrypto(address, amount, currency, network, callback)
PayCrypto-->>Pay: swap_id, status, target
end
else options invalid
Validate-->>Pay: error: rejected option
Pay-->>User: exit with error
end
Pay-->>User: output result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/commands/pay.ts (1)
22-28: ⚡ Quick winInvoice detection is intentionally limited to
lnbc...
payonly auto-detects BOLT-11 invoices when the destination starts withlnbc(/^lnbc/i), and the help text/tests/docs also explicitly state “BOLT-11 invoice (starts with lnbc)”, so non-lnbcprefixes (e.g.,lntb.../lntbs...) will be treated as “Could not detect destination type”. If supporting those networks is a desired enhancement, broaden the prefix match (e.g., includelntb/lntbs) as an optional follow-up.🔧 Optional broadening
- if (/^lnbc/i.test(destination)) return "invoice"; + if (/^ln(bc|tb|tbs|bcrt)/i.test(destination)) return "invoice";🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/pay.ts` around lines 22 - 28, The invoice detection in detectDestinationType currently only matches /^lnbc/i and so misses other BOLT‑11 prefixes like lntb/lntbs; to support those, broaden the invoice regex used in detectDestinationType (the branch that currently tests /^lnbc/i) to also match lntb and lntbs (e.g., a single combined pattern matching ln(bc|tb|tbs) case-insensitively) and update related help/tests/docs that state “starts with lnbc” to reflect the additional accepted prefixes if you want this behavior enabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Around line 127-128: The README EVM pay example and description are incorrect:
for EVM destinations the CLI requires both --currency and --network (see
src/commands/pay.ts), so update the sentence and the example to mark --currency
and --network as required and show a full command using them (e.g., npx
`@getalby/cli` pay 0xabc... --amount 10 --currency USDC --network arbitrum);
ensure the wording explicitly states these flags are mandatory for EVM addresses
and aligns with the validation in the pay command implementation.
In `@src/commands/pay.ts`:
- Around line 133-150: The "invoice" case in the switch allows non-positive
integers because it only validates Number.isInteger(options.amount); update the
validation in the "invoice" branch (inside the case "invoice" block that calls
getClient(...) and payInvoice(...)) to also require options.amount > 0 (mirror
the positivity guard used in the "lightning-address" and "keysend" branches),
and throw the same Invalid --amount error when the amount is missing or <= 0
before calling payInvoice.
---
Nitpick comments:
In `@src/commands/pay.ts`:
- Around line 22-28: The invoice detection in detectDestinationType currently
only matches /^lnbc/i and so misses other BOLT‑11 prefixes like lntb/lntbs; to
support those, broaden the invoice regex used in detectDestinationType (the
branch that currently tests /^lnbc/i) to also match lntb and lntbs (e.g., a
single combined pattern matching ln(bc|tb|tbs) case-insensitively) and update
related help/tests/docs that state “starts with lnbc” to reflect the additional
accepted prefixes if you want this behavior enabled.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c8caa03c-0839-4079-a78e-0c2cd7749c44
📒 Files selected for processing (9)
AGENTS.mdREADME.mdsrc/commands/pay-crypto.tssrc/commands/pay.tssrc/commands/receive.tssrc/index.tssrc/test/pay-command.test.tssrc/test/pay-crypto.test.tssrc/test/receive-command.test.ts
Closes #30
Makes it easier for AI - less likely to make mistakes and not have to handle invoices when paying to lightning addresses.
Also added a receive command - an easy way for the agent to know how it can receive money via lightning address or invoice.
Summary by CodeRabbit
New Features
paycommand with auto-detection for BOLT-11 invoices, lightning addresses, keysend pubkeys, and EVM addresses.receivecommand to generate BOLT-11 invoices or retrieve lightning address.Breaking Changes
pay-cryptocommand now requires explicit--currencyand--networkflags; defaults removed.Documentation
Tests
payandreceivecommands.pay-cryptovalidation tests.