|
5 | 5 | "context"
|
6 | 6 | "fmt"
|
7 | 7 |
|
| 8 | + "github.com/lightninglabs/taproot-assets/fn" |
8 | 9 | "github.com/lightninglabs/taproot-assets/mssmt"
|
9 | 10 | "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
|
10 | 11 | unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
|
@@ -210,6 +211,45 @@ func (r *RpcUniverseDiff) FetchProofLeaf(ctx context.Context,
|
210 | 211 | return []*universe.Proof{uniProof}, nil
|
211 | 212 | }
|
212 | 213 |
|
| 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 | + |
213 | 253 | // A compile time interface to ensure that RpcUniverseDiff implements the
|
214 | 254 | // universe.DiffEngine interface.
|
215 | 255 | var _ universe.DiffEngine = (*RpcUniverseDiff)(nil)
|
0 commit comments