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

add zclassic #2523

Merged
merged 7 commits into from
Oct 20, 2023
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
32 changes: 13 additions & 19 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ type BTCCloneCFG struct {
// LegacyBalance is for clones that don't yet support the 'getbalances' RPC
// call.
LegacyBalance bool
// ZECStyleBalance is for clones that don't support getbalances or
// walletinfo, and don't take an account name argument.
ZECStyleBalance bool
// BalanceFunc is a custom function for getting the wallet's balance.
// BalanceFunc precludes any other methods of balance retrieval.
BalanceFunc func(ctx context.Context, locked uint64) (*asset.Balance, error)
// If segwit is false, legacy addresses and contracts will be used. This
// setting must match the configuration of the server's asset backend.
Segwit bool
Expand Down Expand Up @@ -886,7 +886,7 @@ type baseWallet struct {
initTxSize uint64
initTxSizeBase uint64
useLegacyBalance bool
zecStyleBalance bool
balanceFunc func(ctx context.Context, locked uint64) (*asset.Balance, error)
segwit bool
signNonSegwit TxInSigner
localFeeRate func(context.Context, RawRequester, uint64) (uint64, error)
Expand Down Expand Up @@ -1345,7 +1345,7 @@ func newUnconnectedWallet(cfg *BTCCloneCFG, walletCfg *WalletConfig) (*baseWalle
minNetworkVersion: cfg.MinNetworkVersion,
dustLimit: cfg.ConstantDustLimit,
useLegacyBalance: cfg.LegacyBalance,
zecStyleBalance: cfg.ZECStyleBalance,
balanceFunc: cfg.BalanceFunc,
segwit: cfg.Segwit,
initTxSize: uint64(initTxSize),
initTxSizeBase: uint64(initTxSizeBase),
Expand Down Expand Up @@ -1627,7 +1627,14 @@ func (btc *baseWallet) OwnsDepositAddress(address string) (bool, error) {
}

func (btc *baseWallet) balance() (*asset.Balance, error) {
if btc.useLegacyBalance || btc.zecStyleBalance {
if btc.balanceFunc != nil {
locked, err := btc.lockedSats()
if err != nil {
return nil, fmt.Errorf("(legacy) lockedSats error: %w", err)
}
return btc.balanceFunc(btc.ctx, locked)
}
if btc.useLegacyBalance {
return btc.legacyBalance()
}
balances, err := btc.node.balances()
Expand Down Expand Up @@ -1700,19 +1707,6 @@ func (btc *baseWallet) legacyBalance() (*asset.Balance, error) {
return nil, fmt.Errorf("(legacy) lockedSats error: %w", err)
}

if btc.zecStyleBalance {
var bal uint64
// args: "(dummy)" minconf includeWatchonly inZat
if err := cl.call(methodGetBalance, anylist{"", 0, false, true}, &bal); err != nil {
return nil, err
}
return &asset.Balance{
Available: bal - locked,
Locked: locked,
Other: make(map[asset.BalanceCategory]asset.CustomBalance),
}, nil
}

walletInfo, err := cl.GetWalletInfo()
if err != nil {
return nil, fmt.Errorf("(legacy) GetWalletInfo error: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion client/asset/btc/livetest/livetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func Run(t *testing.T, cfg *Config) {
}

var expConfs uint32
blockWait := time.Second
blockWait := time.Second * 5
if cfg.SPV {
blockWait = time.Second * 6
}
Expand Down
16 changes: 11 additions & 5 deletions client/asset/btc/rpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,28 +888,34 @@ func (wc *rpcClient) estimateSendTxFee(tx *wire.MsgTx, feeRate uint64, subtract
args = append(args, options)
}

res := &btcjson.FundRawTransactionResult{}
var res struct {
TxBytes dex.Bytes `json:"hex"`
Fees float64 `json:"fee"`
ChangePosition uint32 `json:"changepos"`
}
err = wc.call(methodFundRawTransaction, args, &res)
if err != nil {
wc.log.Debugf("%s fundrawtranasaction error for args %+v: %v \n", wc.cloneParams.WalletInfo.Name, args, err)
// This is a work around for ZEC wallet, which does not support options
// argument for fundrawtransaction.
if wc.omitRPCOptionsArg {
var sendAmount uint64
for _, txOut := range tx.TxOut {
sendAmount += uint64(txOut.Value)
}
var bal uint64
var bal float64
// args: "(dummy)" minconf includeWatchonly inZat
if err := wc.call(methodGetBalance, anylist{"", 0, false, true}, &bal); err != nil {
// Using default inZat = false for compatibility with ZCL.
if err := wc.call(methodGetBalance, anylist{"", 0, false}, &bal); err != nil {
return 0, err
}
if subtract && sendAmount <= bal {
if subtract && sendAmount <= toSatoshi(bal) {
return 0, errors.New("wallet does not support options")
}
}
return 0, fmt.Errorf("error calculating transaction fee: %w", err)
}
return toSatoshi(res.Fee.ToBTC()), nil
return toSatoshi(res.Fees), nil
}

// GetWalletInfo gets the getwalletinfo RPC result.
Expand Down
1 change: 0 additions & 1 deletion client/asset/dash/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func newWallet(cfg *asset.WalletConfig, logger dex.Logger, network dex.Network)
DefaultFallbackFee: dexdash.DefaultFee,
DefaultFeeRateLimit: dexdash.DefaultFeeRateLimit,
LegacyBalance: false,
ZECStyleBalance: false,
Segwit: false,
// Dash v19.1.0 has a breaking change from the true/false 'allowhighfees'
// to 'maxfeerate' in DASH/kB, the same as btc.
Expand Down
41 changes: 41 additions & 0 deletions client/asset/zcl/regnet_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build harness

package zcl

// Regnet tests expect the ZEC test harness to be running.

import (
"testing"

"decred.org/dcrdex/client/asset/btc/livetest"
"decred.org/dcrdex/dex"
dexzec "decred.org/dcrdex/dex/networks/zec"
)

var (
tLotSize uint64 = 1e6
tZCL = &dex.Asset{
ID: BipID,
Symbol: "zcl",
SwapSize: dexzec.InitTxSize,
SwapSizeBase: dexzec.InitTxSizeBase,
MaxFeeRate: 100,
SwapConf: 1,
}
)

func TestWallet(t *testing.T) {
livetest.Run(t, &livetest.Config{
NewWallet: NewWallet,
LotSize: tLotSize,
Asset: tZCL,
FirstWallet: &livetest.WalletName{
Node: "alpha",
Filename: "alpha.conf",
},
SecondWallet: &livetest.WalletName{
Node: "beta",
Filename: "beta.conf",
},
})
}
Loading