1
1
package rfq
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"sync"
6
7
"time"
@@ -370,10 +371,12 @@ func (n *Negotiator) HandleIncomingBuyRequest(
370
371
peerID , request .PriceOracleMetadata , IntentRecvPayment ,
371
372
)
372
373
if err != nil {
373
- // Send a reject message to the peer.
374
+ // Construct an appropriate RejectErr based on
375
+ // the oracle's response, and send it to the
376
+ // peer.
374
377
msg := rfqmsg .NewReject (
375
378
request .Peer , request .ID ,
376
- rfqmsg . ErrUnknownReject ,
379
+ createCustomRejectErr ( err ) ,
377
380
)
378
381
sendOutgoingMsg (msg )
379
382
@@ -471,10 +474,12 @@ func (n *Negotiator) HandleIncomingSellRequest(
471
474
peerID , request .PriceOracleMetadata , IntentPayInvoice ,
472
475
)
473
476
if err != nil {
474
- // Send a reject message to the peer.
477
+ // Construct an appropriate RejectErr based on
478
+ // the oracle's response, and send it to the
479
+ // peer.
475
480
msg := rfqmsg .NewReject (
476
481
request .Peer , request .ID ,
477
- rfqmsg . ErrUnknownReject ,
482
+ createCustomRejectErr ( err ) ,
478
483
)
479
484
sendOutgoingMsg (msg )
480
485
@@ -493,6 +498,36 @@ func (n *Negotiator) HandleIncomingSellRequest(
493
498
return nil
494
499
}
495
500
501
+ // createCustomRejectErr creates a RejectErr with code 0 and a custom message
502
+ // based on an error response from a price oracle.
503
+ func createCustomRejectErr (err error ) rfqmsg.RejectErr {
504
+ var oracleError * OracleError
505
+
506
+ if errors .As (err , & oracleError ) {
507
+ // The error is of the expected type, so switch on the error
508
+ // code returned by the oracle. If the code is benign, then the
509
+ // RejectErr will simply relay the oracle's message. Otherwise,
510
+ // we'll return an opaque rejection message.
511
+ switch oracleError .Code {
512
+
513
+ // The rejection message will state that the oracle doesn't
514
+ // support the asset.
515
+ case ErrUnsupportedOracleAsset :
516
+ msg := oracleError .Error ()
517
+ return rfqmsg .ErrRejectWithCustomMsg (msg )
518
+
519
+ // The rejection message will be opaque, with the error
520
+ // unspecified.
521
+ default :
522
+ return rfqmsg .ErrUnknownReject
523
+ }
524
+ } else {
525
+ // The error is of an unexpected type, so just return an opaque
526
+ // error message.
527
+ return rfqmsg .ErrUnknownReject
528
+ }
529
+ }
530
+
496
531
// HandleOutgoingSellOrder handles an outgoing sell order by constructing sell
497
532
// requests and passing them to the outgoing messages channel. These requests
498
533
// are sent to peers.
0 commit comments