Skip to content

Commit f51712c

Browse files
committed
universe: add MultiverseRoot to DiffEngine
1 parent 5600740 commit f51712c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

universe/interface.go

+6
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,12 @@ type DiffEngine interface {
660660
// of diff
661661
FetchProofLeaf(ctx context.Context, id Identifier,
662662
key LeafKey) ([]*Proof, error)
663+
664+
// MultiverseRoot returns the root node of the multiverse for the
665+
// specified proof type. If the given list of universe IDs is non-empty,
666+
// then the root will be calculated just for those universes.
667+
MultiverseRoot(ctx context.Context, proofType ProofType,
668+
filterByIDs []Identifier) (fn.Option[MultiverseRoot], error)
663669
}
664670

665671
// Commitment is an on chain universe commitment. This includes the merkle

universe_rpc_diff.go

+40
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77

8+
"github.com/lightninglabs/taproot-assets/fn"
89
"github.com/lightninglabs/taproot-assets/mssmt"
910
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
1011
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
@@ -210,6 +211,45 @@ func (r *RpcUniverseDiff) FetchProofLeaf(ctx context.Context,
210211
return []*universe.Proof{uniProof}, nil
211212
}
212213

214+
// MultiverseRoot returns the root node of the multiverse for the
215+
// specified proof type. If the given list of universe IDs is non-empty,
216+
// then the root will be calculated just for those universes.
217+
func (r *RpcUniverseDiff) MultiverseRoot(ctx context.Context,
218+
proofType universe.ProofType,
219+
filterByIDs []universe.Identifier) (fn.Option[universe.MultiverseRoot],
220+
error) {
221+
222+
none := fn.None[universe.MultiverseRoot]()
223+
224+
proofTypeRpc, err := MarshalUniProofType(proofType)
225+
if err != nil {
226+
return none, fmt.Errorf("unable to marshal proof type: %w", err)
227+
}
228+
229+
rpcIDs := make([]*unirpc.ID, len(filterByIDs))
230+
for i, id := range filterByIDs {
231+
uniID, err := MarshalUniID(id)
232+
if err != nil {
233+
return none, err
234+
}
235+
236+
rpcIDs[i] = uniID
237+
}
238+
239+
root, err := r.conn.MultiverseRoot(ctx, &unirpc.MultiverseRootRequest{
240+
ProofType: proofTypeRpc,
241+
SpecificIds: rpcIDs,
242+
})
243+
if err != nil {
244+
return none, err
245+
}
246+
247+
return fn.Some(universe.MultiverseRoot{
248+
ProofType: proofType,
249+
Node: unmarshalMerkleSumNode(root.MultiverseRoot),
250+
}), nil
251+
}
252+
213253
// A compile time interface to ensure that RpcUniverseDiff implements the
214254
// universe.DiffEngine interface.
215255
var _ universe.DiffEngine = (*RpcUniverseDiff)(nil)

0 commit comments

Comments
 (0)