-
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
rpc: add gettx command to walletrpc #7654
rpc: add gettx command to walletrpc #7654
Conversation
94bbc0a
to
020621b
Compare
bed1939
to
eb972b5
Compare
c07edec
to
8e3f1f1
Compare
b6a54fe
to
09b9a51
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.
Thanks for the PR. This will be very useful!
I think this can be simplified quite a bit by just using a filter function. If the reason for the duplicated code is to improve performance by not reading everything from disk an then filtering in memory, I think we should instead implement the filter in btcwallet
itself. Such an (optional/nilable) filter function could also be used for other stuff in the future.
71d585a
to
674e85c
Compare
@guggero Everything you asked for should be implemented now. Unfortunately we do have a dual array struct for "mined" and "unmined" transactions in the btcwallet package, so I did implement the filter in lnd instead. The lnwallet test commit is removed since this now uses a filter instead of fetching specific transactions. |
674e85c
to
b87b683
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 very good, thanks a lot for the update!
Just a bunch of nits, will run a couple of manual tests when addressed.
b87b683
to
a8c5382
Compare
213629b
to
4ae1e14
Compare
2ffd56a
to
b6842d3
Compare
4265a45
to
b21c6e6
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.
Just one nit and needs a rebase, otherwise LGTM🙏
itest/lnd_misc_test.go
Outdated
&walletrpc.GetTransactionRequest{ | ||
TxHash: targetTx, | ||
}) | ||
require.NotNil(ht, txResp, "target tx %v not found", targetTx) |
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.
need to use require.NotNilf
to format the string properly.
b21c6e6
to
21465b5
Compare
@yyforyongyu Added |
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.
LGTM🙏
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.
Very nice and super close, just some last small requests.
lnrpc/walletrpc/walletkit.proto
Outdated
@@ -538,6 +543,11 @@ message ListAddressesResponse { | |||
repeated AccountWithAddresses account_with_addresses = 1; | |||
} | |||
|
|||
message GetTransactionRequest { | |||
// Transaction hash. | |||
string tx_hash = 1; |
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.
Since technically this is the TXID (which is the by-reversed hash of the transaction), this should either be called txid
if it's a string, or be turned into a bytes
field which then expects the non-reversed bytes of the transaction hash.
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.
I'd vote for renaming to txid
and leaving the string
type, since that makes the REST call easier as well, since bytes
are a bit harder to handle.
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.
Done
lnwallet/btcwallet/btcwallet.go
Outdated
|
||
txDetail, err := unminedTransactionsToDetail(tx.Summary, b.netParams) | ||
if err != nil { | ||
return nil, err |
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.
nit: we could either add some additional error context here with fmt.Errorf()
. If not, then I guess we can directly do return unminedTransactionsToDetail(...)
.
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.
I will just return it then.
itest/lnd_misc_test.go
Outdated
txResp := ainz.RPC.GetTransaction( | ||
&walletrpc.GetTransactionRequest{ | ||
TxHash: targetTx, | ||
}) |
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.
nit: closing parenthesis on new line.
lnwallet/test/test_interface.go
Outdated
|
||
txDetails, err := bob.GetTransactionDetails(&txHash) | ||
require.NoError(t, err, "unable to receive transaction details") | ||
require.Equal(t, txDetails.Value, amountSats, "expected transaction "+ |
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.
There are formatting placeholders in the last argument, but Equalf()
wasn't used. IMO this can just be require.Equal(t, txDetails.Value, amountSats, "tx value")
since the required library will produce a nice error message already.
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.
@guggero thanks for the review. Will finish it soon.
cb48f3d
to
f9376f6
Compare
Code has been updated and rebased. @guggero: Ready for another review. |
f9376f6
to
c8a7a3d
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.
Nice, LGTM 🎉
Adds a new endpoint 'gettx' to the wallet sub-server.
Fixes #7323.
The btcwallet package has been updated for this endpoint.
This will only fetch transactions from the wallet db and not from a btc node in accordance with the issue description.(https://github.com/lightningnetwork/lnd/blob/04314d3254a9380d51935125869b23ee37240dfe/lnrpc/lightning.proto#L41-L44).
A test is added to lnwallet.