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

Commit 1380f95

Browse files
committed
Checking more closely on order payment msgs
1 parent 668fc00 commit 1380f95

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

core/utils.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,17 @@ func (n *OpenBazaarNode) BuildTransactionRecords(contract *pb.RicardianContract,
8787
refundRecord = new(pb.TransactionRecord)
8888
// Direct we need to use the transaction info in the contract's refund object
8989
ch, err := chainhash.NewHashFromStr(strings.TrimPrefix(contract.Refund.RefundTransaction.Txid, "0x"))
90+
var txid string
9091
if err != nil {
91-
return paymentRecords, refundRecord, err
92+
if strings.HasPrefix(contract.Refund.RefundTransaction.Txid, "bafy") {
93+
txid = contract.Refund.RefundTransaction.Txid
94+
} else {
95+
return paymentRecords, refundRecord, err
96+
}
97+
} else {
98+
txid = ch.String()
9299
}
93-
confirmations, height, err := wal.GetConfirmations(ch.String())
100+
confirmations, height, err := wal.GetConfirmations(txid)
94101
if err != nil {
95102
return paymentRecords, refundRecord, nil
96103
}

net/service/handlers.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -1990,12 +1990,26 @@ func (service *OpenBazaarService) handleOrderPayment(peer peer.ID, pmes *pb.Mess
19901990
}
19911991

19921992
chash, err := chainhash.NewHashFromStr(paymentDetails.GetTransactionID())
1993+
var txid string
19931994
if err != nil {
1994-
return nil, err
1995+
if _, ok := cid.Decode(paymentDetails.TransactionID); ok == nil {
1996+
txid = paymentDetails.TransactionID
1997+
} else {
1998+
return nil, err
1999+
}
2000+
} else {
2001+
txid = chash.String()
19952002
}
19962003

1997-
log.Debugf("retrieving %s transaction %s", paymentDetails.Coin, chash.String())
1998-
txn, err := wal.GetTransaction(chash.String())
2004+
log.Debugf("retrieving %s transaction %s", paymentDetails.Coin, txid)
2005+
var txn wallet.Txn
2006+
for i := 0; i<10; i++ {
2007+
txn, err = wal.GetTransaction(txid)
2008+
if err == nil {
2009+
break;
2010+
}
2011+
time.Sleep(time.Second*2)
2012+
}
19992013
if err != nil {
20002014
return nil, err
20012015
}
@@ -2059,6 +2073,13 @@ func (service *OpenBazaarService) handleOrderPayment(peer peer.ID, pmes *pb.Mess
20592073
}
20602074
}
20612075

2076+
if toAddress.String() == "" {
2077+
toAddress, err = wal.DecodeAddress(txn.ToAddress)
2078+
if err != nil {
2079+
log.Error(err)
2080+
}
2081+
}
2082+
20622083
outputs := []wallet.TransactionOutput{}
20632084
for _, o := range txn.Outputs {
20642085
output := wallet.TransactionOutput{

0 commit comments

Comments
 (0)