Skip to content

Commit

Permalink
multi: register with different assets, add BTC
Browse files Browse the repository at this point in the history
This permits payment of registration fee in different assets, and adds BTC.

* dex/msgjson: update config and register

Asset ID in Register and RegisterResult.

RegFees map in ConfigResult.  New FeeAsset type.

* server/db: external key derivation, add fee_asset

Add FeeAsset uint32 to the db.Account type and accounts table.

HD key derivation and address generation is no longer the role of the
database driver.

Add the db.KeyIndexer interface, which retrieves and records an
integer index for a []byte, a serialized pubkey corresponding to
a master pubkey's child and it's index.
DEXArchivist is now required to be a KeyIndexer.

CreateAccount now requires asset ID and reg address provided as inputs
rather than it generating and returning a reg address.
AccountRegAddr now also returns asset ID with the address.

* server/asset: Addresser and HDKeyIndexer

Add fee address generators to DCR and BTC.

Implement FeeCoin (fee checker) in BTC.

* server/auth: use multi-asset fee addressers and checkers

* server/cmd/dcrdex: per-asset fee config

* server/dex: per-asset fee stitching

FeeCoiner and AddresserFactor provide the helpers for the auth manager.

Update the config response with the RegFees field.

Start archivist before asset backends because the fee Addressers require
it for key index storage and retrieval.

* client/{core.db}: multi-asset fees with FeeAssetID

client/db:

This adds db.AccountInfo.FeeAssetID uint32, and updates the DB encoding.

v2 db.AccountInfo encoding is updated, and fields reordered.
When earlier (v0/v1) blobs are loaded, FeeAssetID is loaded as 42.

client/core:

Add asset ID to RegisterForm.

Add Exchange.RegFees map[string]*FeeAsset field, and a PendingFeeState
struct field that describes the asset and confs of the pending fee,
removing the RegConfirms ('confs') field. Also remove the
ConfsRequired ('confsrequired') and FeePending ('feePending') fields.

Add feeAssetID uint32 to dexAccount.

In Core, use the Exchange.RegFees map, and deal with older servers
providing the old config response.

Change (*Core).GetFee to (*Core).GetRegFees, which is unused.

Update FeePaymentNote with Asset *uint32.

* client/rpcserver and dexcctl

Kill getfee. Implement getdexconfig instead.

* client/webserver: specify DCR/42, but update handlers

Update apiRegister and registrationForm with asset ID.

Kill apiGetFee.

Modify js for pendingFee in FeePaymentNote, and removed confs and
confsrequired from Exchange struct (this.market.dex).

Frontend still defaults to DCR/42, no selection yet.
  • Loading branch information
chappjc authored Sep 18, 2021
1 parent 509205d commit 4f2ab59
Show file tree
Hide file tree
Showing 61 changed files with 1,486 additions and 763 deletions.
6 changes: 3 additions & 3 deletions client/cmd/dexcctl/dexcctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,22 @@ func TestReadTextFile(t *testing.T) {
wantErr bool
}{{
name: "ok with cert",
cmd: "getfee",
cmd: "getdexconfig",
args: []string{"1.2.3.4:3000", "./cert"},
txtFilePath: "./cert",
txtToSave: certTxt,
want: []string{"1.2.3.4:3000", certTxt},
}, {
name: "ok no cert",
cmd: "getfee",
cmd: "getdexconfig",
args: []string{"1.2.3.4:3000"},
want: []string{"1.2.3.4:3000"},
}, {
name: "not a readCerts command",
cmd: "not a real command",
}, {
name: "no file at path",
cmd: "getfee",
cmd: "getdexconfig",
args: []string{"1.2.3.4:3000", "./cert"},
wantErr: true,
}, {
Expand Down
6 changes: 3 additions & 3 deletions client/cmd/dexcctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ var promptPasswords = map[string][]string{
// the text content of a file, where the file path _may_ be found in the route's
// cmd args at the specified index.
var optionalTextFiles = map[string]int{
"getfee": 1,
"register": 2,
"newwallet": 1,
"getdexconfig": 1,
"register": 3,
"newwallet": 1,
}

// promptPWs prompts for passwords on stdin and returns an error if prompting
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexcctl/simnet-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if [ $ETH_ON -eq 0 ]; then
fi

echo registering with DEX
./dexcctl -p abc --simnet register 127.0.0.1:17273 100000000 ~/dextest/dcrdex/rpc.cert
./dexcctl -p abc --simnet register 127.0.0.1:17273 100000000 42 ~/dextest/dcrdex/rpc.cert

echo mining fee confirmation blocks
tmux send-keys -t dcr-harness:0 "./mine-alpha 1" C-m
Expand Down
27 changes: 27 additions & 0 deletions client/core/bookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,33 @@ func (dc *dexConnection) refreshServerConfig() error {
}
}
}

// Patch ConfigResponse.RegFees if no entry for DCR is there, meaning it is
// likely an older server using cfg.Fee and cfg.RegFeeConfirms.
if dcrAsset := cfg.RegFees["dcr"]; dcrAsset == nil {
dc.log.Warnf("Legacy server %v does not provide a regFees map.", dc.acct.host)
if cfg.RegFees == nil {
cfg.RegFees = make(map[string]*msgjson.FeeAsset)
}
if cfg.Fee > 0 {
cfg.RegFees["dcr"] = &msgjson.FeeAsset{ // v0 is only DCR
ID: 42,
Confs: uint32(cfg.RegFeeConfirms),
Amt: cfg.Fee,
}
} else {
dc.log.Warnf("Server %v does not support DCR for registration", dc.acct.host)
}
} else {
if cfg.Fee > 0 && dcrAsset.Amt != cfg.Fee {
dc.log.Warnf("Inconsistent DCR fee amount: %d != %d", dcrAsset.Amt, cfg.Fee)
}
if dcrAsset.Confs != uint32(cfg.RegFeeConfirms) {
dc.log.Warnf("Inconsistent DCR fee confirmation requirement: %d != %d",
dcrAsset.Confs, cfg.RegFeeConfirms)
}
}

// Update the dex connection with the new config details, including
// StartEpoch and FinalEpoch, and rebuild the market data maps.
dc.cfgMtx.Lock()
Expand Down
Loading

0 comments on commit 4f2ab59

Please sign in to comment.