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

Changes required for ORDER_PAYMENT network message #3

Open
wants to merge 2 commits 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
1 change: 1 addition & 0 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"crypto/sha256"
"fmt"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcutil"
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
48 changes: 41 additions & 7 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]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addr is already nil.

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 @@ -1071,3 +1098,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)
}
}