From 0b5be8576e34f3cd8e5a18b1c01d1ade70d8c98c Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 24 Mar 2021 19:51:22 -0700 Subject: [PATCH] channeldb/invoice: make Copy() a member of InvoiceHTLC --- channeldb/invoices.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 6d6c4d5c..5daee5ff 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -535,6 +535,21 @@ type InvoiceHTLC struct { AMP *InvoiceHtlcAMPData } +// Copy makes a deep copy of the target InvoiceHTLC. +func (h *InvoiceHTLC) Copy() *InvoiceHTLC { + result := *h + + // Make a copy of the CustomSet map. + result.CustomRecords = make(record.CustomSet) + for k, v := range h.CustomRecords { + result.CustomRecords[k] = v + } + + result.AMP = h.AMP.Copy() + + return &result +} + // IsInHTLCSet returns true if this HTLC is part an HTLC set. If nil is passed, // this method returns true if this is an MPP HTLC. Otherwise, it only returns // true if the AMP HTLC's set id matches the populated setID. @@ -1742,21 +1757,6 @@ func copySlice(src []byte) []byte { return dest } -// copyInvoiceHTLC makes a deep copy of the supplied invoice HTLC. -func copyInvoiceHTLC(src *InvoiceHTLC) *InvoiceHTLC { - result := *src - - // Make a copy of the CustomSet map. - result.CustomRecords = make(record.CustomSet) - for k, v := range src.CustomRecords { - result.CustomRecords[k] = v - } - - result.AMP = src.AMP.Copy() - - return &result -} - // copyInvoice makes a deep copy of the supplied invoice. func copyInvoice(src *Invoice) *Invoice { dest := Invoice{ @@ -1783,7 +1783,7 @@ func copyInvoice(src *Invoice) *Invoice { } for k, v := range src.Htlcs { - dest.Htlcs[k] = copyInvoiceHTLC(v) + dest.Htlcs[k] = v.Copy() } return &dest