@@ -443,10 +443,26 @@ func (n *OpenBazaarNode) SendRefund(peerID string, refundMessage *pb.RicardianCo
443
443
log .Errorf ("failed to marshal the contract: %v" , err )
444
444
return err
445
445
}
446
+ // Create the REFUND message
446
447
m := pb.Message {
447
448
MessageType : pb .Message_REFUND ,
448
449
Payload : a ,
449
450
}
451
+
452
+ // Save REFUND message to the database for this order for resending if necessary
453
+ orderID0 := refundMessage .Refund .OrderID
454
+ if orderID0 == "" {
455
+ log .Errorf ("failed fetching orderID" )
456
+ } else {
457
+ err = n .Datastore .Messages ().Put (
458
+ fmt .Sprintf ("%s-%d" , orderID0 , int (pb .Message_REFUND )),
459
+ orderID0 , pb .Message_REFUND , peerID , repo.Message {Msg : m },
460
+ "" , 0 , []byte {})
461
+ if err != nil {
462
+ log .Errorf ("failed putting message (%s-%d): %v" , orderID0 , int (pb .Message_REFUND ), err )
463
+ }
464
+ }
465
+
450
466
k , err := libp2p .UnmarshalPublicKey (refundMessage .GetBuyerOrder ().GetBuyerID ().GetPubkeys ().Identity )
451
467
if err != nil {
452
468
log .Errorf ("failed to unmarshal publicKey: %v" , err )
@@ -508,16 +524,33 @@ func (n *OpenBazaarNode) SendOrderCompletion(peerID string, k *libp2p.PubKey, co
508
524
}
509
525
510
526
// SendDisputeOpen - send open dispute msg to peer
511
- func (n * OpenBazaarNode ) SendDisputeOpen (peerID string , k * libp2p.PubKey , disputeMessage * pb.RicardianContract ) error {
527
+ func (n * OpenBazaarNode ) SendDisputeOpen (peerID string , k * libp2p.PubKey , disputeMessage * pb.RicardianContract , orderID string ) error {
512
528
a , err := ptypes .MarshalAny (disputeMessage )
513
529
if err != nil {
514
530
log .Errorf ("failed to marshal the contract: %v" , err )
515
531
return err
516
532
}
533
+
534
+ // Create the DISPUTE_OPEN message
517
535
m := pb.Message {
518
536
MessageType : pb .Message_DISPUTE_OPEN ,
519
537
Payload : a ,
520
538
}
539
+
540
+ // Save DISPUTE_OPEN message to the database for this order for resending if necessary
541
+ orderID0 := orderID
542
+ if orderID0 == "" {
543
+ log .Errorf ("failed fetching orderID" )
544
+ } else {
545
+ err = n .Datastore .Messages ().Put (
546
+ fmt .Sprintf ("%s-%d" , orderID0 , int (pb .Message_DISPUTE_OPEN )),
547
+ orderID0 , pb .Message_DISPUTE_OPEN , peerID , repo.Message {Msg : m },
548
+ "" , 0 , []byte {})
549
+ if err != nil {
550
+ log .Errorf ("failed putting message (%s-%d): %v" , orderID0 , int (pb .Message_DISPUTE_OPEN ), err )
551
+ }
552
+ }
553
+
521
554
return n .sendMessage (peerID , k , m )
522
555
}
523
556
@@ -528,24 +561,58 @@ func (n *OpenBazaarNode) SendDisputeUpdate(peerID string, updateMessage *pb.Disp
528
561
log .Errorf ("failed to marshal the contract: %v" , err )
529
562
return err
530
563
}
564
+
565
+ // Create the DISPUTE_UPDATE message
531
566
m := pb.Message {
532
567
MessageType : pb .Message_DISPUTE_UPDATE ,
533
568
Payload : a ,
534
569
}
570
+
571
+ // Save DISPUTE_UPDATE message to the database for this order for resending if necessary
572
+ orderID0 := updateMessage .OrderId
573
+ if orderID0 == "" {
574
+ log .Errorf ("failed fetching orderID" )
575
+ } else {
576
+ err = n .Datastore .Messages ().Put (
577
+ fmt .Sprintf ("%s-%d" , orderID0 , int (pb .Message_DISPUTE_UPDATE )),
578
+ orderID0 , pb .Message_DISPUTE_UPDATE , peerID , repo.Message {Msg : m },
579
+ "" , 0 , []byte {})
580
+ if err != nil {
581
+ log .Errorf ("failed putting message (%s-%d): %v" , orderID0 , int (pb .Message_DISPUTE_UPDATE ), err )
582
+ }
583
+ }
584
+
535
585
return n .sendMessage (peerID , nil , m )
536
586
}
537
587
538
588
// SendDisputeClose - send dispute closed msg to peer
539
- func (n * OpenBazaarNode ) SendDisputeClose (peerID string , k * libp2p.PubKey , resolutionMessage * pb.RicardianContract ) error {
589
+ func (n * OpenBazaarNode ) SendDisputeClose (peerID string , k * libp2p.PubKey , resolutionMessage * pb.RicardianContract , orderID string ) error {
540
590
a , err := ptypes .MarshalAny (resolutionMessage )
541
591
if err != nil {
542
592
log .Errorf ("failed to marshal the contract: %v" , err )
543
593
return err
544
594
}
595
+
596
+ // Create the DISPUTE_CLOSE message
545
597
m := pb.Message {
546
598
MessageType : pb .Message_DISPUTE_CLOSE ,
547
599
Payload : a ,
548
600
}
601
+
602
+ // Save DISPUTE_CLOSE message to the database for this order for resending if necessary
603
+ orderID0 := orderID
604
+ if orderID0 == "" {
605
+ log .Errorf ("failed fetching orderID" )
606
+ } else {
607
+ err = n .Datastore .Messages ().Put (
608
+ fmt .Sprintf ("%s-%d" , orderID0 , int (pb .Message_DISPUTE_CLOSE )),
609
+ orderID0 , pb .Message_DISPUTE_CLOSE , peerID , repo.Message {Msg : m },
610
+ "" , 0 , []byte {})
611
+ if err != nil {
612
+ log .Errorf ("failed putting message (%s-%d): %v" , orderID0 , int (pb .Message_DISPUTE_CLOSE ), err )
613
+ }
614
+ }
615
+
549
616
return n .sendMessage (peerID , k , m )
550
617
}
551
618
@@ -804,6 +871,8 @@ func (n *OpenBazaarNode) SendOrderPayment(spend *SpendResponse) error {
804
871
if err != nil {
805
872
return err
806
873
}
874
+
875
+ // Create the ORDER_PAYMENT message
807
876
m := pb.Message {
808
877
MessageType : pb .Message_ORDER_PAYMENT ,
809
878
Payload : a ,
@@ -813,6 +882,21 @@ func (n *OpenBazaarNode) SendOrderPayment(spend *SpendResponse) error {
813
882
if err != nil {
814
883
return err
815
884
}
885
+
886
+ // Save ORDER_PAYMENT message to the database for this order for resending if necessary
887
+ orderID0 := msg .OrderID
888
+ if orderID0 == "" {
889
+ log .Errorf ("failed fetching orderID" )
890
+ } else {
891
+ err = n .Datastore .Messages ().Put (
892
+ fmt .Sprintf ("%s-%d" , orderID0 , int (pb .Message_ORDER_PAYMENT )),
893
+ orderID0 , pb .Message_ORDER_PAYMENT , spend .PeerID , repo.Message {Msg : m },
894
+ "" , 0 , []byte {})
895
+ if err != nil {
896
+ log .Errorf ("failed putting message (%s-%d): %v" , orderID0 , int (pb .Message_ORDER_PAYMENT ), err )
897
+ }
898
+ }
899
+
816
900
ctx , cancel := context .WithTimeout (context .Background (), n .OfflineMessageFailoverTimeout )
817
901
err = n .Service .SendMessage (ctx , p , & m )
818
902
cancel ()
0 commit comments