From 0fb29b2598c07540988f9759a986c5a829484819 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Fri, 16 Aug 2024 15:55:18 -0700 Subject: [PATCH] channeldb: add convenience functions for generating Source/Dest Refs --- channeldb/forwarding_package.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/channeldb/forwarding_package.go b/channeldb/forwarding_package.go index 4c447fc03..11c0099e7 100644 --- a/channeldb/forwarding_package.go +++ b/channeldb/forwarding_package.go @@ -286,6 +286,27 @@ func NewFwdPkg(source lnwire.ShortChannelID, height uint64, } } +// SourceRef is a convenience method that returns an AddRef to this forwarding +// package for the index in the argument. It is the caller's responsibility +// to ensure that the index is in bounds. +func (f *FwdPkg) SourceRef(i uint16) AddRef { + return AddRef{ + Height: f.Height, + Index: i, + } +} + +// DestRef is a convenience method that returns a SettleFailRef to this +// forwarding package for the index in the argument. It is the caller's +// responsibility to ensure that the index is in bounds. +func (f *FwdPkg) DestRef(i uint16) SettleFailRef { + return SettleFailRef{ + Source: f.Source, + Height: f.Height, + Index: i, + } +} + // ID returns an unique identifier for this package, used to ensure that sphinx // replay processing of this batch is idempotent. func (f *FwdPkg) ID() []byte {