Add On-Chain Send/Receive to NWC#1807
Add On-Chain Send/Receive to NWC#1807barrydeen wants to merge 9 commits intonostr-protocol:masterfrom
Conversation
|
A sign psbt and list utxos cmd would make sense as well. Also the balance command might want to include an onchain and unconfirmed balance now as well |
Agreed on all fronts. |
|
would you do sign psbt like this?
|
|
Yeah, could add an optional input index too |
|
ACK |
|
Very cool! But please don't change formatting with new ideas. |
Ah yes. Fixed. |
|
One thing I'm a bit unsure about is if chain amounts should be expressed as msats or sats. For now an msat can never settle on chain, but if you're building an app or wallet service I bet it will be extremely annoying to treat the amounts differently |
|
For signPsbt maybe take a look at Unisats wallet API. I believe it's the best one out there that's being used. We iterated and improved the available options to this |
|
Would it make sense to add an ALREADY_PAID error and recommend wallets to not pay the same amount to the same address twice? This to reduce the risk of making the same payment twice in case the client for whatever reason didn't receive the response and retries a request? Or should this just be kept track of and be handled by any wallet how it seems fit and not really be mentioned in the specs? |
If you specify the input index, wouldn't the wallet service already know the pubkey and address? |
Lightning nodes already reply with an error if you try to pay the same payment request twice, I don't see how NWC would open up a new opportunity for double payments. You can put a failure reason in the message of the response already. |
Lightning nodes with bolt11 invoices indeed do, but when adding onchain payments, they can be made twice to the same address. But I agree that it can be put in a failure reason and just use an internal or other error... |
Still, an error message should be specified so that implementations don't diverge on this point. Also, I think there should be an override option. A user might want to send the same amount to the same address twice. E.g. what if it's a subscription service? Or what if a user decided to send 10k sats to an exchange once per week and sell it as a kind of "allowance"? If that exchange has a static deposit address, as some do, then if the wallet says "you're not supposed to send the same amount to the same address twice," the user should be able to override that and say "do it anyway." |
I don't love this, you can already have idempotentcy from the event id, adding it redundantly like this just inhibits use cases and can be confusing |
Totally agree, and that was where I was going to go, should we add a recommendation to the specs now that 'pay' retries should be done with the same event/event id? Because I can imagine naive client implementations may have their retry logic generate a completely new event... |
Yes, I agree that should all be possible. I think the most straightforward way to handle it and permit those use cases is as @benthecarman mentions, wallet services should keep track of already processed events and not process them twice. My worry is just that both wallet services as clients may not think about this initially, especially since the "risk" of accidentally making the same payment twice didn't exist with lightning invoices only. Since with on-chain payments it does exist, I thought we could at least add a recommendation on what to check in a wallet service and how best to retry (on-chain) payments from the client side to reduce this risk. |
|
Yeah I think putting some text about the potential issue in the nip is fine. But shaping the protocol around that doesn't make sense. |
|
Stoked to see this @barrydeen. We will add this to the Clams Accounting app. A couple of thoughts / questions:
|
|
Sorry for late reply, you raise a lot of good points that make sense. I'll make some changes to the PR soon to reflect. Only thing is I think it makes sense for these output lists to be in the list_chain_transactions method and not mash it with the lightning txns |
|
Oh yes, my bad, |
|
Just highlighting I was on spaces with Cove wallet creator that was looking a way to connect a node to his mobile wallet and mentioned this may work with NWC. He's main request was "getting txn information for addresses" |
That is completely separate and should be separate from nwc |
|
A method to get the current mempool state might be useful to have in this context, so the client can get fee estimates from its own backend and doesn't have to rely on other sources: {
"method": "get_mempool_info",
"params": {}
}Response: {
"result_type": "get_mempool_info",
"result": {
"estimates": { # blocks -> sat/vb
"1": "24",
"2": "20",
"5": "18",
"10": "10",
"25": "5",
"144": "2",
"1008": "1",
}
}
}the backend should be free to specify the available block values, the client shouldn't rely on these specific values. Edit: |
|
Gentleman, major update, look forward to your comments:
|
i just wonder how far we go down this route, in theory why not just expose the entire bitcoin rpc to nwc methods? (maybe we should!) - I don't disagree with your logic that it would make life easier for a client, I'm just not sure. |
|
|
||
| Description: Requests payment to a chain address. | ||
| Description: Requests payment to one or more chain addresses. | ||
|
|
There was a problem hiding this comment.
What should happen if the backend is not able to pay all adresses but only some (e.g. too few funds)?
Might add a line saying something alike: All given addresses have to be paid in a single transaction or the request gets failed.
This should give the client the explicit guarantee that the transaction will happen as requested.
f321x
left a comment
There was a problem hiding this comment.
looks reasonable, RE get_mempool_info, i agree there has to be some limitation on what calls really make sense for this usecase to include.
I think some mempool information would be quite useful for clients that do onchain operations, and the optional nature of NIP-47 features would leave the decision open if the backend actually wants to implement it, otherwise they can just not signal support for it.
|
How is this going? Have any implementations supported it? |
|
LGTM, nice work @barrydeen |
|
There was a bunch of discussion on using bip (3)21 as a standard way to encode flexible payment instructions in a future rev of nwc in #1952. Ultimately we decided to do a live call and I summarized some of our conclusions at #1952 (comment) ISTM that would be a simpler way to also get on-chain where we can design one thing that is forward-looking and flexible rather than trying to add new methods for every new payment method in the future. Of course some use-cases will need specific payment methods and may even need optional future extensions, but specifying it as generic as possible means those extensions can be quite simple and additional payment methods can even be totally transparent to some wallets. |
Introduces new chain methods:
pay_chainmake_chain_addresslist_utxossign_psbtlist_chain_transactionsget_chain_balance