Skip to content

Commit eff99b8

Browse files
committed
address+rpcserver: move DecDisplayForAssetID to addr book
1 parent fa97f8f commit eff99b8

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

address/book.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,20 @@ func (b *Book) FetchAssetMetaForAsset(ctx context.Context,
423423
return meta, nil
424424
}
425425

426+
// DecDisplayForAssetID attempts to fetch the meta reveal for a specific asset
427+
// ID and extract the decimal display value from it.
428+
func (b *Book) DecDisplayForAssetID(ctx context.Context,
429+
id asset.ID) (fn.Option[uint32], error) {
430+
431+
meta, err := b.FetchAssetMetaForAsset(ctx, id)
432+
if err != nil {
433+
return fn.None[uint32](), fmt.Errorf("unable to fetch asset "+
434+
"meta for asset_id=%v :%v", id, err)
435+
}
436+
437+
return meta.DecDisplayOption()
438+
}
439+
426440
// NewAddress creates a new Taproot Asset address based on the input parameters.
427441
func (b *Book) NewAddress(ctx context.Context, addrVersion Version,
428442
specifier asset.Specifier, amount uint64,

rpcserver.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,9 @@ func (r *rpcServer) MarshalChainAsset(ctx context.Context, a asset.ChainAsset,
12291229
case meta != nil:
12301230
decDisplay, err = meta.DecDisplayOption()
12311231
default:
1232-
decDisplay, err = r.DecDisplayForAssetID(ctx, a.ID())
1232+
decDisplay, err = r.cfg.AddrBook.DecDisplayForAssetID(
1233+
ctx, a.ID(),
1234+
)
12331235
}
12341236
if err != nil {
12351237
return nil, err
@@ -5475,7 +5477,9 @@ func (r *rpcServer) AssetLeaves(ctx context.Context,
54755477
for i, assetLeaf := range assetLeaves {
54765478
assetLeaf := assetLeaf
54775479

5478-
decDisplay, err := r.DecDisplayForAssetID(ctx, assetLeaf.ID())
5480+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(
5481+
ctx, assetLeaf.ID(),
5482+
)
54795483
if err != nil {
54805484
return nil, err
54815485
}
@@ -5579,7 +5583,9 @@ func (r *rpcServer) marshalUniverseProofLeaf(ctx context.Context,
55795583
return nil, err
55805584
}
55815585

5582-
decDisplay, err := r.DecDisplayForAssetID(ctx, proof.Leaf.ID())
5586+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(
5587+
ctx, proof.Leaf.ID(),
5588+
)
55835589
if err != nil {
55845590
return nil, err
55855591
}
@@ -6047,7 +6053,7 @@ func (r *rpcServer) marshalUniverseDiff(ctx context.Context,
60476053

60486054
leaves := make([]*unirpc.AssetLeaf, len(diff.NewLeafProofs))
60496055
for i, leaf := range diff.NewLeafProofs {
6050-
decDisplay, err := r.DecDisplayForAssetID(
6056+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(
60516057
ctx, leaf.ID(),
60526058
)
60536059
if err != nil {
@@ -6542,7 +6548,7 @@ func (r *rpcServer) marshalAssetSyncSnapshot(ctx context.Context,
65426548
AnchorPoint: a.AnchorPoint.String(),
65436549
}
65446550

6545-
decDisplay, err := r.DecDisplayForAssetID(ctx, a.AssetID)
6551+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(ctx, a.AssetID)
65466552
if err == nil {
65476553
decDisplay.WhenSome(func(u uint32) {
65486554
rpcAsset.DecimalDisplay = u
@@ -8559,20 +8565,6 @@ func encodeVirtualPackets(packets []*tappsbt.VPacket) ([][]byte, error) {
85598565
return rawPackets, nil
85608566
}
85618567

8562-
// DecDisplayForAssetID attempts to fetch the meta reveal for a specific asset
8563-
// ID and extract the decimal display value from it.
8564-
func (r *rpcServer) DecDisplayForAssetID(ctx context.Context,
8565-
id asset.ID) (fn.Option[uint32], error) {
8566-
8567-
meta, err := r.cfg.AddrBook.FetchAssetMetaForAsset(ctx, id)
8568-
if err != nil {
8569-
return fn.None[uint32](), fmt.Errorf("unable to fetch asset "+
8570-
"meta for asset_id=%v :%v", id, err)
8571-
}
8572-
8573-
return meta.DecDisplayOption()
8574-
}
8575-
85768568
// getInboundPolicy returns the policy of the given channel that points towards
85778569
// our node, so it's the policy set by the remote peer.
85788570
func (r *rpcServer) getInboundPolicy(ctx context.Context, chanID uint64,
@@ -8776,7 +8768,7 @@ func (r *rpcServer) DecodeAssetPayReq(ctx context.Context,
87768768

87778769
// The final piece of information we need is the decimal display
87788770
// information for this asset ID.
8779-
decDisplay, err := r.DecDisplayForAssetID(ctx, assetID)
8771+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(ctx, assetID)
87808772
if err != nil {
87818773
return nil, err
87828774
}

0 commit comments

Comments
 (0)