Skip to content

Commit

Permalink
- rebase with planetdecred#257(dcr package PR), restructure multiwall…
Browse files Browse the repository at this point in the history
…et to

hold mutiple assets, fix crash while creating a wallet
  • Loading branch information
dreacot committed Aug 18, 2022
1 parent 861137d commit dc3e86c
Show file tree
Hide file tree
Showing 15 changed files with 1,925 additions and 427 deletions.
51 changes: 51 additions & 0 deletions btc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package dcrlibwallet

import (
// "context"
// "fmt"
"os"
"path/filepath"

"decred.org/dcrwallet/v2/errors"

"github.com/asdine/storm"
// "github.com/asdine/storm/q"

bolt "go.etcd.io/bbolt"

"github.com/planetdecred/dcrlibwallet/wallets/btc"
)

func initializeBTCWallet(rootDir, dbDriver, netType string) (*storm.DB, string, error) {
var btcDB *storm.DB

rootDir = filepath.Join(rootDir, netType, "btc")
err := os.MkdirAll(rootDir, os.ModePerm)
if err != nil {
return btcDB, "", errors.Errorf("failed to create btc rootDir: %v", err)
}

err = initLogRotator(filepath.Join(rootDir, logFileName))
if err != nil {
return btcDB, "", errors.Errorf("failed to init btc logRotator: %v", err.Error())
}

btcDB, err = storm.Open(filepath.Join(rootDir, walletsDbName))
if err != nil {
log.Errorf("Error opening btc wallets database: %s", err.Error())
if err == bolt.ErrTimeout {
// timeout error occurs if storm fails to acquire a lock on the database file
return btcDB, "", errors.E(ErrWalletDatabaseInUse)
}
return btcDB, "", errors.Errorf("error opening btc wallets database: %s", err.Error())
}

// init database for saving/reading wallet objects
err = btcDB.Init(&btc.Wallet{})
if err != nil {
log.Errorf("Error initializing btc wallets database: %s", err.Error())
return btcDB, "", err
}

return btcDB, rootDir, nil
}
193 changes: 0 additions & 193 deletions btcwallet.go

This file was deleted.

14 changes: 3 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module github.com/planetdecred/dcrlibwallet
require (
decred.org/dcrdex v0.4.1
decred.org/dcrwallet/v2 v2.0.2-0.20220505152146-ece5da349895
github.com/DataDog/zstd v1.4.8 // indirect
github.com/asdine/storm v0.0.0-20190216191021-fe89819f6282
github.com/companyzero/sntrup4591761 v0.0.0-20220309191932-9e0f3af2f07a // indirect
github.com/dchest/siphash v1.2.3 // indirect
github.com/decred/base58 v1.0.4 // indirect
github.com/btcsuite/btcd v0.22.1
github.com/decred/dcrd/addrmgr/v2 v2.0.0
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0
github.com/decred/dcrd/chaincfg/chainhash v1.0.3
Expand All @@ -24,20 +21,15 @@ require (
github.com/decred/politeia v1.3.1
github.com/decred/slog v1.2.0
github.com/dgraph-io/badger v1.6.2
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jrick/logrotate v1.0.0
github.com/kevinburke/nacl v0.0.0-20190829012316-f3ed23dbd7f8
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/planetdecred/dcrlibwallet/btcwallet v0.0.0-00010101000000-000000000000
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220223161805-c736f970653d
github.com/planetdecred/dcrlibwallet/wallets/btc v0.0.0-00010101000000-000000000000
go.etcd.io/bbolt v1.3.6
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3 // indirect
)

// Older versions of github.com/lib/pq are required by politeia (v1.9.0)
Expand All @@ -46,7 +38,7 @@ require (
// of those projects update their github.com/lib/pq dependency.
replace (
github.com/lib/pq => github.com/lib/pq v1.10.4
github.com/planetdecred/dcrlibwallet/btcwallet => ./btcwallet // TODO: testing purpose, will remove when have new version
github.com/planetdecred/dcrlibwallet/wallets/btc => ./wallets/btc // TODO: testing purpose, will remove when have new version
)

go 1.16
13 changes: 12 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,16 @@ github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13P
github.com/btcsuite/btcd v0.21.0-beta.0.20201208033208-6bd4c64a54fa/go.mod h1:Sv4JPQ3/M+teHz9Bo5jBpkNcP0x6r7rdihlNL/7tTAs=
github.com/btcsuite/btcd v0.21.0-beta.0.20210426180113-7eba688b65e5/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
github.com/btcsuite/btcd v0.22.0-beta.0.20210803133449-f5a1fb9965e4/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
github.com/btcsuite/btcd v0.22.0-beta.0.20211026140004-31791ba4dc6e h1:d0NkvbJGQThTkhypOdtf5Orxe2+dUHLB86pQ4EXwrTo=
github.com/btcsuite/btcd v0.22.0-beta.0.20211026140004-31791ba4dc6e/go.mod h1:3PH+KbvLFfzBTCevQenPiDedjGQGt6aa70dVjJDWGTA=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y=
github.com/btcsuite/btcd/btcec/v2 v2.1.1/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
github.com/btcsuite/btcd/btcutil v1.1.1/go.mod h1:nbKlBMNm9FGsdvKvu0essceubPiAcI57pYBNnsLAa34=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
Expand Down Expand Up @@ -696,6 +704,7 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M
github.com/jessevdk/go-flags v0.0.0-20181221193153-c0795c8afcf4/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.1-0.20200711081900-c17162fe8fd7/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jhump/protoreflect v1.6.1/go.mod h1:RZQ/lnuN+zqeRVpQigTwO6o0AJUkxbnSnpuG7toUTG4=
github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
Expand Down Expand Up @@ -891,6 +900,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
github.com/planetdecred/dcrlibwallet v1.7.0/go.mod h1:QTADevJvo+ugI0LZkwVVwCMiqtVf/W0DKlODTYwbnCs=
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220223161805-c736f970653d h1:egC6nx+qP3QMwKQhA+JdJReKV9NhG17Ag+3oCVCsj3c=
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220223161805-c736f970653d/go.mod h1:jO4RP2rgqom8CLgl3rMwZ4cGzmalJqBkKjHgVS812lM=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -1239,6 +1249,7 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
Loading

0 comments on commit dc3e86c

Please sign in to comment.