Skip to content

Commit 2dd2c8c

Browse files
committed
address+rpcserver: move DecDisplayForAssetID to addr book
1 parent fa86360 commit 2dd2c8c

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
@@ -334,6 +334,20 @@ func (b *Book) FetchAssetMetaForAsset(ctx context.Context,
334334
return meta, nil
335335
}
336336

337+
// DecDisplayForAssetID attempts to fetch the meta reveal for a specific asset
338+
// ID and extract the decimal display value from it.
339+
func (b *Book) DecDisplayForAssetID(ctx context.Context,
340+
id asset.ID) (fn.Option[uint32], error) {
341+
342+
meta, err := b.FetchAssetMetaForAsset(ctx, id)
343+
if err != nil {
344+
return fn.None[uint32](), fmt.Errorf("unable to fetch asset "+
345+
"meta for asset_id=%v :%v", id, err)
346+
}
347+
348+
return meta.DecDisplayOption()
349+
}
350+
337351
// NewAddress creates a new Taproot Asset address based on the input parameters.
338352
func (b *Book) NewAddress(ctx context.Context, addrVersion Version,
339353
assetID asset.ID, amount uint64,

rpcserver.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,9 @@ func (r *rpcServer) MarshalChainAsset(ctx context.Context, a asset.ChainAsset,
12281228
case meta != nil:
12291229
decDisplay, err = meta.DecDisplayOption()
12301230
default:
1231-
decDisplay, err = r.DecDisplayForAssetID(ctx, a.ID())
1231+
decDisplay, err = r.cfg.AddrBook.DecDisplayForAssetID(
1232+
ctx, a.ID(),
1233+
)
12321234
}
12331235
if err != nil {
12341236
return nil, err
@@ -5440,7 +5442,9 @@ func (r *rpcServer) AssetLeaves(ctx context.Context,
54405442
for i, assetLeaf := range assetLeaves {
54415443
assetLeaf := assetLeaf
54425444

5443-
decDisplay, err := r.DecDisplayForAssetID(ctx, assetLeaf.ID())
5445+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(
5446+
ctx, assetLeaf.ID(),
5447+
)
54445448
if err != nil {
54455449
return nil, err
54465450
}
@@ -5544,7 +5548,9 @@ func (r *rpcServer) marshalUniverseProofLeaf(ctx context.Context,
55445548
return nil, err
55455549
}
55465550

5547-
decDisplay, err := r.DecDisplayForAssetID(ctx, proof.Leaf.ID())
5551+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(
5552+
ctx, proof.Leaf.ID(),
5553+
)
55485554
if err != nil {
55495555
return nil, err
55505556
}
@@ -6012,7 +6018,7 @@ func (r *rpcServer) marshalUniverseDiff(ctx context.Context,
60126018

60136019
leaves := make([]*unirpc.AssetLeaf, len(diff.NewLeafProofs))
60146020
for i, leaf := range diff.NewLeafProofs {
6015-
decDisplay, err := r.DecDisplayForAssetID(
6021+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(
60166022
ctx, leaf.ID(),
60176023
)
60186024
if err != nil {
@@ -6507,7 +6513,7 @@ func (r *rpcServer) marshalAssetSyncSnapshot(ctx context.Context,
65076513
AnchorPoint: a.AnchorPoint.String(),
65086514
}
65096515

6510-
decDisplay, err := r.DecDisplayForAssetID(ctx, a.AssetID)
6516+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(ctx, a.AssetID)
65116517
if err == nil {
65126518
decDisplay.WhenSome(func(u uint32) {
65136519
rpcAsset.DecimalDisplay = u
@@ -8536,20 +8542,6 @@ func encodeVirtualPackets(packets []*tappsbt.VPacket) ([][]byte, error) {
85368542
return rawPackets, nil
85378543
}
85388544

8539-
// DecDisplayForAssetID attempts to fetch the meta reveal for a specific asset
8540-
// ID and extract the decimal display value from it.
8541-
func (r *rpcServer) DecDisplayForAssetID(ctx context.Context,
8542-
id asset.ID) (fn.Option[uint32], error) {
8543-
8544-
meta, err := r.cfg.AddrBook.FetchAssetMetaForAsset(ctx, id)
8545-
if err != nil {
8546-
return fn.None[uint32](), fmt.Errorf("unable to fetch asset "+
8547-
"meta for asset_id=%v :%v", id, err)
8548-
}
8549-
8550-
return meta.DecDisplayOption()
8551-
}
8552-
85538545
// getInboundPolicy returns the policy of the given channel that points towards
85548546
// our node, so it's the policy set by the remote peer.
85558547
func (r *rpcServer) getInboundPolicy(ctx context.Context, chanID uint64,
@@ -8751,7 +8743,7 @@ func (r *rpcServer) DecodeAssetPayReq(ctx context.Context,
87518743

87528744
// The final piece of information we need is the decimal display
87538745
// information for this asset ID.
8754-
decDisplay, err := r.DecDisplayForAssetID(ctx, assetID)
8746+
decDisplay, err := r.cfg.AddrBook.DecDisplayForAssetID(ctx, assetID)
87558747
if err != nil {
87568748
return nil, err
87578749
}

0 commit comments

Comments
 (0)