mirror of
https://github.com/lightningnetwork/lnd.git
synced 2026-08-16 13:00:19 +02:00
The Offer struct models a long-lived, reusable BOLT 12 payment template. It defines TLV fields as optional records and exposes Encode/DecodeOffer for round-trip serialization. The struct implements lnwire.PureTLVMessage; AllRecords filters the decoded TypeMap through bolt12InUnsignedRange to derive any signed-range extras the encoder must re-emit, keeping offer_id and the Merkle root stable across encoders that understand a wider set of even/odd extensions.
29 lines
669 B
Go
29 lines
669 B
Go
package bolt12
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/lightningnetwork/lnd/tlv"
|
|
)
|
|
|
|
// decodeStream runs a single typed-stream pass over data and returns the
|
|
// canonical TypeMap. Records may be passed in any order; NewStream requires
|
|
// them sorted, so SortRecords runs first.
|
|
func decodeStream(data []byte, records ...tlv.Record) (tlv.TypeMap, error) {
|
|
tlv.SortRecords(records)
|
|
|
|
stream, err := tlv.NewStream(records...)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("create stream: %w", err)
|
|
}
|
|
|
|
typeMap, err := stream.DecodeWithParsedTypesP2P(
|
|
bytes.NewReader(data),
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("decode stream: %w", err)
|
|
}
|
|
|
|
return typeMap, nil
|
|
}
|