-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
lnrpc: Add destination output information (pkScript, output index, amount and if output belongs to the node) #5476
lnrpc: Add destination output information (pkScript, output index, amount and if output belongs to the node) #5476
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, thank you! This additional info should be very useful.
I think we should merge the new info with the address internally and deprecate the address field in the RPC. But other than that looks great to me!
Perhaps we could even optimize the output here. If we can't parse the address, we set the address to nil (and empty string on the RPC) but still include the other details. That way we could get rid of that |
bdb9c3f
to
c6e3059
Compare
I agree and think this makes a lot of sense. My only reservation is in the way that the address is calculated. As it currently is, the returned address for a single output script is a slice of potential multiple addresses. Normally the slice will just contain a single valid address that corresponds to exactly the output script. However, in the extremely rare case of a MultiSig script NOT encoded via a P2SH, the returned slice of addresses will simply contain a list of P2PKH addresses from the multisig script (since the direct multisig script does not have an address representation). I have therefore added some logic to make sure in this case we return an empty address. |
c6e3059
to
45a19bf
Compare
I have squashed the new changes:
|
45a19bf
to
c30efa7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for adding the new enum. Just one comment about the enum values and a few nits, other than that I think this is ready.
506cc07
to
73547d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the super quick updates, LGTM 🎉
@ellemouton: review reminder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left some comments. Also, needs a rebase :)
lnrpc/rpc.proto
Outdated
OutputScriptType output_type = 1; | ||
|
||
// The address | ||
string address = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the first commit, the OutputDetail struct has an array of addresses instead of just 1. I assumed that is for a multisig script or something? in anycase, if we do a slice there, then this should also be be repeated
. otherwise, the struct should be changed to just have 1 addr too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason to use a slice for it was to deprecate DestAddresses
but still expose it on the RPC for backwards compatibility. However, we can also re-introduce the DestAddresses
directly to the interface and have the OutputDetail
only contain the single destination address if available?
lnrpc/rpc_utils.go
Outdated
|
||
var address string | ||
if len(o.Addresses) == 1 { | ||
address = o.Addresses[0].EncodeAddress() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah so following up on my comment from before, what about the other addresses here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DestAddresses
field is a bit weird, because if an output is not re-presentable by an address (e.g. due to NonStandard
type or the MultiSigType
), then the indices in the DestAddresses
do not correspond to the outputs.
The reason that MultiSigType
returns a slice of addresses, is because this is the case where the multisig script is directly put inside the scriptPubKey, hence not behind a hash. Therefore it cannot be represented by an address. It is questionable if a slice of addresses for the pubkeys referred to in the multisig script is helpful though. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok cool, chatted to oli about this and he agrees with you 👍
73547d9
to
7b8b602
Compare
Thanks @ellemouton for your comments! I have rebased this PR. Also I have tried to clarify the weird behaviour of the legacy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK 🚀
i think it needs another rebase @bjarnemagnussen
A new `DestOutputs` field contains additional information on destinations of a transaction described with the `TransactionDetail` structure. The additional information inside `DestOuputs` denote the output script and amount, as well as a flag `IsOurAddress` if the address is controlled by the node's wallet.
Adds the output script and amount to the `DestOutput` field of `TransactionDetails`, as well as sets the flag `isOurAddress` if the output is controlled by the node's wallet.
With `OutputDetail` now containing the destination addresses, the `DestAddresses` field can be removed from the `lnwallet.TransactionDetail`. It is already populated when needed for backwards compatibility to `lnrpc.TransactionDetail` via `OutputDetail.Addresses`.
7b8b602
to
b4ba8c5
Compare
Thanks @ellemouton! I have rebased and added release notes! |
Fixes #2835.
This PR adds destination output information to the
TransactionDetail
structure returned by both RPCGetTransactions
andSubscribeTransactions
.The additional fields include the output script (
PkScript
), amount (Amount
), index (OutputIndex
) and a bool (IsOurAddress
) to denote if the output belongs to the node's internal wallet or not.Since all of this information is already available when constructing the
TransactionDetail
, this information can just be added as it can be useful in many applications and depending on the use case may also solve issue #4826.Note
The output index does not simply correspond to the position in the
DestOutput
array, as unrecognized outputs are skipped:lnd/lnwallet/btcwallet/btcwallet.go
Lines 927 to 935 in 756a0ab