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

multi: Update to latest dcrd/dcrwallet dev modules #953

Merged
merged 6 commits into from
May 13, 2021
Merged
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
2 changes: 1 addition & 1 deletion client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/decred/dcrd/rpcclient/v6"
"github.com/decred/dcrd/rpcclient/v7"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion client/asset/dcr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"decred.org/dcrdex/dex"
"decred.org/dcrdex/dex/config"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrutil/v3"
"github.com/decred/dcrd/dcrutil/v4"
)

const (
Expand Down
62 changes: 32 additions & 30 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ import (
"decred.org/dcrdex/dex"
"decred.org/dcrdex/dex/calc"
dexdcr "decred.org/dcrdex/dex/networks/dcr"
"decred.org/dcrwallet/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/rpc/jsonrpc/types"
"decred.org/dcrwallet/v2/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/v2/rpc/jsonrpc/types"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrec"
"github.com/decred/dcrd/dcrec/secp256k1/v3"
"github.com/decred/dcrd/dcrec/secp256k1/v3/ecdsa"
"github.com/decred/dcrd/dcrjson/v3"
"github.com/decred/dcrd/dcrutil/v3"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/rpcclient/v6"
"github.com/decred/dcrd/txscript/v3"
"github.com/decred/dcrd/dcrutil/v4"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v3"
"github.com/decred/dcrd/rpcclient/v7"
"github.com/decred/dcrd/txscript/v4"
"github.com/decred/dcrd/wire"
)

Expand Down Expand Up @@ -69,7 +69,7 @@ const (

var (
requiredWalletVersion = dex.Semver{Major: 8, Minor: 5, Patch: 0}
requiredNodeVersion = dex.Semver{Major: 6, Minor: 1, Patch: 2}
requiredNodeVersion = dex.Semver{Major: 7, Minor: 0, Patch: 0}
)

var (
Expand Down Expand Up @@ -153,10 +153,10 @@ var (

// rpcClient is an rpcclient.Client, or a stub for testing.
type rpcClient interface {
EstimateSmartFee(ctx context.Context, confirmations int64, mode chainjson.EstimateSmartFeeMode) (float64, error)
EstimateSmartFee(ctx context.Context, confirmations int64, mode chainjson.EstimateSmartFeeMode) (*chainjson.EstimateSmartFeeResult, error)
GetBlockChainInfo(ctx context.Context) (*chainjson.GetBlockChainInfoResult, error)
SendRawTransaction(ctx context.Context, tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error)
GetTxOut(ctx context.Context, txHash *chainhash.Hash, index uint32, mempool bool) (*chainjson.GetTxOutResult, error)
GetTxOut(ctx context.Context, txHash *chainhash.Hash, index uint32, tree int8, mempool bool) (*chainjson.GetTxOutResult, error)
GetBalanceMinConf(ctx context.Context, account string, minConfirms int) (*walletjson.GetBalanceResult, error)
GetBestBlock(ctx context.Context) (*chainhash.Hash, int64, error)
GetBlockHash(ctx context.Context, blockHeight int64) (*chainhash.Hash, error)
Expand Down Expand Up @@ -700,11 +700,11 @@ func (dcr *ExchangeWallet) feeRate(confTarget uint64) (uint64, error) {
if confTarget < 2 {
confTarget = 2
}
dcrPerKB, err := dcr.node.EstimateSmartFee(dcr.ctx, int64(confTarget), chainjson.EstimateSmartFeeConservative)
estimateFeeResult, err := dcr.node.EstimateSmartFee(dcr.ctx, int64(confTarget), chainjson.EstimateSmartFeeConservative)
if err != nil {
return 0, translateRPCCancelErr(err)
}
atomsPerKB, err := dcrutil.NewAmount(dcrPerKB) // satPerKB is 0 when err != nil
atomsPerKB, err := dcrutil.NewAmount(estimateFeeResult.FeeRate) // atomsPerKB is 0 when err != nil
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -1272,7 +1272,7 @@ func (dcr *ExchangeWallet) FundingCoins(ids []dex.Bytes) (asset.Coins, error) {
if !notFound[pt] {
continue
}
txOut, err := dcr.node.GetTxOut(dcr.ctx, txHash, output.Vout, true)
txOut, err := dcr.node.GetTxOut(dcr.ctx, txHash, output.Vout, output.Tree, true)
if err != nil {
return nil, fmt.Errorf("gettxout error for locked output %v: %w", pt.String(), translateRPCCancelErr(err))
}
Expand Down Expand Up @@ -1541,7 +1541,7 @@ func (dcr *ExchangeWallet) SignMessage(coin asset.Coin, msg dex.Bytes) (pubkeys,
addr = fCoin.addr
} else {
// Check if we can get the address from gettxout.
txOut, err := dcr.node.GetTxOut(dcr.ctx, op.txHash(), op.vout(), true)
txOut, err := dcr.node.GetTxOut(dcr.ctx, op.txHash(), op.vout(), op.tree, true)
if err == nil && txOut != nil {
addrs := txOut.ScriptPubKey.Addresses
if len(addrs) != 1 {
Expand Down Expand Up @@ -1589,7 +1589,7 @@ func (dcr *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes) (*a
return nil, fmt.Errorf("error extracting swap addresses: %w", err)
}
// Get the contracts P2SH address from the tx output's pubkey script.
txOut, err := dcr.node.GetTxOut(dcr.ctx, txHash, vout, true)
txOut, txTree, err := dcr.getTxOut(txHash, vout, true)
if err != nil {
return nil, fmt.Errorf("error finding unspent contract: %w", translateRPCCancelErr(err))
}
Expand Down Expand Up @@ -1623,7 +1623,7 @@ func (dcr *ExchangeWallet) AuditContract(coinID, contract, txData dex.Bytes) (*a
contractHash, addr.ScriptAddress())
}
return &asset.AuditInfo{
Coin: newOutput(txHash, vout, toAtoms(txOut.Value), wire.TxTreeRegular),
Coin: newOutput(txHash, vout, toAtoms(txOut.Value), txTree),
Contract: contract,
SecretHash: secretHash,
Recipient: receiver.String(),
Expand Down Expand Up @@ -2035,7 +2035,7 @@ func (dcr *ExchangeWallet) Refund(coinID, contract dex.Bytes) (dex.Bytes, error)
return nil, err
}
// Grab the unspent output to make sure it's good and to get the value.
utxo, err := dcr.node.GetTxOut(dcr.ctx, txHash, vout, true)
utxo, err := dcr.node.GetTxOut(dcr.ctx, txHash, vout, wire.TxTreeRegular, true)
if err != nil {
return nil, fmt.Errorf("error finding unspent contract: %w", translateRPCCancelErr(err))
}
Expand Down Expand Up @@ -2237,15 +2237,12 @@ func (dcr *ExchangeWallet) ValidateSecret(secret, secretHash []byte) bool {
// first checking for a unspent output, and if not found, searching indexed
// wallet transactions.
func (dcr *ExchangeWallet) Confirmations(ctx context.Context, id dex.Bytes) (confs uint32, spent bool, err error) {
// Could check with gettransaction first, figure out the tree, and look for a
// redeem script with listscripts, but the listunspent entry has all the
// necessary fields already.
Comment on lines -2240 to -2242
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this is an outdated comment? Don't see a need for redeem script in this method.

txHash, vout, err := decodeCoinID(id)
if err != nil {
return 0, false, err
}
// Check for an unspent output.
txOut, err := dcr.node.GetTxOut(ctx, txHash, vout, true)
txOut, _, err := dcr.getTxOut(txHash, vout, true)
if err == nil && txOut != nil {
return uint32(txOut.Confirmations), false, nil
}
Expand Down Expand Up @@ -2378,6 +2375,19 @@ func (dcr *ExchangeWallet) lockedAtoms() (uint64, error) {
return sum, nil
}

// getTxOut attempts to find the specified txout from the regular tree and if
// not found in the regular tree, checks the stake tree. Also returns the tree
// where the output is found.
func (dcr *ExchangeWallet) getTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*chainjson.GetTxOutResult, int8, error) {
tree := wire.TxTreeRegular
txout, err := dcr.node.GetTxOut(dcr.ctx, txHash, index, tree, mempool) // check regular tree first
if err == nil && txout == nil {
tree = wire.TxTreeStake
txout, err = dcr.node.GetTxOut(dcr.ctx, txHash, index, tree, mempool) // check stake tree
}
return txout, tree, err
}

// convertCoin converts the asset.Coin to an unspent output.
func (dcr *ExchangeWallet) convertCoin(coin asset.Coin) (*output, error) {
op, _ := coin.(*output)
Expand All @@ -2388,20 +2398,12 @@ func (dcr *ExchangeWallet) convertCoin(coin asset.Coin) (*output, error) {
if err != nil {
return nil, err
}
txOut, err := dcr.node.GetTxOut(dcr.ctx, txHash, vout, true)
txOut, tree, err := dcr.getTxOut(txHash, vout, true)
if err != nil {
return nil, fmt.Errorf("error finding unspent output %s:%d: %w", txHash, vout, translateRPCCancelErr(err))
}
if txOut == nil {
return nil, asset.CoinNotFoundError
}
pkScript, err := hex.DecodeString(txOut.ScriptPubKey.Hex)
if err != nil {
return nil, err
}
tree := wire.TxTreeRegular
if dexdcr.IsStakePubkeyHashScript(pkScript) || dexdcr.IsStakeScriptHashScript(pkScript) {
tree = wire.TxTreeStake
return nil, asset.CoinNotFoundError // maybe spent
}
return newOutput(txHash, vout, coin.Value(), tree), nil
}
Expand Down
20 changes: 10 additions & 10 deletions client/asset/dcr/dcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import (
"decred.org/dcrdex/dex"
"decred.org/dcrdex/dex/calc"
dexdcr "decred.org/dcrdex/dex/networks/dcr"
"decred.org/dcrwallet/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/rpc/jsonrpc/types"
"decred.org/dcrwallet/v2/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/v2/rpc/jsonrpc/types"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrec"
"github.com/decred/dcrd/dcrec/secp256k1/v3"
"github.com/decred/dcrd/dcrec/secp256k1/v3/ecdsa"
"github.com/decred/dcrd/dcrutil/v3"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v2"
"github.com/decred/dcrd/txscript/v3"
"github.com/decred/dcrd/dcrutil/v4"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v3"
"github.com/decred/dcrd/txscript/v4"
"github.com/decred/dcrd/wire"
)

Expand Down Expand Up @@ -246,13 +246,13 @@ func newTRPCClient() *tRPCClient {
}
}

func (c *tRPCClient) EstimateSmartFee(_ context.Context, confirmations int64, mode chainjson.EstimateSmartFeeMode) (float64, error) {
func (c *tRPCClient) EstimateSmartFee(_ context.Context, confirmations int64, mode chainjson.EstimateSmartFeeMode) (*chainjson.EstimateSmartFeeResult, error) {
if c.estFeeErr != nil {
return 0, c.estFeeErr
return nil, c.estFeeErr
}
optimalRate := float64(optimalFeeRate) * 1e-5
optimalRate := float64(optimalFeeRate) * 1e-5 // optimalFeeRate: 22 atoms/byte = 0.00022 DCR/KB * 1e8 atoms/DCR * 1e-3 KB/Byte
// fmt.Println((float64(optimalFeeRate)*1e-5)-0.00022)
return optimalRate, nil // optimalFeeRate: 22 atoms/byte = 0.00022 DCR/KB * 1e8 atoms/DCR * 1e-3 KB/Byte
return &chainjson.EstimateSmartFeeResult{FeeRate: optimalRate}, nil
}

func (c *tRPCClient) GetBlockChainInfo(_ context.Context) (*chainjson.GetBlockChainInfoResult, error) {
Expand All @@ -268,7 +268,7 @@ func (c *tRPCClient) SendRawTransaction(_ context.Context, tx *wire.MsgTx, allow
return c.sendRawHash, c.sendRawErr
}

func (c *tRPCClient) GetTxOut(_ context.Context, txHash *chainhash.Hash, vout uint32, mempool bool) (*chainjson.GetTxOutResult, error) {
func (c *tRPCClient) GetTxOut(_ context.Context, txHash *chainhash.Hash, vout uint32, tree int8, mempool bool) (*chainjson.GetTxOutResult, error) {
return c.txOutRes[newOutPoint(txHash, vout)], c.txOutErr
}

Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"decred.org/dcrdex/client/cmd/dexc/version"
"decred.org/dcrdex/dex"
"github.com/decred/dcrd/dcrutil/v3"
"github.com/decred/dcrd/dcrutil/v4"
flags "github.com/jessevdk/go-flags"
)

Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexcctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
flags "github.com/jessevdk/go-flags"

"decred.org/dcrdex/client/rpcserver"
"github.com/decred/dcrd/dcrutil/v3"
"github.com/decred/dcrd/dcrutil/v4"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions dex/networks/dcr/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"fmt"

"decred.org/dcrdex/dex"
"decred.org/dcrwallet/wallet/txsizes"
"decred.org/dcrwallet/v2/wallet/txsizes"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrec"
"github.com/decred/dcrd/dcrutil/v3"
"github.com/decred/dcrd/txscript/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/txscript/v4"
"github.com/decred/dcrd/wire"
)

Expand Down
4 changes: 2 additions & 2 deletions dex/networks/dcr/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrec"
"github.com/decred/dcrd/dcrec/secp256k1/v3"
"github.com/decred/dcrd/dcrutil/v3"
"github.com/decred/dcrd/txscript/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/txscript/v4"
"github.com/decred/dcrd/wire"
)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/rpcclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"decred.org/dcrdex/client/rpcserver"
"decred.org/dcrdex/dex/msgjson"
"github.com/decred/dcrd/dcrutil/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/gorilla/websocket"
)

Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module decred.org/dcrdex
go 1.15

require (
decred.org/dcrwallet v1.7.0
decred.org/dcrwallet/v2 v2.0.0-20210415173800-2c9ede7f8daa
github.com/btcsuite/btcd v0.20.1-beta.0.20200615134404-e4f59022a387
github.com/btcsuite/btcutil v1.0.2
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/blockchain/stake/v3 v3.0.0
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0-20210330065944-a2366e6e0b3b
github.com/decred/dcrd/certgen v1.1.1
github.com/decred/dcrd/chaincfg/chainhash v1.0.2
github.com/decred/dcrd/chaincfg/v3 v3.0.0
Expand All @@ -16,11 +16,11 @@ require (
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.1
github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0
github.com/decred/dcrd/dcrjson/v3 v3.1.0
github.com/decred/dcrd/dcrutil/v3 v3.0.0
github.com/decred/dcrd/dcrutil/v4 v4.0.0-20210330065944-a2366e6e0b3b
github.com/decred/dcrd/hdkeychain/v3 v3.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v2 v2.3.0
github.com/decred/dcrd/rpcclient/v6 v6.0.2
github.com/decred/dcrd/txscript/v3 v3.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v3 v3.0.0-20210330065944-a2366e6e0b3b
github.com/decred/dcrd/rpcclient/v7 v7.0.0-20210330065944-a2366e6e0b3b
github.com/decred/dcrd/txscript/v4 v4.0.0-20210330065944-a2366e6e0b3b
github.com/decred/dcrd/wire v1.4.0
github.com/decred/go-socks v1.1.0
github.com/decred/slog v1.1.0
Expand Down
Loading