Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BTC wallet #254

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
24 changes: 24 additions & 0 deletions btcwallet/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module github.com/planetdecred/dcrlibwallet/btcwallet

require (
github.com/btcsuite/btcd v0.22.0-beta.0.20211026140004-31791ba4dc6e
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v1.0.3-0.20210527170813-e2ba6805a890 // note: hoists btcd's own require of btcutil
github.com/btcsuite/btcwallet v0.12.0
github.com/btcsuite/btcwallet/wallet/txauthor v1.1.0 // indirect
github.com/btcsuite/btcwallet/wallet/txsizes v1.1.0 // indirect
github.com/btcsuite/btcwallet/walletdb v1.4.0
github.com/btcsuite/btcwallet/wtxmgr v1.3.0
github.com/decred/dcrd/lru v1.1.1 // indirect
github.com/decred/slog v1.2.0
github.com/jrick/logrotate v1.0.0
github.com/kkdai/bstream v1.0.0 // indirect
github.com/lightninglabs/neutrino v0.13.1-0.20211214231330-53b628ce1756
github.com/stretchr/testify v1.7.0 // indirect
go.etcd.io/bbolt v1.3.5 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
)

go 1.16
168 changes: 168 additions & 0 deletions btcwallet/go.sum

Large diffs are not rendered by default.

Loading