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

Commit

Permalink
Checking more closely on order payment msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmabc committed Aug 4, 2020
1 parent ebc9f72 commit 07ad745
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
11 changes: 9 additions & 2 deletions core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,17 @@ func (n *OpenBazaarNode) BuildTransactionRecords(contract *pb.RicardianContract,
refundRecord = new(pb.TransactionRecord)
// Direct we need to use the transaction info in the contract's refund object
ch, err := chainhash.NewHashFromStr(strings.TrimPrefix(contract.Refund.RefundTransaction.Txid, "0x"))
var txid string
if err != nil {
return paymentRecords, refundRecord, err
if strings.HasPrefix(contract.Refund.RefundTransaction.Txid, "bafy") {
txid = contract.Refund.RefundTransaction.Txid
} else {
return paymentRecords, refundRecord, err
}
} else {
txid = ch.String()
}
confirmations, height, err := wal.GetConfirmations(ch.String())
confirmations, height, err := wal.GetConfirmations(txid)
if err != nil {
return paymentRecords, refundRecord, nil
}
Expand Down
27 changes: 24 additions & 3 deletions net/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1990,12 +1990,26 @@ func (service *OpenBazaarService) handleOrderPayment(peer peer.ID, pmes *pb.Mess
}

chash, err := chainhash.NewHashFromStr(paymentDetails.GetTransactionID())
var txid string
if err != nil {
return nil, err
if _, ok := cid.Decode(paymentDetails.TransactionID); ok == nil {
txid = paymentDetails.TransactionID
} else {
return nil, err
}
} else {
txid = chash.String()
}

log.Debugf("retrieving %s transaction %s", paymentDetails.Coin, chash.String())
txn, err := wal.GetTransaction(chash.String())
log.Debugf("retrieving %s transaction %s", paymentDetails.Coin, txid)
var txn wallet.Txn
for i := 0; i<10; i++ {
txn, err = wal.GetTransaction(txid)
if err == nil {
break;
}
time.Sleep(time.Second*2)
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2059,6 +2073,13 @@ func (service *OpenBazaarService) handleOrderPayment(peer peer.ID, pmes *pb.Mess
}
}

if toAddress.String() == "" {
toAddress, err = wal.DecodeAddress(txn.ToAddress)
if err != nil {
log.Error(err)
}
}

outputs := []wallet.TransactionOutput{}
for _, o := range txn.Outputs {
output := wallet.TransactionOutput{
Expand Down

0 comments on commit 07ad745

Please sign in to comment.