@@ -53,6 +53,11 @@ type LightningClient interface {
53
53
// ClosedChannels returns all closed channels of the backing lnd node.
54
54
ClosedChannels (ctx context.Context ) ([]ClosedChannel , error )
55
55
56
+ // ForwardingHistory makes a paginated call to our forwarding history
57
+ // endpoint.
58
+ ForwardingHistory (ctx context.Context ,
59
+ req ForwardingHistoryRequest ) (* ForwardingHistoryResponse , error )
60
+
56
61
// ChannelBackup retrieves the backup for a particular channel. The
57
62
// backup is returned as an encrypted chanbackup.Single payload.
58
63
ChannelBackup (context.Context , wire.OutPoint ) ([]byte , error )
@@ -842,6 +847,95 @@ func getInitiator(initiator lnrpc.Initiator) (Initiator, error) {
842
847
}
843
848
}
844
849
850
+ // ForwardingHistoryRequest contains the request parameters for a paginated
851
+ // forwarding history call.
852
+ type ForwardingHistoryRequest struct {
853
+ // StartTime is the beginning of the query period.
854
+ StartTime time.Time
855
+
856
+ // EndTime is the end of the query period.
857
+ EndTime time.Time
858
+
859
+ // MaxEvents is the maximum number of events to return.
860
+ MaxEvents uint32
861
+
862
+ // Offset is the index from which to start querying.
863
+ Offset uint32
864
+ }
865
+
866
+ // ForwardingHistoryResponse contains the response to a forwarding history
867
+ // query, including last index offset required for paginated queries.
868
+ type ForwardingHistoryResponse struct {
869
+ // LastIndexOffset is the index offset of the last item in our set.
870
+ LastIndexOffset uint32
871
+
872
+ // Events is the set of events that were found in the interval queried.
873
+ Events []ForwardingEvent
874
+ }
875
+
876
+ // ForwardingEvent represents a htlc that was forwarded through our node.
877
+ type ForwardingEvent struct {
878
+ // Timestamp is the time that we processed the forwarding event.
879
+ Timestamp time.Time
880
+
881
+ // ChannelIn is the id of the channel the htlc arrived at our node on.
882
+ ChannelIn uint64
883
+
884
+ // ChannelOut is the id of the channel the htlc left our node on.
885
+ ChannelOut uint64
886
+
887
+ // AmountMsatIn is the amount that was forwarded into our node in
888
+ // millisatoshis.
889
+ AmountMsatIn lnwire.MilliSatoshi
890
+
891
+ // AmountMsatOut is the amount that was forwarded out of our node in
892
+ // millisatoshis.
893
+ AmountMsatOut lnwire.MilliSatoshi
894
+
895
+ // FeeMsat is the amount of fees earned in millisatoshis,
896
+ FeeMsat lnwire.MilliSatoshi
897
+ }
898
+
899
+ // ForwardingHistory returns a set of forwarding events for the period queried.
900
+ // Note that this call is paginated, and the information required to make
901
+ // subsequent calls is provided in the response.
902
+ func (s * lightningClient ) ForwardingHistory (ctx context.Context ,
903
+ req ForwardingHistoryRequest ) (* ForwardingHistoryResponse , error ) {
904
+
905
+ rpcCtx , cancel := context .WithTimeout (ctx , rpcTimeout )
906
+ defer cancel ()
907
+
908
+ response , err := s .client .ForwardingHistory (
909
+ s .adminMac .WithMacaroonAuth (rpcCtx ),
910
+ & lnrpc.ForwardingHistoryRequest {
911
+ StartTime : uint64 (req .StartTime .Unix ()),
912
+ EndTime : uint64 (req .EndTime .Unix ()),
913
+ IndexOffset : req .Offset ,
914
+ NumMaxEvents : req .MaxEvents ,
915
+ },
916
+ )
917
+ if err != nil {
918
+ return nil , err
919
+ }
920
+
921
+ events := make ([]ForwardingEvent , len (response .ForwardingEvents ))
922
+ for i , event := range response .ForwardingEvents {
923
+ events [i ] = ForwardingEvent {
924
+ Timestamp : time .Unix (int64 (event .Timestamp ), 0 ),
925
+ ChannelIn : event .ChanIdIn ,
926
+ ChannelOut : event .ChanIdOut ,
927
+ AmountMsatIn : lnwire .MilliSatoshi (event .AmtIn ),
928
+ AmountMsatOut : lnwire .MilliSatoshi (event .AmtOut ),
929
+ FeeMsat : lnwire .MilliSatoshi (event .FeeMsat ),
930
+ }
931
+ }
932
+
933
+ return & ForwardingHistoryResponse {
934
+ LastIndexOffset : response .LastOffsetIndex ,
935
+ Events : events ,
936
+ }, nil
937
+ }
938
+
845
939
// ChannelBackup retrieves the backup for a particular channel. The backup is
846
940
// returned as an encrypted chanbackup.Single payload.
847
941
func (s * lightningClient ) ChannelBackup (ctx context.Context ,
0 commit comments