diff --git a/vendor/github.com/OpenBazaar/go-ethwallet/wallet/wallet.go b/vendor/github.com/OpenBazaar/go-ethwallet/wallet/wallet.go index 09e5029a04..a95db5d5d3 100644 --- a/vendor/github.com/OpenBazaar/go-ethwallet/wallet/wallet.go +++ b/vendor/github.com/OpenBazaar/go-ethwallet/wallet/wallet.go @@ -519,16 +519,22 @@ func (wallet *EthereumWallet) Balance() (confirmed, unconfirmed wi.CurrencyValue // TransactionsFromBlock - Returns a list of transactions for this wallet begining from the specified block func (wallet *EthereumWallet) TransactionsFromBlock(startBlock *int) ([]wi.Txn, error) { + ret := []wi.Txn{} + + unconf, _ := wallet.db.Txns().GetAll(false) + txns, err := wallet.client.eClient.NormalTxByAddress(util.EnsureCorrectPrefix(wallet.account.Address().String()), startBlock, nil, 1, 0, false) - if err != nil { + if err != nil && len(unconf) == 0 { log.Error("err fetching transactions : ", err) return []wi.Txn{}, nil } - ret := []wi.Txn{} for _, t := range txns { status := wi.StatusConfirmed + if t.Confirmations > 1 && t.Confirmations <= 7 { + status = wi.StatusPending + } prefix := "" if t.IsError != 0 { status = wi.StatusError @@ -549,6 +555,11 @@ func (wallet *EthereumWallet) TransactionsFromBlock(startBlock *int) ([]wi.Txn, ret = append(ret, tnew) } + for _, u := range unconf { + u.Status = wi.StatusUnconfirmed + ret = append(ret, u) + } + return ret, nil } @@ -653,15 +664,20 @@ func (wallet *EthereumWallet) GetFeePerByte(feeLevel wi.FeeLevel) big.Int { // Spend - Send ether to an external wallet func (wallet *EthereumWallet) Spend(amount big.Int, addr btcutil.Address, feeLevel wi.FeeLevel, referenceID string, spendAll bool) (*chainhash.Hash, error) { - var hash common.Hash - var h *chainhash.Hash - var err error + var ( + hash common.Hash + h *chainhash.Hash + watchOnly bool + nonce int32 + err error + ) actualRecipient := addr if referenceID == "" { // no referenceID means this is a direct transfer hash, err = wallet.Transfer(util.EnsureCorrectPrefix(addr.String()), &amount, spendAll, wallet.GetFeePerByte(feeLevel)) } else { + watchOnly = true // this is a spend which means it has to be linked to an order // specified using the referenceID @@ -710,36 +726,36 @@ func (wallet *EthereumWallet) Spend(amount big.Int, addr btcutil.Address, feeLev } // txn is pending - nonce, err := wallet.client.GetTxnNonce(util.EnsureCorrectPrefix(hash.Hex())) - if err == nil { - data, err := SerializePendingTxn(PendingTxn{ - TxnID: hash, - Amount: amount.String(), - OrderID: referenceID, - Nonce: nonce, - From: wallet.address.EncodeAddress(), - To: actualRecipient.EncodeAddress(), - WithInput: false, - }) - if err == nil { - err0 := wallet.db.Txns().Put(data, ut.NormalizeAddress(hash.Hex()), "0", 0, time.Now(), true) - if err0 != nil { - log.Error(err0.Error()) - } - } + nonce, err = wallet.client.GetTxnNonce(util.EnsureCorrectPrefix(hash.Hex())) + if err != nil { + return nil, err } } - if err == nil { h, err = util.CreateChainHash(hash.Hex()) if err == nil { wallet.invokeTxnCB(h.String(), &amount) } } - return h, err + data, err := SerializePendingTxn(PendingTxn{ + TxnID: hash, + Amount: amount.String(), + OrderID: referenceID, + Nonce: nonce, + From: wallet.address.EncodeAddress(), + To: actualRecipient.EncodeAddress(), + WithInput: false, + }) + if err == nil { + err0 := wallet.db.Txns().Put(data, ut.NormalizeAddress(hash.Hex()), amount.String(), 0, time.Now(), watchOnly) + if err0 != nil { + log.Error(err0.Error()) + } + } + return h, nil } -func (wallet *EthereumWallet) createTxnCallback(txID, orderID string, toAddress btcutil.Address, value big.Int, bTime time.Time, withInput bool) wi.TransactionCallback { +func (wallet *EthereumWallet) createTxnCallback(txID, orderID string, toAddress btcutil.Address, value big.Int, bTime time.Time, withInput bool, height int64) wi.TransactionCallback { output := wi.TransactionOutput{ Address: toAddress, Value: value, @@ -759,12 +775,11 @@ func (wallet *EthereumWallet) createTxnCallback(txID, orderID string, toAddress } } - return wi.TransactionCallback{ Txid: util.EnsureCorrectPrefix(txID), Outputs: []wi.TransactionOutput{output}, Inputs: []wi.TransactionInput{input}, - Height: 1, + Height: int32(height), Timestamp: time.Now(), Value: value, WatchOnly: false, @@ -812,9 +827,10 @@ func (wallet *EthereumWallet) checkTxnRcpt(hash *common.Hash, data []byte) (*com toAddr = common.HexToAddress(util.EnsureCorrectPrefix(pTxn.To)) withInput = pTxn.WithInput } + height := rcpt.BlockNumber.Int64() go wallet.AssociateTransactionWithOrder( wallet.createTxnCallback(util.EnsureCorrectPrefix(hash.Hex()), pTxn.OrderID, EthAddress{&toAddr}, - *n, time.Now(), withInput)) + *n, time.Now(), withInput, height)) } } return hash, nil