Skip to content

Commit 27faee9

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 798597a commit 27faee9

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

rpcserver.go

+45-14
Original file line numberDiff line numberDiff line change
@@ -7687,13 +7687,29 @@ 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+
groupKey, err := btcec.ParsePubKey(req.GroupKey)
7706+
if err != nil {
7707+
return nil, fmt.Errorf("failed to parse group key: %w",
7708+
err)
7709+
}
7710+
specifier = asset.NewSpecifierFromGroupKey(*groupKey)
7711+
76947712
}
7695-
var assetID asset.ID
7696-
copy(assetID[:], req.AssetId)
76977713

76987714
// The peer public key is optional if there is only a single asset
76997715
// channel.
@@ -7708,8 +7724,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77087724
peerPubKey = &parsedKey
77097725
}
77107726

7711-
specifier := asset.NewSpecifierFromId(assetID)
7712-
77137727
// We can now query the asset channels we have.
77147728
assetChan, err := r.rfqChannel(
77157729
ctx, specifier, peerPubKey, ReceiveIntention,
@@ -7731,15 +7745,32 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77317745
time.Duration(expirySeconds) * time.Second,
77327746
)
77337747

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

0 commit comments

Comments
 (0)