Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 12c273f

Browse files
committed
Fix bug confirming offline order
The point of confirming an offline order is to just accept whatever amount is offered in the order. However, the code was re-calculating the order total causing the vendor to reject the order in some instances.
1 parent 2f766b9 commit 12c273f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

core/confirmation.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/golang/protobuf/ptypes"
1818
)
1919

20-
func (n *OpenBazaarNode) NewOrderConfirmation(contract *pb.RicardianContract, addressRequest bool) (*pb.RicardianContract, error) {
20+
func (n *OpenBazaarNode) NewOrderConfirmation(contract *pb.RicardianContract, addressRequest, calculateNewTotal bool) (*pb.RicardianContract, error) {
2121
oc := new(pb.OrderConfirmation)
2222
// Calculate order ID
2323
orderID, err := n.CalcOrderId(contract.BuyerOrder)
@@ -61,9 +61,13 @@ func (n *OpenBazaarNode) NewOrderConfirmation(contract *pb.RicardianContract, ad
6161
oc.PaymentAddress = contract.BuyerOrder.Payment.Address
6262
}
6363

64-
oc.RequestedAmount, err = n.CalculateOrderTotal(contract)
65-
if err != nil {
66-
return nil, err
64+
if calculateNewTotal {
65+
oc.RequestedAmount, err = n.CalculateOrderTotal(contract)
66+
if err != nil {
67+
return nil, err
68+
}
69+
} else {
70+
oc.RequestedAmount = contract.BuyerOrder.Payment.Amount
6771
}
6872
contract.VendorOrderConfirmation = oc
6973
contract, err = n.SignOrderConfirmation(contract)
@@ -74,7 +78,7 @@ func (n *OpenBazaarNode) NewOrderConfirmation(contract *pb.RicardianContract, ad
7478
}
7579

7680
func (n *OpenBazaarNode) ConfirmOfflineOrder(contract *pb.RicardianContract, records []*wallet.TransactionRecord) error {
77-
contract, err := n.NewOrderConfirmation(contract, false)
81+
contract, err := n.NewOrderConfirmation(contract, false, false)
7882
if err != nil {
7983
return err
8084
}

net/service/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (service *OpenBazaarService) handleOrder(peer peer.ID, pmes *pb.Message, op
272272
log.Error("Calculated a different payment amount")
273273
return errorResponse("Calculated a different payment amount"), nil
274274
}
275-
contract, err = service.node.NewOrderConfirmation(contract, true)
275+
contract, err = service.node.NewOrderConfirmation(contract, true, true)
276276
if err != nil {
277277
log.Error(err)
278278
return errorResponse("Error building order confirmation"), nil
@@ -345,7 +345,7 @@ func (service *OpenBazaarService) handleOrder(peer peer.ID, pmes *pb.Message, op
345345
return errorResponse(err.Error()), err
346346
}
347347
service.node.Wallet.AddWatchedScript(script)
348-
contract, err = service.node.NewOrderConfirmation(contract, false)
348+
contract, err = service.node.NewOrderConfirmation(contract, false, true)
349349
if err != nil {
350350
log.Error(err)
351351
return errorResponse("Error building order confirmation"), nil

0 commit comments

Comments
 (0)