Skip to content

Commit 99e85a7

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 a486a7b commit 99e85a7

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

Diff for: rpcserver.go

+25-16
Original file line numberDiff line numberDiff line change
@@ -7684,18 +7684,31 @@ func checkOverpayment(quote *rfqrpc.PeerAcceptedSellQuote,
76847684
func (r *rpcServer) AddInvoice(ctx context.Context,
76857685
req *tchrpc.AddInvoiceRequest) (*tchrpc.AddInvoiceResponse, error) {
76867686

7687+
if len(req.AssetId) > 0 && len(req.GroupKey) > 0 {
7688+
return nil, fmt.Errorf("cannot set both asset id and group key")
7689+
}
7690+
76877691
if req.InvoiceRequest == nil {
76887692
return nil, fmt.Errorf("invoice request must be specified")
76897693
}
76907694
iReq := req.InvoiceRequest
76917695

7692-
// Do some preliminary checks on the asset ID and make sure we have any
7693-
// balance for that asset.
7694-
if len(req.AssetId) != sha256.Size {
7695-
return nil, fmt.Errorf("asset ID must be 32 bytes")
7696+
var specifier asset.Specifier
7697+
7698+
assetID, groupKey, err := parseAssetSpecifier(
7699+
req.AssetId, "", req.GroupKey, "",
7700+
)
7701+
if err != nil {
7702+
return nil, err
7703+
}
7704+
7705+
switch {
7706+
case assetID != nil:
7707+
specifier = asset.NewSpecifierFromId(*assetID)
7708+
7709+
case groupKey != nil:
7710+
specifier = asset.NewSpecifierFromGroupKey(*groupKey)
76967711
}
7697-
var assetID asset.ID
7698-
copy(assetID[:], req.AssetId)
76997712

77007713
// The peer public key is optional if there is only a single asset
77017714
// channel.
@@ -7710,8 +7723,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77107723
peerPubKey = &parsedKey
77117724
}
77127725

7713-
specifier := asset.NewSpecifierFromId(assetID)
7714-
77157726
// We can now query the asset channels we have.
77167727
assetChan, err := r.rfqChannel(
77177728
ctx, specifier, peerPubKey, ReceiveIntention,
@@ -7733,15 +7744,13 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77337744
time.Duration(expirySeconds) * time.Second,
77347745
)
77357746

7747+
rpcSpecifier := marshalAssetSpecifier(specifier)
7748+
77367749
resp, err := r.AddAssetBuyOrder(ctx, &rfqrpc.AddAssetBuyOrderRequest{
7737-
AssetSpecifier: &rfqrpc.AssetSpecifier{
7738-
Id: &rfqrpc.AssetSpecifier_AssetId{
7739-
AssetId: assetID[:],
7740-
},
7741-
},
7742-
AssetMaxAmt: req.AssetAmount,
7743-
Expiry: uint64(expiryTimestamp.Unix()),
7744-
PeerPubKey: peerPubKey[:],
7750+
AssetSpecifier: &rpcSpecifier,
7751+
AssetMaxAmt: req.AssetAmount,
7752+
Expiry: uint64(expiryTimestamp.Unix()),
7753+
PeerPubKey: peerPubKey[:],
77457754
TimeoutSeconds: uint32(
77467755
rfq.DefaultTimeout.Seconds(),
77477756
),

0 commit comments

Comments
 (0)