lnwire: add MergedCopy method to CustomRecords

This commit is contained in:
Oliver Gugger
2024-09-12 17:45:26 +02:00
parent 0c6a1558d5
commit 83923c7f33
2 changed files with 68 additions and 0 deletions

View File

@@ -89,6 +89,22 @@ func (c CustomRecords) Copy() CustomRecords {
return customRecords
}
// MergedCopy creates a copy of the records and merges them with the given
// records. If the same key is present in both sets, the value from the other
// records will be used.
func (c CustomRecords) MergedCopy(other CustomRecords) CustomRecords {
copiedRecords := make(CustomRecords, len(c))
for k, v := range c {
copiedRecords[k] = v
}
for k, v := range other {
copiedRecords[k] = v
}
return copiedRecords
}
// ExtendRecordProducers extends the given records slice with the custom
// records. The resultant records slice will be sorted if the given records
// slice contains TLV types greater than or equal to MinCustomRecordsTlvType.