Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate AddWatchedAddress #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exchangerates/exchange_rates.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"sync"
"time"

"strings"

exchange "github.com/OpenBazaar/spvwallet/exchangerates"
"golang.org/x/net/proxy"
"strings"
)

type ExchangeRateProvider struct {
Expand Down
7 changes: 4 additions & 3 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package zcashd

import (
"encoding/json"
"io/ioutil"
"net/http"
"time"

"github.com/OpenBazaar/wallet-interface"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
btcrpcclient "github.com/btcsuite/btcd/rpcclient"
"io/ioutil"
"net/http"
"time"
)

type NotificationListener struct {
Expand Down
58 changes: 41 additions & 17 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
"path"
"runtime"
"strconv"
"strings"
"time"

"github.com/OpenBazaar/bitcoind-wallet"
"github.com/OpenBazaar/spvwallet"
"github.com/OpenBazaar/wallet-interface"
Expand All @@ -27,13 +35,6 @@ import (
"github.com/op/go-logging"
b39 "github.com/tyler-smith/go-bip39"
"golang.org/x/net/proxy"
"os"
"os/exec"
"path"
"runtime"
"strconv"
"strings"
"time"
)

var log = logging.MustGetLogger("zcashd")
Expand Down Expand Up @@ -475,6 +476,32 @@ func (w *ZcashdWallet) GetTransaction(txid chainhash.Hash) (wallet.Txn, error) {
t.Height = int32(resp.BlockIndex)
t.Timestamp = time.Unix(resp.TimeReceived, 0)
t.WatchOnly = false

tx := wire.NewMsgTx(1)
rbuf := bytes.NewReader([]byte(resp.Hex))
err = tx.BtcDecode(rbuf, wire.ProtocolVersion, wire.WitnessEncoding)
if err != nil {
return t, err
}
outs := []wallet.TransactionOutput{}
for i, out := range tx.TxOut {
var addr btc.Address
_, addrs, _, err := txscript.ExtractPkScriptAddrs(out.PkScript, w.params)
if err != nil {
log.Warningf("error extracting address from txn pkscript: %v\n", err)
}
if len(addrs) != 0 {
addr = addrs[0]
}
tout := wallet.TransactionOutput{
Address: addr,
Value: out.Value,
Index: uint32(i),
}
outs = append(outs, tout)
}
t.Outputs = outs

return t, nil
}

Expand Down Expand Up @@ -1030,16 +1057,6 @@ func (w *ZcashdWallet) GenerateMultisigScript(keys []hd.ExtendedKey, threshold i
return addr, redeemScript, nil
}

func (w *ZcashdWallet) AddWatchedAddress(addr btc.Address) error {
select {
case <-w.initChan:
return w.addWatchedScript(addr)
default:
w.addrsToWatch = append(w.addrsToWatch, addr)
}
return nil
}

func (w *ZcashdWallet) addWatchedScript(addr btc.Address) error {
a := `"` + addr.EncodeAddress() + `"`
_, err := w.rpcClient.RawRequest("importaddress", []json.RawMessage{json.RawMessage(a), json.RawMessage(`""`), json.RawMessage(`false`)})
Expand Down Expand Up @@ -1071,3 +1088,10 @@ func (w *ZcashdWallet) Close() {
func (w *ZcashdWallet) ExchangeRates() wallet.ExchangeRates {
return w.exchangeRates
}

// AssociateTransactionWithOrder used for ORDER_PAYMENT message
func (w *ZcashdWallet) AssociateTransactionWithOrder(txnCB wallet.TransactionCallback) {
for _, l := range w.listeners {
go l(txnCB)
}
}