5
5
"encoding/hex"
6
6
"errors"
7
7
"fmt"
8
+ "github.com/OpenBazaar/openbazaar-go/repo"
8
9
"math/big"
9
10
"strings"
10
11
"time"
@@ -28,7 +29,12 @@ func (n *OpenBazaarNode) NewOrderConfirmation(contract *pb.RicardianContract, ad
28
29
}
29
30
oc .OrderID = orderID
30
31
31
- wal , err := n .Multiwallet .WalletForCurrencyCode (contract .BuyerOrder .Payment .AmountCurrency .Code )
32
+ order , err := repo .ToV5Order (contract .BuyerOrder , n .LookupCurrency )
33
+ if err != nil {
34
+ return nil , err
35
+ }
36
+
37
+ wal , err := n .Multiwallet .WalletForCurrencyCode (order .Payment .AmountCurrency .Code )
32
38
if err != nil {
33
39
return nil , err
34
40
}
@@ -45,13 +51,13 @@ func (n *OpenBazaarNode) NewOrderConfirmation(contract *pb.RicardianContract, ad
45
51
oc .Timestamp = ts
46
52
47
53
oc .RatingSignatures = []* pb.RatingSignature {}
48
- if contract . BuyerOrder .Payment .Method == pb .Order_Payment_MODERATED {
54
+ if order .Payment .Method == pb .Order_Payment_MODERATED {
49
55
for _ , listing := range contract .VendorListings {
50
56
metadata := new (pb.RatingSignature_TransactionMetadata )
51
57
metadata .ListingSlug = listing .Slug
52
- metadata .ModeratorKey = contract . BuyerOrder .Payment .ModeratorKey
58
+ metadata .ModeratorKey = order .Payment .ModeratorKey
53
59
54
- if contract . BuyerOrder .Version > 0 {
60
+ if order .Version > 0 {
55
61
metadata .ListingTitle = listing .Item .Title
56
62
if len (listing .Item .Images ) > 0 {
57
63
metadata .Thumbnail = & pb.RatingSignature_TransactionMetadata_Image {
@@ -79,10 +85,10 @@ func (n *OpenBazaarNode) NewOrderConfirmation(contract *pb.RicardianContract, ad
79
85
80
86
oc .RatingSignatures = append (oc .RatingSignatures , rs )
81
87
}
82
- oc .PaymentAddress = contract . BuyerOrder .Payment .Address
88
+ oc .PaymentAddress = order .Payment .Address
83
89
}
84
90
85
- oc .BigRequestedAmount = contract . BuyerOrder .Payment .BigAmount
91
+ oc .BigRequestedAmount = order .Payment .BigAmount
86
92
contract .VendorOrderConfirmation = oc
87
93
contract , err = n .SignOrderConfirmation (contract )
88
94
if err != nil {
@@ -190,12 +196,16 @@ func (n *OpenBazaarNode) RejectOfflineOrder(contract *pb.RicardianContract, reco
190
196
if err != nil {
191
197
return fmt .Errorf ("marshal timestamp: %s" , err .Error ())
192
198
}
193
- wal , err := n .Multiwallet .WalletForCurrencyCode (contract .BuyerOrder .Payment .AmountCurrency .Code )
199
+ order , err := repo .ToV5Order (contract .BuyerOrder , n .LookupCurrency )
200
+ if err != nil {
201
+ return err
202
+ }
203
+ wal , err := n .Multiwallet .WalletForCurrencyCode (order .Payment .AmountCurrency .Code )
194
204
if err != nil {
195
205
return err
196
206
}
197
207
rejectMsg .Timestamp = ts
198
- if contract . BuyerOrder .Payment .Method == pb .Order_Payment_MODERATED {
208
+ if order .Payment .Method == pb .Order_Payment_MODERATED {
199
209
var ins []wallet.TransactionInput
200
210
outValue := * big .NewInt (0 )
201
211
for _ , r := range records {
@@ -219,7 +229,7 @@ func (n *OpenBazaarNode) RejectOfflineOrder(contract *pb.RicardianContract, reco
219
229
}
220
230
}
221
231
222
- refundAddress , err := wal .DecodeAddress (contract . BuyerOrder .RefundAddress )
232
+ refundAddress , err := wal .DecodeAddress (order .RefundAddress )
223
233
if err != nil {
224
234
return fmt .Errorf ("decode refund address: %s" , err .Error ())
225
235
}
@@ -228,7 +238,7 @@ func (n *OpenBazaarNode) RejectOfflineOrder(contract *pb.RicardianContract, reco
228
238
Value : outValue ,
229
239
}
230
240
231
- chaincode , err := hex .DecodeString (contract . BuyerOrder .Payment .Chaincode )
241
+ chaincode , err := hex .DecodeString (order .Payment .Chaincode )
232
242
if err != nil {
233
243
return fmt .Errorf ("decode buyer chaincode: %s" , err .Error ())
234
244
}
@@ -240,11 +250,11 @@ func (n *OpenBazaarNode) RejectOfflineOrder(contract *pb.RicardianContract, reco
240
250
if err != nil {
241
251
return fmt .Errorf ("generate child key: %s" , err .Error ())
242
252
}
243
- redeemScript , err := hex .DecodeString (contract . BuyerOrder .Payment .RedeemScript )
253
+ redeemScript , err := hex .DecodeString (order .Payment .RedeemScript )
244
254
if err != nil {
245
255
return fmt .Errorf ("generate child key: %s" , err .Error ())
246
256
}
247
- fee , ok := new (big.Int ).SetString (contract . BuyerOrder .BigRefundFee , 10 )
257
+ fee , ok := new (big.Int ).SetString (order .BigRefundFee , 10 )
248
258
if ! ok {
249
259
return errors .New ("invalid refund fee value" )
250
260
}
@@ -259,7 +269,7 @@ func (n *OpenBazaarNode) RejectOfflineOrder(contract *pb.RicardianContract, reco
259
269
}
260
270
rejectMsg .Sigs = sigs
261
271
}
262
- err = n .SendReject (contract . BuyerOrder .BuyerID .PeerID , rejectMsg )
272
+ err = n .SendReject (order .BuyerID .PeerID , rejectMsg )
263
273
if err != nil {
264
274
return fmt .Errorf ("sending rejection: %s" , err .Error ())
265
275
}
@@ -275,18 +285,24 @@ func (n *OpenBazaarNode) ValidateOrderConfirmation(contract *pb.RicardianContrac
275
285
if err != nil {
276
286
return err
277
287
}
278
- if contract .VendorOrderConfirmation .OrderID != orderID {
288
+
289
+ orderConfirmation := repo .ToV5OrderConfirmation (contract .VendorOrderConfirmation )
290
+
291
+ order , err := repo .ToV5Order (contract .BuyerOrder , n .LookupCurrency )
292
+ if err != nil {
293
+ return err
294
+ }
295
+ if orderConfirmation .OrderID != orderID {
279
296
return errors .New ("vendor's response contained invalid order ID" )
280
297
}
281
- if contract .VendorOrderConfirmation .BigRequestedAmount != contract .BuyerOrder .Payment .BigAmount {
282
- return fmt .Errorf ("vendor requested an amount different from what we calculated: want %s, got %s" ,
283
- contract .BuyerOrder .Payment .BigAmount , contract .VendorOrderConfirmation .BigRequestedAmount )
298
+ if orderConfirmation .BigRequestedAmount != order .Payment .BigAmount {
299
+ return errors .New ("vendor requested an amount different from what we calculated" )
284
300
}
285
- wal , err := n .Multiwallet .WalletForCurrencyCode (contract . BuyerOrder .Payment .AmountCurrency .Code )
301
+ wal , err := n .Multiwallet .WalletForCurrencyCode (order .Payment .AmountCurrency .Code )
286
302
if err != nil {
287
303
return err
288
304
}
289
- if contract . BuyerOrder .Payment .Method == pb .Order_Payment_MODERATED {
305
+ if order .Payment .Method == pb .Order_Payment_MODERATED {
290
306
for _ , sig := range contract .VendorOrderConfirmation .RatingSignatures {
291
307
exists := false
292
308
for _ , listing := range contract .VendorListings {
@@ -303,7 +319,7 @@ func (n *OpenBazaarNode) ValidateOrderConfirmation(contract *pb.RicardianContrac
303
319
return err
304
320
}
305
321
306
- if ! bytes .Equal (sig .Metadata .ModeratorKey , contract . BuyerOrder .Payment .ModeratorKey ) {
322
+ if ! bytes .Equal (sig .Metadata .ModeratorKey , order .Payment .ModeratorKey ) {
307
323
return errors .New ("rating signature does not contain moderatory key" )
308
324
}
309
325
ser , err := proto .Marshal (sig .Metadata )
0 commit comments