Skip to content

Commit 565ee3c

Browse files
committed
multi: add decimal display to OpenChannel struct
1 parent 63e7997 commit 565ee3c

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

rfqmsg/custom_channel_data.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ type JsonAssetGenesis struct {
2121
// JsonAssetUtxo is a struct that represents the UTXO information of an asset
2222
// within a channel.
2323
type JsonAssetUtxo struct {
24-
Version int64 `json:"version"`
25-
AssetGenesis JsonAssetGenesis `json:"asset_genesis"`
26-
Amount uint64 `json:"amount"`
27-
ScriptKey string `json:"script_key"`
24+
Version int64 `json:"version"`
25+
AssetGenesis JsonAssetGenesis `json:"asset_genesis"`
26+
Amount uint64 `json:"amount"`
27+
ScriptKey string `json:"script_key"`
28+
DecimalDisplay uint8 `json:"decimal_display"`
2829
}
2930

3031
// JsonAssetChanInfo is a struct that represents the channel information of a

tapchannel/aux_funding_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func (p *pendingAssetFunding) toAuxFundingDesc(req *bindFundingReq,
541541

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

546546
// Now we'll encode the 3 TLV blobs that lnd will store: the main one
547547
// for the funding details, and then the blobs for the local and remote

tapchannelmsg/custom_channel_data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (c *ChannelCustomData) AsJson() ([]byte, error) {
8181
ScriptKey: hex.EncodeToString(
8282
a.ScriptKey.PubKey.SerializeCompressed(),
8383
),
84+
DecimalDisplay: c.OpenChan.DecimalDisplay.Val,
8485
}
8586
resp.Assets = append(resp.Assets, rfqmsg.JsonAssetChanInfo{
8687
AssetInfo: utxo,

tapchannelmsg/records.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,28 @@ type OpenChannel struct {
8686
// FundedAssets is a list of asset outputs that was committed to the
8787
// funding output of a commitment.
8888
FundedAssets tlv.RecordT[tlv.TlvType0, AssetOutputListRecord]
89+
90+
// DecimalDisplay is the asset's unit precision. We place this value on
91+
// the channel directly and not into each funding asset balance struct
92+
// since even for a channel with multiple tranches of fungible assets,
93+
// this value needs to be the same for all assets. Otherwise, they would
94+
// not be fungible.
95+
DecimalDisplay tlv.RecordT[tlv.TlvType1, uint8]
8996
}
9097

9198
// NewOpenChannel creates a new OpenChannel record with the given funded assets.
92-
func NewOpenChannel(fundedAssets []*AssetOutput) *OpenChannel {
99+
func NewOpenChannel(fundedAssets []*AssetOutput,
100+
decimalDisplay uint8) *OpenChannel {
101+
93102
return &OpenChannel{
94103
FundedAssets: tlv.NewRecordT[tlv.TlvType0](
95104
AssetOutputListRecord{
96105
Outputs: fundedAssets,
97106
},
98107
),
108+
DecimalDisplay: tlv.NewPrimitiveRecord[tlv.TlvType1](
109+
decimalDisplay,
110+
),
99111
}
100112
}
101113

@@ -109,6 +121,7 @@ func (o *OpenChannel) Assets() []*AssetOutput {
109121
func (o *OpenChannel) records() []tlv.Record {
110122
return []tlv.Record{
111123
o.FundedAssets.Record(),
124+
o.DecimalDisplay.Record(),
112125
}
113126
}
114127

tapchannelmsg/records_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ func TestOpenChannel(t *testing.T) {
7676
name: "channel with funded asset",
7777
channel: NewOpenChannel([]*AssetOutput{
7878
NewAssetOutput([32]byte{1}, 1000, *randProof),
79-
}),
79+
}, 0),
8080
},
8181
{
8282
name: "channel with multiple funded assets",
8383
channel: NewOpenChannel([]*AssetOutput{
8484
NewAssetOutput([32]byte{1}, 1000, *randProof),
8585
NewAssetOutput([32]byte{2}, 2000, *randProof),
86-
}),
86+
}, 11),
8787
},
8888
}
8989

0 commit comments

Comments
 (0)