Skip to content

Commit 6bc4df0

Browse files
authored
Merge pull request #142 from bhandras/verbose-sweeps
walletkit: add ListSweepsVerbose method to fetch verbose tx details
2 parents c73da86 + 9e74e60 commit 6bc4df0

File tree

5 files changed

+186
-23
lines changed

5 files changed

+186
-23
lines changed

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module github.com/lightninglabs/lndclient
22

33
require (
4-
github.com/btcsuite/btcd v0.23.3
5-
github.com/btcsuite/btcd/btcec/v2 v2.2.1
6-
github.com/btcsuite/btcd/btcutil v1.1.2
4+
github.com/btcsuite/btcd v0.23.4
5+
github.com/btcsuite/btcd/btcec/v2 v2.2.2
6+
github.com/btcsuite/btcd/btcutil v1.1.3
77
github.com/btcsuite/btcd/btcutil/psbt v1.1.5
88
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
99
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
1010
github.com/btcsuite/btcwallet/wtxmgr v1.5.0
11-
github.com/lightningnetwork/lnd v0.15.4-beta
11+
github.com/lightningnetwork/lnd v0.15.5-beta
1212
github.com/lightningnetwork/lnd/kvdb v1.3.1
13-
github.com/stretchr/testify v1.7.1
13+
github.com/stretchr/testify v1.8.0
1414
go.etcd.io/bbolt v1.3.6
1515
google.golang.org/grpc v1.38.0
1616
gopkg.in/macaroon-bakery.v2 v2.0.1
@@ -22,7 +22,7 @@ require (
2222
github.com/aead/siphash v1.0.1 // indirect
2323
github.com/andybalholm/brotli v1.0.3 // indirect
2424
github.com/beorn7/perks v1.0.1 // indirect
25-
github.com/btcsuite/btcwallet v0.16.1 // indirect
25+
github.com/btcsuite/btcwallet v0.16.5 // indirect
2626
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2 // indirect
2727
github.com/btcsuite/btcwallet/wallet/txrules v1.2.0 // indirect
2828
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.3 // indirect
@@ -104,7 +104,7 @@ require (
104104
github.com/sirupsen/logrus v1.7.0 // indirect
105105
github.com/soheilhy/cmux v0.1.5 // indirect
106106
github.com/spf13/pflag v1.0.5 // indirect
107-
github.com/stretchr/objx v0.2.0 // indirect
107+
github.com/stretchr/objx v0.4.0 // indirect
108108
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
109109
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect
110110
github.com/ulikunitz/xz v0.5.10 // indirect
@@ -141,7 +141,7 @@ require (
141141
gopkg.in/errgo.v1 v1.0.1 // indirect
142142
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
143143
gopkg.in/yaml.v2 v2.4.0 // indirect
144-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
144+
gopkg.in/yaml.v3 v3.0.1 // indirect
145145
sigs.k8s.io/yaml v1.2.0 // indirect
146146
)
147147

go.sum

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ github.com/btcsuite/btcd v0.22.0-beta.0.20220207191057-4dc4ff7963b4/go.mod h1:7a
7676
github.com/btcsuite/btcd v0.22.0-beta.0.20220316175102-8d5c75c28923/go.mod h1:taIcYprAW2g6Z9S0gGUxyR+zDwimyDMK5ePOX+iJ2ds=
7777
github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
7878
github.com/btcsuite/btcd v0.23.1/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
79-
github.com/btcsuite/btcd v0.23.3 h1:4KH/JKy9WiCd+iUS9Mu0Zp7Dnj17TGdKrg9xc/FGj24=
80-
github.com/btcsuite/btcd v0.23.3/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
79+
github.com/btcsuite/btcd v0.23.4 h1:IzV6qqkfwbItOS/sg/aDfPDsjPP8twrCOE2R93hxMlQ=
80+
github.com/btcsuite/btcd v0.23.4/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
8181
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
8282
github.com/btcsuite/btcd/btcec/v2 v2.1.1/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
8383
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
84-
github.com/btcsuite/btcd/btcec/v2 v2.2.1 h1:xP60mv8fvp+0khmrN0zTdPC3cNm24rfeE6lh2R/Yv3E=
85-
github.com/btcsuite/btcd/btcec/v2 v2.2.1/go.mod h1:9/CSmJxmuvqzX9Wh2fXMWToLOHhPd11lSPuIupwTkI8=
84+
github.com/btcsuite/btcd/btcec/v2 v2.2.2 h1:5uxe5YjoCq+JeOpg0gZSNHuFgeogrocBYxvg6w9sAgc=
85+
github.com/btcsuite/btcd/btcec/v2 v2.2.2/go.mod h1:9/CSmJxmuvqzX9Wh2fXMWToLOHhPd11lSPuIupwTkI8=
8686
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
8787
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
8888
github.com/btcsuite/btcd/btcutil v1.1.1/go.mod h1:nbKlBMNm9FGsdvKvu0essceubPiAcI57pYBNnsLAa34=
89-
github.com/btcsuite/btcd/btcutil v1.1.2 h1:XLMbX8JQEiwMcYft2EGi8zPUkoa0abKIU6/BJSRsjzQ=
90-
github.com/btcsuite/btcd/btcutil v1.1.2/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0=
89+
github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ=
90+
github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0=
9191
github.com/btcsuite/btcd/btcutil/psbt v1.1.4/go.mod h1:9AyU6EQVJ9Iw9zPyNT1lcdHd6cnEZdno5wLu5FY74os=
9292
github.com/btcsuite/btcd/btcutil/psbt v1.1.5 h1:x0ZRrYY8j75ThV6xBz86CkYAG82F5bzay4H5D1c8b/U=
9393
github.com/btcsuite/btcd/btcutil/psbt v1.1.5/go.mod h1:kA6FLH/JfUx++j9pYU0pyu+Z8XGBQuuTmuKYUf6q7/U=
@@ -97,8 +97,8 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtyd
9797
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
9898
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
9999
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
100-
github.com/btcsuite/btcwallet v0.16.1 h1:nD8qXJeAU8c7a0Jlx5jwI2ufbf/9ouy29XGapRLTmos=
101-
github.com/btcsuite/btcwallet v0.16.1/go.mod h1:NCO8+5rIcbUm5CtVNSQM0xrtK4iYprlyuvpGzhkejaM=
100+
github.com/btcsuite/btcwallet v0.16.5 h1:4DTJ5aYAJomcR0jAb6JP8D0wNSxfz4H7WN/RBtNZY4o=
101+
github.com/btcsuite/btcwallet v0.16.5/go.mod h1:mM19pFB3lGVxOL+kvHhHZAhdSWXKsZGiHvpJVvxL0D8=
102102
github.com/btcsuite/btcwallet/wallet/txauthor v1.2.3/go.mod h1:T2xSiKGpUkSLCh68aF+FMXmKK9mFqNdHl9VaqOr+JjU=
103103
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2 h1:etuLgGEojecsDOYTII8rYiGHjGyV5xTqsXi+ZQ715UU=
104104
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2/go.mod h1:Zpk/LOb2sKqwP2lmHjaZT9AdaKsHPSbNLm2Uql5IQ/0=
@@ -503,8 +503,8 @@ github.com/lightninglabs/neutrino v0.14.2/go.mod h1:OICUeTCn+4Tu27YRJIpWvvqySxx4
503503
github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display/go.mod h1:2oKOBU042GKFHrdbgGiKax4xVrFiZu51lhacUZQ9MnE=
504504
github.com/lightningnetwork/lightning-onion v1.0.2-0.20220211021909-bb84a1ccb0c5 h1:TkKwqFcQTGYoI+VEqyxA8rxpCin8qDaYX0AfVRinT3k=
505505
github.com/lightningnetwork/lightning-onion v1.0.2-0.20220211021909-bb84a1ccb0c5/go.mod h1:7dDx73ApjEZA0kcknI799m2O5kkpfg4/gr7N092ojNo=
506-
github.com/lightningnetwork/lnd v0.15.4-beta h1:vO+UZjuA8RqJdDlfwQeS0h2PCocYwwqv5HkX2IXf5/M=
507-
github.com/lightningnetwork/lnd v0.15.4-beta/go.mod h1:6aoOkifcI9tuk8UV5l2rVZSq0681obuP4zvfK+2ZrT0=
506+
github.com/lightningnetwork/lnd v0.15.5-beta h1:jdGVLJIYSe60NAn7qzBY3gET2I/FmLW4TTGvrECmgOE=
507+
github.com/lightningnetwork/lnd v0.15.5-beta/go.mod h1:/UKsaOll/pYJltXIC0VKRGHR0Jqhl9bBX/fUiINSwF4=
508508
github.com/lightningnetwork/lnd/cert v1.1.1/go.mod h1:1P46svkkd73oSoeI4zjkVKgZNwGq8bkGuPR8z+5vQUs=
509509
github.com/lightningnetwork/lnd/clock v1.0.1/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg=
510510
github.com/lightningnetwork/lnd/clock v1.1.0 h1:/yfVAwtPmdx45aQBoXQImeY7sOIEr7IXlImRMBOZ7GQ=
@@ -666,16 +666,18 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
666666
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
667667
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
668668
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
669-
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
670669
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
670+
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
671+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
671672
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
672673
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
673674
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
674675
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
675676
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
676677
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
677-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
678678
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
679+
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
680+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
679681
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
680682
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
681683
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
@@ -1167,8 +1169,9 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
11671169
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
11681170
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
11691171
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1170-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
11711172
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1173+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
1174+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11721175
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
11731176
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
11741177
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

lnd_services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func NewLndServices(cfg *LndServicesConfig) (*GrpcLndServices, error) {
344344
conn, macaroons[SignerServiceMac], timeout,
345345
)
346346
walletKitClient := newWalletKitClient(
347-
conn, macaroons[WalletKitServiceMac], timeout,
347+
conn, macaroons[WalletKitServiceMac], timeout, chainParams,
348348
)
349349
invoicesClient := newInvoicesClient(
350350
conn, macaroons[InvoiceServiceMac], timeout,

macaroon_recipes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
"EstimateFeeRate": "EstimateFee",
4242
"EstimateFeeToP2WSH": "EstimateFee",
4343
"OpenChannelStream": "OpenChannel",
44+
"ListSweepsVerbose": "ListSweeps",
4445
}
4546
)
4647

walletkit_client.go

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"github.com/btcsuite/btcd/btcec/v2"
1111
"github.com/btcsuite/btcd/btcutil"
1212
"github.com/btcsuite/btcd/btcutil/psbt"
13+
"github.com/btcsuite/btcd/chaincfg"
1314
"github.com/btcsuite/btcd/chaincfg/chainhash"
15+
"github.com/btcsuite/btcd/txscript"
1416
"github.com/btcsuite/btcd/wire"
1517
"github.com/btcsuite/btcwallet/wtxmgr"
1618
"github.com/lightningnetwork/lnd/keychain"
@@ -69,6 +71,11 @@ type WalletKitClient interface {
6971
// query our wallet for the full set of transactions.
7072
ListSweeps(ctx context.Context) ([]string, error)
7173

74+
// ListSweepsVerbose returns a list of sweep transactions known to our
75+
// node with verbose information about each sweep.
76+
ListSweepsVerbose(ctx context.Context) ([]lnwallet.TransactionDetail,
77+
error)
78+
7279
// BumpFee attempts to bump the fee of a transaction by spending one of
7380
// its outputs at the given fee rate. This essentially results in a
7481
// child-pays-for-parent (CPFP) scenario. If the given output has been
@@ -140,19 +147,22 @@ type walletKitClient struct {
140147
client walletrpc.WalletKitClient
141148
walletKitMac serializedMacaroon
142149
timeout time.Duration
150+
chainParams *chaincfg.Params
143151
}
144152

145153
// A compile-time constraint to ensure walletKitclient satisfies the
146154
// WalletKitClient interface.
147155
var _ WalletKitClient = (*walletKitClient)(nil)
148156

149157
func newWalletKitClient(conn grpc.ClientConnInterface,
150-
walletKitMac serializedMacaroon, timeout time.Duration) *walletKitClient {
158+
walletKitMac serializedMacaroon, timeout time.Duration,
159+
chainParams *chaincfg.Params) *walletKitClient {
151160

152161
return &walletKitClient{
153162
client: walletrpc.NewWalletKitClient(conn),
154163
walletKitMac: walletKitMac,
155164
timeout: timeout,
165+
chainParams: chainParams,
156166
}
157167
}
158168

@@ -424,6 +434,155 @@ func (m *walletKitClient) ListSweeps(ctx context.Context) ([]string, error) {
424434
return sweeps.TransactionIds, nil
425435
}
426436

437+
// unmarshallOutputType translates a lnrpc.OutputScriptType into a
438+
// txscript.ScriptClass.
439+
func unmarshallOutputType(o lnrpc.OutputScriptType) txscript.ScriptClass {
440+
switch o {
441+
case lnrpc.OutputScriptType_SCRIPT_TYPE_SCRIPT_HASH:
442+
return txscript.ScriptHashTy
443+
444+
case lnrpc.OutputScriptType_SCRIPT_TYPE_WITNESS_V0_PUBKEY_HASH:
445+
return txscript.WitnessV0PubKeyHashTy
446+
447+
case lnrpc.OutputScriptType_SCRIPT_TYPE_WITNESS_V0_SCRIPT_HASH:
448+
return txscript.WitnessV0ScriptHashTy
449+
450+
case lnrpc.OutputScriptType_SCRIPT_TYPE_PUBKEY:
451+
return txscript.PubKeyTy
452+
453+
case lnrpc.OutputScriptType_SCRIPT_TYPE_MULTISIG:
454+
return txscript.MultiSigTy
455+
456+
case lnrpc.OutputScriptType_SCRIPT_TYPE_NULLDATA:
457+
return txscript.NullDataTy
458+
459+
case lnrpc.OutputScriptType_SCRIPT_TYPE_NON_STANDARD:
460+
return txscript.NonStandardTy
461+
462+
case lnrpc.OutputScriptType_SCRIPT_TYPE_WITNESS_UNKNOWN:
463+
return txscript.WitnessUnknownTy
464+
465+
case lnrpc.OutputScriptType_SCRIPT_TYPE_WITNESS_V1_TAPROOT:
466+
return txscript.WitnessV1TaprootTy
467+
468+
default:
469+
return txscript.NonStandardTy
470+
}
471+
}
472+
473+
// RPCTransaction returns a rpc transaction.
474+
func UnmarshalTransactionDetail(tx *lnrpc.Transaction,
475+
chainParams *chaincfg.Params) (*lnwallet.TransactionDetail, error) {
476+
477+
var outputDetails []lnwallet.OutputDetail
478+
for _, o := range tx.OutputDetails {
479+
address, err := btcutil.DecodeAddress(o.Address, chainParams)
480+
if err != nil {
481+
return nil, err
482+
}
483+
484+
pkScript, err := hex.DecodeString(o.PkScript)
485+
if err != nil {
486+
return nil, err
487+
}
488+
489+
outputDetails = append(outputDetails, lnwallet.OutputDetail{
490+
OutputType: unmarshallOutputType(o.OutputType),
491+
Addresses: []btcutil.Address{address},
492+
PkScript: pkScript,
493+
OutputIndex: int(o.OutputIndex),
494+
Value: btcutil.Amount(o.Amount),
495+
IsOurAddress: o.IsOurAddress,
496+
})
497+
}
498+
499+
previousOutpoints := make(
500+
[]lnwallet.PreviousOutPoint, len(tx.PreviousOutpoints),
501+
)
502+
for idx, previousOutPoint := range tx.PreviousOutpoints {
503+
previousOutpoints[idx] = lnwallet.PreviousOutPoint{
504+
OutPoint: previousOutPoint.Outpoint,
505+
IsOurOutput: previousOutPoint.IsOurOutput,
506+
}
507+
}
508+
509+
// We also get unconfirmed transactions, so BlockHash can be empty.
510+
var (
511+
blockHash *chainhash.Hash
512+
err error
513+
)
514+
515+
if tx.BlockHash != "" {
516+
blockHash, err = chainhash.NewHashFromStr(tx.BlockHash)
517+
if err != nil {
518+
return nil, err
519+
}
520+
}
521+
522+
txHash, err := chainhash.NewHashFromStr(tx.TxHash)
523+
if err != nil {
524+
return nil, err
525+
}
526+
527+
rawTx, err := hex.DecodeString(tx.RawTxHex)
528+
if err != nil {
529+
return nil, err
530+
}
531+
532+
return &lnwallet.TransactionDetail{
533+
Hash: *txHash,
534+
Value: btcutil.Amount(tx.Amount),
535+
NumConfirmations: tx.NumConfirmations,
536+
BlockHash: blockHash,
537+
BlockHeight: tx.BlockHeight,
538+
Timestamp: tx.TimeStamp,
539+
TotalFees: tx.TotalFees,
540+
OutputDetails: outputDetails,
541+
RawTx: rawTx,
542+
Label: tx.Label,
543+
PreviousOutpoints: previousOutpoints,
544+
}, nil
545+
}
546+
547+
// ListSweepsVerbose returns a list of sweep transactions known to our node
548+
// with verbose information about each sweep.
549+
func (m *walletKitClient) ListSweepsVerbose(ctx context.Context) (
550+
[]lnwallet.TransactionDetail, error) {
551+
552+
rpcCtx, cancel := context.WithTimeout(ctx, m.timeout)
553+
defer cancel()
554+
555+
resp, err := m.client.ListSweeps(
556+
m.walletKitMac.WithMacaroonAuth(rpcCtx),
557+
&walletrpc.ListSweepsRequest{
558+
Verbose: true,
559+
},
560+
)
561+
if err != nil {
562+
return nil, err
563+
}
564+
565+
// Since we have requested the verbose response from LND, we need to
566+
// unmarshal transaction details for each individual sweep.
567+
rpcDetails := resp.GetTransactionDetails()
568+
if rpcDetails == nil {
569+
return nil, fmt.Errorf("invalid transaction details")
570+
}
571+
572+
var result []lnwallet.TransactionDetail
573+
for _, txDetail := range rpcDetails.Transactions {
574+
tx, err := UnmarshalTransactionDetail(
575+
txDetail, m.chainParams,
576+
)
577+
if err != nil {
578+
return nil, err
579+
}
580+
result = append(result, *tx)
581+
}
582+
583+
return result, nil
584+
}
585+
427586
// BumpFee attempts to bump the fee of a transaction by spending one of its
428587
// outputs at the given fee rate. This essentially results in a
429588
// child-pays-for-parent (CPFP) scenario. If the given output has been used in a

0 commit comments

Comments
 (0)