From c8e7231b5fb534dc9bb087186966c318e89650b8 Mon Sep 17 00:00:00 2001 From: Jonathan Chappelow Date: Thu, 25 Aug 2022 10:20:03 -0500 Subject: [PATCH] server/dex: use the real bond parser --- server/dex/dex.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/server/dex/dex.go b/server/dex/dex.go index d2781b8ee4..f6b124728b 100644 --- a/server/dex/dex.go +++ b/server/dex/dex.go @@ -6,6 +6,7 @@ package dex import ( "context" "encoding/json" + "errors" "fmt" "strconv" "strings" @@ -19,6 +20,7 @@ import ( "decred.org/dcrdex/server/account" "decred.org/dcrdex/server/apidata" "decred.org/dcrdex/server/asset" + "decred.org/dcrdex/server/asset/dcr" "decred.org/dcrdex/server/auth" "decred.org/dcrdex/server/coinlock" "decred.org/dcrdex/server/comms" @@ -602,9 +604,17 @@ func NewDEX(ctx context.Context, cfg *DexConf) (*DEX, error) { return fc.FeeCoin(coinID) } - dummyBondParser := func(assetID uint32, ver uint16, rawTx, bondScript []byte) (bondCoinID []byte, amt int64, bondAddr string, - lockTime int64, acct account.AccountID, err error) { - return // actual parser will wrap server/asset/dcr.ParseBondTx + bondTxParser := func(assetID uint32, version uint16, rawTx, bondData []byte) (bondCoinID []byte, amt int64, + bondAddr string, lockTime int64, acct account.AccountID, err error) { + if assetID != dcr.BipID { + err = errors.New("asset not supported") + return + } + // TODO: If the parser remains a package-level function, consider a + // driver method. If the parser becomes a backend method, get it from + // the backedAssets map containing the asset.Backend instances. + bondCoinID, amt, bondAddr, _, lockTime, acct, err = dcr.ParseBondTx(version, rawTx) + return } authCfg := auth.Config{ @@ -615,7 +625,7 @@ func NewDEX(ctx context.Context, cfg *DexConf) (*DEX, error) { FeeChecker: feeChecker, BondConfs: 1, // TODO BondIncrement: cfg.BondIncrement, - BondTxParser: dummyBondParser, // NOTE: backend instantiation sets the package-level network params + BondTxParser: bondTxParser, BondExpiry: uint64(bondExpiry), UserUnbooker: userUnbookFun, MiaUserTimeout: cfg.BroadcastTimeout,