Skip to content

Commit

Permalink
update dex implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
  • Loading branch information
ukane-philemon committed Jun 7, 2024
1 parent 1b50ae7 commit 2b699dd
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 39 deletions.
5 changes: 3 additions & 2 deletions dexc/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ type DEXClient struct {
log dex.Logger
}

func (dc *DEXClient) InitWithPassword(pw []byte, seed []byte) error {
return dc.InitializeClient(pw, seed)
func (dc *DEXClient) InitWithPassword(pw []byte, seed *string) error {
_, err := dc.InitializeClient(pw, seed)
return err
}

func (dc *DEXClient) IsInitialized() bool {
Expand Down
27 changes: 12 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ require (
github.com/jrick/logrotate v1.0.0
github.com/kevinburke/nacl v0.0.0-20190829012316-f3ed23dbd7f8
github.com/lightninglabs/neutrino v0.15.0
github.com/ltcsuite/ltcd v0.22.1-beta.0.20230329025258-1ea035d2e665
github.com/ltcsuite/ltcd/btcec/v2 v2.1.0
github.com/ltcsuite/ltcd/ltcutil v1.1.0
github.com/ltcsuite/ltcd v0.23.6-0.20240131072528-64dfa402637a
github.com/ltcsuite/ltcd/btcec/v2 v2.3.2
github.com/ltcsuite/ltcd/chaincfg/chainhash v1.0.2
github.com/ltcsuite/ltcd/ltcutil v1.1.4-0.20240131072528-64dfa402637a
github.com/ltcsuite/ltcwallet v0.13.1
github.com/ltcsuite/ltcwallet/wallet/txauthor v1.1.0
github.com/ltcsuite/ltcwallet/wallet/txrules v1.2.0
Expand Down Expand Up @@ -95,6 +96,7 @@ require (
github.com/dchest/blake2b v1.0.0 // indirect
github.com/dchest/siphash v1.2.3 // indirect
github.com/dcrlabs/bchwallet v0.0.0-20240114124852-0e95005810be // indirect
github.com/dcrlabs/ltcwallet v0.0.0-20240518141247-13553c8fce6a // indirect
github.com/dcrlabs/neutrino-bch v0.0.0-20240114121828-d656bce11095 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/base58 v1.0.5 // indirect
Expand Down Expand Up @@ -133,7 +135,6 @@ require (
github.com/gcash/bchutil v0.0.0-20210113190856-6ea28dff4000 // indirect
github.com/gcash/bchwallet v0.10.0 // indirect
github.com/gcash/bchwallet/walletdb v0.0.0-20210524114850-4837f9798568 // indirect
github.com/gcash/neutrino v0.0.0-20210524114821-3b1878290cf9 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-chi/chi/v5 v5.0.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand All @@ -145,6 +146,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/trillian v1.4.1 // indirect
Expand All @@ -171,9 +173,10 @@ require (
github.com/lightningnetwork/lnd/ticker v1.0.0 // indirect
github.com/lightningnetwork/lnd/tlv v1.0.2 // indirect
github.com/ltcsuite/lnd/clock v0.0.0-20200822020009-1a001cbb895a // indirect
github.com/ltcsuite/lnd/queue v1.0.3 // indirect
github.com/ltcsuite/lnd/queue v1.1.0 // indirect
github.com/ltcsuite/lnd/ticker v1.0.1 // indirect
github.com/ltcsuite/ltcd/ltcutil/psbt v1.1.0-1 // indirect
github.com/ltcsuite/lnd/tlv v0.0.0-20240222214433-454d35886119 // indirect
github.com/ltcsuite/ltcd/ltcutil/psbt v1.1.1-0.20240131072528-64dfa402637a // indirect
github.com/ltcsuite/neutrino v0.13.2 // indirect
github.com/marcopeereboom/sbox v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down Expand Up @@ -209,7 +212,7 @@ require (
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand All @@ -230,11 +233,5 @@ replace github.com/lib/pq => github.com/lib/pq v1.10.4
// github.com/btcsuite/btcwallet.
replace github.com/btcsuite/btcwallet v0.16.10-0.20230706223227-037580c66b74 => github.com/btcsuite/btcwallet v0.16.9

// github.com/ukane-philemon/dcrdex v0.0.0-20240127032309-04dce45a6f09 is
// (https://github.com/ukane-philemon/dcrdex/tree/with-upstream) the latest dcrdex
// master plus commits that adds methods required by cryptopower. This should be
// updated when these PRs get merged.
// 1. core: add ActiveOrders method to Core: https://github.com/decred/dcrdex/pull/2680
// 2. core: Add ExpiredBonds method to Core: https://github.com/decred/dcrdex/pull/2679
// 3. And: https://github.com/ukane-philemon/dcrdex/tree/btc-node
replace decred.org/dcrdex v0.6.3 => github.com/ukane-philemon/dcrdex v0.0.0-20240127032309-04dce45a6f09
// https://github.com/ukane-philemon/dcrdex/tree/btc-node
replace decred.org/dcrdex v0.6.3 => github.com/ukane-philemon/dcrdex v0.0.0-20240607004202-233e846a345b
39 changes: 28 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIX
github.com/dcrlabs/bchwallet v0.0.0-20240114115928-2a995d024eed/go.mod h1:dX7SZgs+dmGL56e6KHn+MktfriF/aM2qI4yYK56ySEQ=
github.com/dcrlabs/bchwallet v0.0.0-20240114124852-0e95005810be h1:F61HTz77YatFuMgleG4Hp4QpXWJgjSG+S72YlXD4jPA=
github.com/dcrlabs/bchwallet v0.0.0-20240114124852-0e95005810be/go.mod h1:Km7vMslEkg88jIFE2TA/XX7kAvXvnsoGTXN9ktYSi98=
github.com/dcrlabs/ltcwallet v0.0.0-20240518141247-13553c8fce6a h1:KJtx5FcK8oXCiXGoBpzQvGtRnhC1Q3UFKh7UVQ8YKSI=
github.com/dcrlabs/ltcwallet v0.0.0-20240518141247-13553c8fce6a/go.mod h1:UwMkslDKQGQx7UCGjolqPKulzX3YQxMhDvVZ0KukIQk=
github.com/dcrlabs/neutrino-bch v0.0.0-20240114121828-d656bce11095 h1:oGXgq+wZ2FvBzBTqXnOJ+ZP6f79zhfJNd46nDkJaUdU=
github.com/dcrlabs/neutrino-bch v0.0.0-20240114121828-d656bce11095/go.mod h1:aymH7e5PUsdsLagAIIMbpyJIff0Kv8/BJg7nolIVJbU=
github.com/dcrlabs/neutrino-ltc v0.0.0-20221031001456-55ef06cefead h1:pblpm/kKhsgJTDdJmolLYkQO2jsRRr9bcIoKaHV7cpE=
Expand Down Expand Up @@ -1155,20 +1157,30 @@ github.com/linkedin/goavro v2.1.0+incompatible/go.mod h1:bBCwI2eGYpUI/4820s67MEl
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/ltcsuite/lnd/clock v0.0.0-20200822020009-1a001cbb895a h1:HsowuWZjuKHWnTS1l+TdWbl1I1iAZszoW1fvoc8M3To=
github.com/ltcsuite/lnd/clock v0.0.0-20200822020009-1a001cbb895a/go.mod h1:d474AXivZyx25TMDB2tjjiQNuPrybFcgz+yl7vQgFTs=
github.com/ltcsuite/lnd/queue v1.0.3 h1:c3lV2VVknh6tUNBgSHrIUiyaaFfWWdt+s2q0Oz4fDaQ=
github.com/ltcsuite/lnd/queue v1.0.3/go.mod h1:L0MMGRrsJFPHhTInek8YgW2v7NyB6pXrAh6Bbg2D7u8=
github.com/ltcsuite/lnd/queue v1.1.0 h1:/aVgox4Lz74xBU8BSw5HDau7hHl2irJs5M9u1SPQ2E0=
github.com/ltcsuite/lnd/queue v1.1.0/go.mod h1:DJrxK2gPC2FjJAVYxPOcnY2CplI3rhL2PEq7IexlTWQ=
github.com/ltcsuite/lnd/ticker v1.0.1 h1:+0KvqE4HYO+fFPgNo+42hhyEjK0DwBp//IPmkLhCMcI=
github.com/ltcsuite/lnd/ticker v1.0.1/go.mod h1:WZKpekfDVAVv7Gsrr0GAWC/U1XURfGesFg9sQYJbeL4=
github.com/ltcsuite/lnd/tlv v0.0.0-20240222214433-454d35886119 h1:/xcrgmcwYQmJR96tEmDERX/X9Ni22TYJbncrkgFnzew=
github.com/ltcsuite/lnd/tlv v0.0.0-20240222214433-454d35886119/go.mod h1:hhywtdA49oLw1oCkG5gBUfhk0qDJEgAsH3X66vJv8k8=
github.com/ltcsuite/ltcd v0.20.1-beta/go.mod h1:ZFQaYdYULIuTQiWqs7AUiHD2XhDFeeHW1IH+UYMdABU=
github.com/ltcsuite/ltcd v0.22.0-beta/go.mod h1:/BXtm50r591uMfXf8XgSpL5er32HCvheJtBSPYK5bFM=
github.com/ltcsuite/ltcd v0.22.1-beta.0.20230329025258-1ea035d2e665 h1:6JipITSBzYFnjiOpPRwLj7H95nPtOPQPfG3NDBxstyo=
github.com/ltcsuite/ltcd v0.22.1-beta.0.20230329025258-1ea035d2e665/go.mod h1:O9R9U/mbZwRgr3So8TlNmW7CPc2ZQVhWyVlhXrqu/vo=
github.com/ltcsuite/ltcd/btcec/v2 v2.1.0 h1:0DMWBjQDb0V1+4kCLOJlNdHs7ewwYturuUfLHq8mosY=
github.com/ltcsuite/ltcd v0.23.5/go.mod h1:JV6swXR5m0cYFi0VYdQPp3UnMdaDQxaRUCaU1PPjb+g=
github.com/ltcsuite/ltcd v0.23.6-0.20240131072528-64dfa402637a h1:AcP4TSIeinHkqp/+g7gl7AGGSzSTBqU403kuhyPakiw=
github.com/ltcsuite/ltcd v0.23.6-0.20240131072528-64dfa402637a/go.mod h1:JV6swXR5m0cYFi0VYdQPp3UnMdaDQxaRUCaU1PPjb+g=
github.com/ltcsuite/ltcd/btcec/v2 v2.1.0/go.mod h1:Vc9ZYXMcl5D6bA0VwMvGRDJYggO3YZ7/BuIri02Lq0E=
github.com/ltcsuite/ltcd/ltcutil v1.1.0 h1:btwbdHO9cEr22zW/vgCLiF6ghh+IDngJdJsyhJ6mntU=
github.com/ltcsuite/ltcd/btcec/v2 v2.3.2 h1:HVArUNQGqGaSSoyYkk9qGht74U0/uNhS0n7jV9rkmno=
github.com/ltcsuite/ltcd/btcec/v2 v2.3.2/go.mod h1:T1t5TjbjPnryvlGQ+RpSKGuU8KhjNN7rS5+IznPj1VM=
github.com/ltcsuite/ltcd/chaincfg/chainhash v1.0.2 h1:xuWxvRKxLvOKuS7/Q/7I3tpc3cWAB0+hZpU8YdVqkzg=
github.com/ltcsuite/ltcd/chaincfg/chainhash v1.0.2/go.mod h1:nkLkAFGhursWf2U68gt61hPieK1I+0m78e+2aevNyD8=
github.com/ltcsuite/ltcd/ltcutil v1.1.0/go.mod h1:VbZlcopVgQteiCC5KRjIuxXH5wi1CtzhsvoYZ3K7FaE=
github.com/ltcsuite/ltcd/ltcutil/psbt v1.1.0-1 h1:jMJ3CA8n0qIwsVQgDPLqN2Kmz01qiB9k5eONzVlCY5g=
github.com/ltcsuite/ltcd/ltcutil v1.1.3/go.mod h1:z8txd/ohBFrOMBUT70K8iZvHJD/Vc3gzx+6BP6cBxQw=
github.com/ltcsuite/ltcd/ltcutil v1.1.4-0.20240131072528-64dfa402637a h1:fQ9S26cBkx09dbKcf9A5ibKemdW2tmiwlRH/rdm3IMo=
github.com/ltcsuite/ltcd/ltcutil v1.1.4-0.20240131072528-64dfa402637a/go.mod h1:z8txd/ohBFrOMBUT70K8iZvHJD/Vc3gzx+6BP6cBxQw=
github.com/ltcsuite/ltcd/ltcutil/psbt v1.1.0-1/go.mod h1:jpDQOdehihA+lu9OW26YgHSJ+6lReEb8HNcQL5grC4k=
github.com/ltcsuite/ltcd/ltcutil/psbt v1.1.1-0.20240131072528-64dfa402637a h1:vGmxYaHruD6GcoT6ui/4CulFqdnwfYoKZ+At84Uy10w=
github.com/ltcsuite/ltcd/ltcutil/psbt v1.1.1-0.20240131072528-64dfa402637a/go.mod h1:zcnG/wmZrTcQGTJIBgrG4Fu2ljZcV0DvZ8tzfCvU91o=
github.com/ltcsuite/ltcutil v0.0.0-20191227053721-6bec450ea6ad/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=
github.com/ltcsuite/ltcwallet v0.13.1 h1:XMyrDHn0BmgUgkNbR/Lzg36vjRsup3xdiPLSD471UMg=
github.com/ltcsuite/ltcwallet v0.13.1/go.mod h1:e6pIWRM9gsd5JnMsI9SgCJM0wi7awWdr20F1C1KUPiw=
Expand Down Expand Up @@ -1532,6 +1544,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand All @@ -1541,7 +1555,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
Expand Down Expand Up @@ -1581,8 +1596,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ukane-philemon/dcrdex v0.0.0-20240127032309-04dce45a6f09 h1:RRE8ellrTOkHmQbaIFyC9aAY6f4mQm8ZMx3YAlzba5Q=
github.com/ukane-philemon/dcrdex v0.0.0-20240127032309-04dce45a6f09/go.mod h1:2U+b4uDx4ZbAkk/pLaa2rv57G23XTyEe0Sw7Um+AdNE=
github.com/ukane-philemon/dcrdex v0.0.0-20240607004202-233e846a345b h1:A3YrjXVAeblg5bKtqpnZBo4SmmlCYA3IBQQeY50ZE5U=
github.com/ukane-philemon/dcrdex v0.0.0-20240607004202-233e846a345b/go.mod h1:t9ur12VGbTof3MPbvnmOBSvufxFE4w4fGlWt83lE2vY=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ultraware/funlen v0.0.3/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
Expand Down Expand Up @@ -2423,8 +2438,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4=
google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down Expand Up @@ -2472,7 +2487,9 @@ gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
55 changes: 55 additions & 0 deletions libwallet/assets/btc/dex-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/btcsuite/btcwallet/wallet/txauthor"
"github.com/btcsuite/btcwallet/wtxmgr"
"github.com/decred/slog"
"github.com/jrick/logrotate/rotator"
"github.com/lightninglabs/neutrino"
)

Expand All @@ -48,6 +49,9 @@ type DEXWallet struct {

// dexLogger satisfies dex.Logger.
type dexLogger struct {
level slog.Level
meterMtx *sync.RWMutex
meters map[string]time.Time
btclog.Logger
}

Expand All @@ -56,13 +60,44 @@ func (dl dexLogger) Level() slog.Level {
}

func (dl dexLogger) SetLevel(lvl slog.Level) {
dl.level = lvl
dl.Logger.SetLevel(btclog.Level(lvl))
}

func (dl dexLogger) SubLogger(string) dex.Logger {
return dl
}

// FileLogger creates a logger that logs to a file rotator. Subloggers will also
// log to the file only.
func (dl dexLogger) FileLogger(r *rotator.Rotator) dex.Logger {
return dl
}

// Meter enforces a time delay on logging. The first call to a metered logger
// always logs. Subsequent calls for the same callerID are ignored until the
// delay is surpassed.
func (dl dexLogger) Meter(callerID string, delay time.Duration) dex.Logger {
if dl.meterMtx == nil {
dl.meterMtx = &sync.RWMutex{}
}

dl.meterMtx.Lock()
defer dl.meterMtx.Unlock()
if dl.meters == nil {
dl.meters = make(map[string]time.Time)
}

if lastLog, exists := dl.meters[callerID]; exists && time.Since(lastLog) < delay {
dl.Logger.SetLevel(btclog.Level(slog.Disabled.Level()))
return dl
}

dl.Logger.SetLevel(btclog.Level(dl.level))
dl.meters[callerID] = time.Now()
return dl
}

type SyncStatusChecker interface {
IsSyncing() bool
IsSynced() bool
Expand Down Expand Up @@ -960,6 +995,26 @@ func (s *btcChainService) Peers() []dexbtc.SPVPeer {
}
}

// Fingerprint returns an identifier for this wallet. It is the hash of the
// compressed serialization of the account pub key.
func (dw *DEXWallet) Fingerprint() (string, error) {
props, err := dw.w.AccountProperties(waddrmgr.KeyScopeBIP0084, uint32(dw.acctNum))
if err != nil {
return "", err
}

if props.AccountPubKey == nil {
return "", fmt.Errorf("no account key available")
}

pk, err := props.AccountPubKey.ECPubKey()
if err != nil {
return "", err
}

return hex.EncodeToString(btcutil.Hash160(pk.SerializeCompressed())), nil
}

// secretSource is used to locate keys and redemption scripts while signing a
// transaction. secretSource satisfies the txauthor.SecretsSource interface.
type secretSource struct {
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/dcr/dex_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func (dw *DEXWallet) Reconfigure(_ context.Context, _ *dexasset.WalletConfig, _

// PurchaseTickets purchases n tickets. vspHost and vspPubKey only
// needed for internal wallets.
func (dw *DEXWallet) PurchaseTickets(_ context.Context, _ int, _, _ string) ([]*dexasset.Ticket, error) {
func (dw *DEXWallet) PurchaseTickets(_ context.Context, _ int, _, _ string, _ *dexdcr.MixingConfig) ([]*dexasset.Ticket, error) {
return nil, errors.New("PurchaseTickets not implemented by Cryptopower DEX wallet")
}

Expand Down
39 changes: 39 additions & 0 deletions libwallet/assets/ltc/dex-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
neutrino "github.com/dcrlabs/neutrino-ltc"
"github.com/dcrlabs/neutrino-ltc/chain"
"github.com/decred/slog"
"github.com/jrick/logrotate/rotator"
btcneutrino "github.com/lightninglabs/neutrino"
"github.com/lightninglabs/neutrino/headerfs"
ltcchaincfg "github.com/ltcsuite/ltcd/chaincfg"
Expand Down Expand Up @@ -64,6 +65,9 @@ type DEXWallet struct {

// dexLogger satisfies dex.Logger.
type dexLogger struct {
level slog.Level
meterMtx *sync.RWMutex
meters map[string]time.Time
btclog.Logger
}

Expand All @@ -72,13 +76,44 @@ func (dl dexLogger) Level() slog.Level {
}

func (dl dexLogger) SetLevel(lvl slog.Level) {
dl.level = lvl
dl.Logger.SetLevel(btclog.Level(lvl))
}

func (dl dexLogger) SubLogger(string) dex.Logger {
return dl
}

// FileLogger creates a logger that logs to a file rotator. Subloggers will also
// log to the file only.
func (dl dexLogger) FileLogger(_ *rotator.Rotator) dex.Logger {
return dl
}

// Meter enforces a time delay on logging. The first call to a metered logger
// always logs. Subsequent calls for the same callerID are ignored until the
// delay is surpassed.
func (dl dexLogger) Meter(callerID string, delay time.Duration) dex.Logger {
if dl.meterMtx == nil {
dl.meterMtx = &sync.RWMutex{}
}

dl.meterMtx.Lock()
defer dl.meterMtx.Unlock()
if dl.meters == nil {
dl.meters = make(map[string]time.Time)
}

if lastLog, exists := dl.meters[callerID]; exists && time.Since(lastLog) < delay {
dl.Logger.SetLevel(btclog.Level(slog.Disabled.Level()))
return dl
}

dl.Logger.SetLevel(btclog.Level(dl.level))
dl.meters[callerID] = time.Now()
return dl
}

type SyncStatusChecker interface {
IsSyncing() bool
IsSynced() bool
Expand Down Expand Up @@ -1102,6 +1137,10 @@ func (dw *DEXWallet) syncedTo() waddrmgr.BlockStamp {
}
}

func (dw *DEXWallet) Fingerprint() (string, error) {
return "", errors.New("Fingerprint not supported for Cyptopower btc wallet")
}

// ltcChainService wraps ltcsuite *neutrino.ChainService in order to translate
// the neutrino.ServerPeer to the SPVPeer interface and implement required chain
// service methods for ltc.
Expand Down
Loading

0 comments on commit 2b699dd

Please sign in to comment.