Skip to content

Commit ca19ee8

Browse files
committed
WIP: universerpc: add InsertSupplyLeaves RPC endpoint
1 parent f5d5b59 commit ca19ee8

File tree

6 files changed

+709
-298
lines changed

6 files changed

+709
-298
lines changed

rpcserver.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,6 +4595,105 @@ func (r *rpcServer) FetchSupplyLeaves(ctx context.Context,
45954595
}, nil
45964596
}
45974597

4598+
// InsertSupplyLeaves inserts the set of supply leaves for the given asset
4599+
// specifier.
4600+
func (r *rpcServer) InsertSupplyLeaves(ctx context.Context,
4601+
req *unirpc.InsertSupplyLeavesRequest) (
4602+
*unirpc.InsertSupplyLeavesResponse, error) {
4603+
4604+
// Parse asset group key from the request.
4605+
var groupPubKey btcec.PublicKey
4606+
4607+
switch {
4608+
case len(req.GetGroupKeyBytes()) > 0:
4609+
gk, err := btcec.ParsePubKey(req.GetGroupKeyBytes())
4610+
if err != nil {
4611+
return nil, fmt.Errorf("parsing group key: %w", err)
4612+
}
4613+
4614+
groupPubKey = *gk
4615+
4616+
case len(req.GetGroupKeyStr()) > 0:
4617+
groupKeyBytes, err := hex.DecodeString(req.GetGroupKeyStr())
4618+
if err != nil {
4619+
return nil, fmt.Errorf("decoding group key: %w", err)
4620+
}
4621+
4622+
gk, err := btcec.ParsePubKey(groupKeyBytes)
4623+
if err != nil {
4624+
return nil, fmt.Errorf("parsing group key: %w", err)
4625+
}
4626+
4627+
groupPubKey = *gk
4628+
4629+
default:
4630+
return nil, fmt.Errorf("group key unspecified")
4631+
}
4632+
4633+
// Log the operation for debugging purposes.
4634+
rpcsLog.Debugf("InsertSupplyLeaves called for group key: %x",
4635+
groupPubKey.SerializeCompressed())
4636+
4637+
// Initialize the SupplyLeaves structure to collect all unmarshalled
4638+
// events.
4639+
var supplyLeaves supplycommit.SupplyLeaves
4640+
4641+
// Process issuance leaves.
4642+
supplyLeaves.IssuanceLeafEntries = make(
4643+
[]supplycommit.NewMintEvent, 0, len(req.IssuanceLeaves),
4644+
)
4645+
for _, rpcLeaf := range req.IssuanceLeaves {
4646+
mintEvent, err := unmarshalMintSupplyLeaf(rpcLeaf)
4647+
if err != nil {
4648+
return nil, fmt.Errorf("failed to unmarshal issuance "+
4649+
"leaf: %w", err)
4650+
}
4651+
supplyLeaves.IssuanceLeafEntries = append(
4652+
supplyLeaves.IssuanceLeafEntries, *mintEvent,
4653+
)
4654+
}
4655+
4656+
// Process burn leaves.
4657+
supplyLeaves.BurnLeafEntries = make(
4658+
[]supplycommit.NewBurnEvent, 0, len(req.BurnLeaves),
4659+
)
4660+
for _, rpcLeaf := range req.BurnLeaves {
4661+
burnEvent, err := unmarshalBurnSupplyLeaf(rpcLeaf)
4662+
if err != nil {
4663+
return nil, fmt.Errorf("failed to unmarshal burn "+
4664+
"leaf: %w", err)
4665+
}
4666+
supplyLeaves.BurnLeafEntries = append(
4667+
supplyLeaves.BurnLeafEntries, *burnEvent,
4668+
)
4669+
}
4670+
4671+
// Process ignore leaves.
4672+
supplyLeaves.IgnoreLeafEntries = make(
4673+
[]supplycommit.NewIgnoreEvent, 0, len(req.IgnoreLeaves),
4674+
)
4675+
for _, rpcLeaf := range req.IgnoreLeaves {
4676+
ignoreEvent, err := unmarshalIgnoreSupplyLeaf(rpcLeaf)
4677+
if err != nil {
4678+
return nil, fmt.Errorf("failed to unmarshal ignore "+
4679+
"leaf: %w", err)
4680+
}
4681+
supplyLeaves.IgnoreLeafEntries = append(
4682+
supplyLeaves.IgnoreLeafEntries, *ignoreEvent,
4683+
)
4684+
}
4685+
4686+
rpcsLog.Debugf("Successfully unmarshalled %d issuance, %d burn, "+
4687+
"and %d ignore leaves", len(supplyLeaves.IssuanceLeafEntries),
4688+
len(supplyLeaves.BurnLeafEntries),
4689+
len(supplyLeaves.IgnoreLeafEntries))
4690+
4691+
// TODO: Implement actual insertion logic using the populated
4692+
// supplyLeaves.
4693+
4694+
return &unirpc.InsertSupplyLeavesResponse{}, nil
4695+
}
4696+
45984697
// SubscribeSendAssetEventNtfns registers a subscription to the event
45994698
// notification stream which relates to the asset sending process.
46004699
func (r *rpcServer) SubscribeSendAssetEventNtfns(

0 commit comments

Comments
 (0)