Skip to content

Commit e9e1de8

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 154b001 commit e9e1de8

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

rpcserver.go

+20-16
Original file line numberDiff line numberDiff line change
@@ -7679,18 +7679,26 @@ func checkOverpayment(quote *rfqrpc.PeerAcceptedSellQuote,
76797679
func (r *rpcServer) AddInvoice(ctx context.Context,
76807680
req *tchrpc.AddInvoiceRequest) (*tchrpc.AddInvoiceResponse, error) {
76817681

7682+
if len(req.AssetId) > 0 && len(req.GroupKey) > 0 {
7683+
return nil, fmt.Errorf("cannot set both asset id and group key")
7684+
}
7685+
76827686
if req.InvoiceRequest == nil {
76837687
return nil, fmt.Errorf("invoice request must be specified")
76847688
}
76857689
iReq := req.InvoiceRequest
76867690

7687-
// Do some preliminary checks on the asset ID and make sure we have any
7688-
// balance for that asset.
7689-
if len(req.AssetId) != sha256.Size {
7690-
return nil, fmt.Errorf("asset ID must be 32 bytes")
7691+
assetID, groupKey, err := parseAssetSpecifier(
7692+
req.AssetId, "", req.GroupKey, "",
7693+
)
7694+
if err != nil {
7695+
return nil, err
7696+
}
7697+
7698+
specifier, err := asset.NewExclusiveSpecifier(assetID, groupKey)
7699+
if err != nil {
7700+
return nil, err
76917701
}
7692-
var assetID asset.ID
7693-
copy(assetID[:], req.AssetId)
76947702

76957703
// The peer public key is optional if there is only a single asset
76967704
// channel.
@@ -7705,8 +7713,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77057713
peerPubKey = &parsedKey
77067714
}
77077715

7708-
specifier := asset.NewSpecifierFromId(assetID)
7709-
77107716
// We can now query the asset channels we have.
77117717
assetChan, err := r.rfqChannel(
77127718
ctx, specifier, peerPubKey, ReceiveIntention,
@@ -7728,15 +7734,13 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
77287734
time.Duration(expirySeconds) * time.Second,
77297735
)
77307736

7737+
rpcSpecifier := marshalAssetSpecifier(specifier)
7738+
77317739
resp, err := r.AddAssetBuyOrder(ctx, &rfqrpc.AddAssetBuyOrderRequest{
7732-
AssetSpecifier: &rfqrpc.AssetSpecifier{
7733-
Id: &rfqrpc.AssetSpecifier_AssetId{
7734-
AssetId: assetID[:],
7735-
},
7736-
},
7737-
AssetMaxAmt: req.AssetAmount,
7738-
Expiry: uint64(expiryTimestamp.Unix()),
7739-
PeerPubKey: peerPubKey[:],
7740+
AssetSpecifier: &rpcSpecifier,
7741+
AssetMaxAmt: req.AssetAmount,
7742+
Expiry: uint64(expiryTimestamp.Unix()),
7743+
PeerPubKey: peerPubKey[:],
77407744
TimeoutSeconds: uint32(
77417745
rfq.DefaultTimeout.Seconds(),
77427746
),

0 commit comments

Comments
 (0)