Skip to content

Commit

Permalink
move dcr related capability to the dcr package
Browse files Browse the repository at this point in the history
  • Loading branch information
dreacot committed Jul 21, 2022
1 parent c6b8672 commit 2b0f810
Show file tree
Hide file tree
Showing 42 changed files with 4,075 additions and 1,934 deletions.
58 changes: 58 additions & 0 deletions dcr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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/dcr"
)

func initializeDCRWallet(rootDir, dbDriver, netType string) (*storm.DB, string, error) {
var mwDB *storm.DB

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

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

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

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

// init database for saving/reading proposal objects
err = mwDB.Init(&dcr.Proposal{})
if err != nil {
log.Errorf("Error initializing wallets database: %s", err.Error())
return mwDB, "", err
}

return mwDB, rootDir, nil
}
2 changes: 1 addition & 1 deletion dexclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (mw *MultiWallet) prepareDexSupportForDcrWalletLibrary() error {
return nil, fmt.Errorf("account error: %v", err)
}

walletDesc := fmt.Sprintf("%q in %s", wallet.Name, wallet.dataDir)
walletDesc := fmt.Sprintf("%q in %s", wallet.Name, wallet.DataDir)
return dexdcr.NewSpvWallet(wallet.Internal(), walletDesc, chainParams, logger.SubLogger("DLWL")), nil
}

Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ require (
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/btcsuite/btcd v0.22.0-beta.0.20211026140004-31791ba4dc6e // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/btcsuite/btcutil v1.0.3-0.20210527170813-e2ba6805a890 // indirect
github.com/btcsuite/btcwallet v0.12.0 // indirect
github.com/btcsuite/btcwallet/walletdb v1.4.0 // indirect
github.com/btcsuite/btcwallet/wtxmgr v1.3.0 // indirect
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
Expand All @@ -16,6 +22,7 @@ require (
github.com/decred/dcrd/dcrutil/v4 v4.0.0
github.com/decred/dcrd/gcs/v3 v3.0.0
github.com/decred/dcrd/hdkeychain/v3 v3.1.0
github.com/decred/dcrd/rpc/jsonrpc/types/v3 v3.0.0
github.com/decred/dcrd/txscript/v4 v4.0.0
github.com/decred/dcrd/wire v1.5.0
github.com/decred/dcrdata/v7 v7.0.0-20211216152310-365c9dc820eb
Expand All @@ -26,6 +33,7 @@ require (
github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/jrick/logrotate v1.0.0
github.com/kevinburke/nacl v0.0.0-20190829012316-f3ed23dbd7f8
github.com/lightninglabs/neutrino v0.13.1-0.20211214231330-53b628ce1756 // indirect
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/planetdecred/dcrlibwallet/dexdcr v0.0.0-20220223161805-c736f970653d
Expand Down
Loading

0 comments on commit 2b0f810

Please sign in to comment.