Skip to content

Commit

Permalink
multi: add decimal display to OpenChannel struct
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Dec 6, 2024
1 parent 63e7997 commit 565ee3c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
9 changes: 5 additions & 4 deletions rfqmsg/custom_channel_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ type JsonAssetGenesis struct {
// JsonAssetUtxo is a struct that represents the UTXO information of an asset
// within a channel.
type JsonAssetUtxo struct {
Version int64 `json:"version"`
AssetGenesis JsonAssetGenesis `json:"asset_genesis"`
Amount uint64 `json:"amount"`
ScriptKey string `json:"script_key"`
Version int64 `json:"version"`
AssetGenesis JsonAssetGenesis `json:"asset_genesis"`
Amount uint64 `json:"amount"`
ScriptKey string `json:"script_key"`
DecimalDisplay uint8 `json:"decimal_display"`
}

// JsonAssetChanInfo is a struct that represents the channel information of a
Expand Down
2 changes: 1 addition & 1 deletion tapchannel/aux_funding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func (p *pendingAssetFunding) toAuxFundingDesc(req *bindFundingReq,

// With all the outputs assembled, we'll now map that to the open
// channel wrapper that'll go in the set of TLV blobs.
openChanDesc := cmsg.NewOpenChannel(assetOutputs)
openChanDesc := cmsg.NewOpenChannel(assetOutputs, decimalDisplay)

// Now we'll encode the 3 TLV blobs that lnd will store: the main one
// for the funding details, and then the blobs for the local and remote
Expand Down
1 change: 1 addition & 0 deletions tapchannelmsg/custom_channel_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (c *ChannelCustomData) AsJson() ([]byte, error) {
ScriptKey: hex.EncodeToString(
a.ScriptKey.PubKey.SerializeCompressed(),
),
DecimalDisplay: c.OpenChan.DecimalDisplay.Val,
}
resp.Assets = append(resp.Assets, rfqmsg.JsonAssetChanInfo{
AssetInfo: utxo,
Expand Down
15 changes: 14 additions & 1 deletion tapchannelmsg/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,28 @@ type OpenChannel struct {
// FundedAssets is a list of asset outputs that was committed to the
// funding output of a commitment.
FundedAssets tlv.RecordT[tlv.TlvType0, AssetOutputListRecord]

// DecimalDisplay is the asset's unit precision. We place this value on
// the channel directly and not into each funding asset balance struct
// since even for a channel with multiple tranches of fungible assets,
// this value needs to be the same for all assets. Otherwise, they would
// not be fungible.
DecimalDisplay tlv.RecordT[tlv.TlvType1, uint8]
}

// NewOpenChannel creates a new OpenChannel record with the given funded assets.
func NewOpenChannel(fundedAssets []*AssetOutput) *OpenChannel {
func NewOpenChannel(fundedAssets []*AssetOutput,
decimalDisplay uint8) *OpenChannel {

return &OpenChannel{
FundedAssets: tlv.NewRecordT[tlv.TlvType0](
AssetOutputListRecord{
Outputs: fundedAssets,
},
),
DecimalDisplay: tlv.NewPrimitiveRecord[tlv.TlvType1](
decimalDisplay,
),
}
}

Expand All @@ -109,6 +121,7 @@ func (o *OpenChannel) Assets() []*AssetOutput {
func (o *OpenChannel) records() []tlv.Record {
return []tlv.Record{
o.FundedAssets.Record(),
o.DecimalDisplay.Record(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions tapchannelmsg/records_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func TestOpenChannel(t *testing.T) {
name: "channel with funded asset",
channel: NewOpenChannel([]*AssetOutput{
NewAssetOutput([32]byte{1}, 1000, *randProof),
}),
}, 0),
},
{
name: "channel with multiple funded assets",
channel: NewOpenChannel([]*AssetOutput{
NewAssetOutput([32]byte{1}, 1000, *randProof),
NewAssetOutput([32]byte{2}, 2000, *randProof),
}),
}, 11),
},
}

Expand Down

0 comments on commit 565ee3c

Please sign in to comment.