Skip to content

Commit b53b3a2

Browse files
committed
rpcserver: AddInvoice uses groupkey
In this commit we take the user defined group key and allow the asset specifier to be created over it. All the calls that accept it as an argument are already groupkey aware.
1 parent f4b1458 commit b53b3a2

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

rpcserver.go

+46-14
Original file line numberDiff line numberDiff line change
@@ -7687,13 +7687,30 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
76877687
}
76887688
iReq := req.InvoiceRequest
76897689

7690-
// Do some preliminary checks on the asset ID and make sure we have any
7691-
// balance for that asset.
7692-
if len(req.AssetId) != sha256.Size {
7693-
return nil, fmt.Errorf("asset ID must be 32 bytes")
7690+
var specifier asset.Specifier
7691+
7692+
switch {
7693+
case len(req.AssetId) > 0 && len(req.GroupKey) > 0:
7694+
return nil, fmt.Errorf("cannot set both asset id and group key")
7695+
7696+
case len(req.AssetId) > 0:
7697+
if len(req.AssetId) != sha256.Size {
7698+
return nil, fmt.Errorf("asset ID must be 32 bytes")
7699+
}
7700+
var assetID asset.ID
7701+
copy(assetID[:], req.AssetId)
7702+
specifier = asset.NewSpecifierFromId(assetID)
7703+
7704+
case len(req.GroupKey) > 0:
7705+
// asset.NewSpecifierFromGroupKey()
7706+
groupKey, err := btcec.ParsePubKey(req.GroupKey)
7707+
if err != nil {
7708+
return nil, fmt.Errorf("failed to parse group key: %w",
7709+
err)
7710+
}
7711+
specifier = asset.NewSpecifierFromGroupKey(*groupKey)
7712+
76947713
}
7695-
var assetID asset.ID
7696-
copy(assetID[:], req.AssetId)
76977714

76987715
// The peer public key is optional if there is only a single asset
76997716
// channel.
@@ -7708,8 +7725,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77087725
peerPubKey = &parsedKey
77097726
}
77107727

7711-
specifier := asset.NewSpecifierFromId(assetID)
7712-
77137728
// We can now query the asset channels we have.
77147729
assetChan, err := r.rfqChannel(
77157730
ctx, specifier, peerPubKey, ReceiveIntention,
@@ -7731,15 +7746,32 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77317746
time.Duration(expirySeconds) * time.Second,
77327747
)
77337748

7734-
resp, err := r.AddAssetBuyOrder(ctx, &rfqrpc.AddAssetBuyOrderRequest{
7735-
AssetSpecifier: &rfqrpc.AssetSpecifier{
7749+
var rpcSpecifier rfqrpc.AssetSpecifier
7750+
7751+
switch {
7752+
case specifier.HasId():
7753+
assetID := specifier.UnwrapIdToPtr()
7754+
rpcSpecifier = rfqrpc.AssetSpecifier{
77367755
Id: &rfqrpc.AssetSpecifier_AssetId{
77377756
AssetId: assetID[:],
77387757
},
7739-
},
7740-
AssetMaxAmt: req.AssetAmount,
7741-
Expiry: uint64(expiryTimestamp.Unix()),
7742-
PeerPubKey: peerPubKey[:],
7758+
}
7759+
7760+
case specifier.HasGroupPubKey():
7761+
groupKey := specifier.UnwrapGroupKeyToPtr()
7762+
groupKeyBytes := groupKey.SerializeCompressed()
7763+
rpcSpecifier = rfqrpc.AssetSpecifier{
7764+
Id: &rfqrpc.AssetSpecifier_GroupKey{
7765+
GroupKey: groupKeyBytes,
7766+
},
7767+
}
7768+
}
7769+
7770+
resp, err := r.AddAssetBuyOrder(ctx, &rfqrpc.AddAssetBuyOrderRequest{
7771+
AssetSpecifier: &rpcSpecifier,
7772+
AssetMaxAmt: req.AssetAmount,
7773+
Expiry: uint64(expiryTimestamp.Unix()),
7774+
PeerPubKey: peerPubKey[:],
77437775
TimeoutSeconds: uint32(
77447776
rfq.DefaultTimeout.Seconds(),
77457777
),

0 commit comments

Comments
 (0)