本文整理汇总了Golang中github.com/btcsuite/btcwallet/walletdb.Create函数的典型用法代码示例。如果您正苦于以下问题:Golang Create函数的具体用法?Golang Create怎么用?Golang Create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createSimulationWallet
// createSimulationWallet is intended to be called from the rpcclient
// and used to create a wallet for actors involved in simulations.
func createSimulationWallet(cfg *config) error {
// Simulation wallet password is 'password'.
privPass := []byte("password")
// Public passphrase is the default.
pubPass := []byte(wallet.InsecurePubPassphrase)
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
// Create the wallet.
dbPath := filepath.Join(netDir, walletDbName)
fmt.Println("Creating the wallet...")
// Create the wallet database backed by bolt db.
db, err := walletdb.Create("bdb", dbPath)
if err != nil {
return err
}
defer db.Close()
// Create the wallet.
err = wallet.Create(db, pubPass, privPass, nil, activeNet.Params)
if err != nil {
return err
}
fmt.Println("The wallet has been created successfully.")
return nil
}
示例2: testStore
func testStore() (*Store, func(), error) {
tmpDir, err := ioutil.TempDir("", "wtxmgr_test")
if err != nil {
return nil, func() {}, err
}
db, err := walletdb.Create("bdb", filepath.Join(tmpDir, "db"))
if err != nil {
teardown := func() {
os.RemoveAll(tmpDir)
}
return nil, teardown, err
}
teardown := func() {
db.Close()
os.RemoveAll(tmpDir)
}
ns, err := db.Namespace([]byte("txstore"))
if err != nil {
return nil, teardown, err
}
err = Create(ns)
if err != nil {
return nil, teardown, err
}
s, err := Open(ns, &chaincfg.TestNet3Params)
return s, teardown, err
}
示例3: testDB
func testDB() (walletdb.DB, func(), error) {
tmpDir, err := ioutil.TempDir("", "wtxmgr_test")
if err != nil {
return nil, func() {}, err
}
db, err := walletdb.Create("bdb", filepath.Join(tmpDir, "db"))
return db, func() { os.RemoveAll(tmpDir) }, err
}
示例4: TestInterface
// TestInterface performs all interfaces tests for this database driver.
func TestInterface(t *testing.T) {
// Create a new database to run tests against.
dbPath := "interfacetest.db"
db, err := walletdb.Create(dbType, dbPath)
if err != nil {
t.Errorf("Failed to create test database (%s) %v", dbType, err)
return
}
defer os.Remove(dbPath)
defer db.Close()
// Run all of the interface tests against the database.
testInterface(t, db)
}
示例5: createDbNamespace
// createDbNamespace creates a new wallet database at the provided path and
// returns it along with the address manager namespace.
func createDbNamespace(dbPath string) (walletdb.DB, walletdb.Namespace, error) {
db, err := walletdb.Create("bdb", dbPath)
if err != nil {
return nil, nil, err
}
namespace, err := db.Namespace(waddrmgrNamespaceKey)
if err != nil {
db.Close()
return nil, nil, err
}
return db, namespace, nil
}
示例6: createWalletDB
func createWalletDB() (walletdb.DB, func(), error) {
dir, err := ioutil.TempDir("", "votingpool_example")
if err != nil {
return nil, nil, err
}
db, err := walletdb.Create("bdb", filepath.Join(dir, "wallet.db"))
if err != nil {
return nil, nil, err
}
dbTearDown := func() {
db.Close()
os.RemoveAll(dir)
}
return db, dbTearDown, nil
}
示例7: exampleLoadDB
// exampleLoadDB is used in the examples to elide the setup code.
func exampleLoadDB() (walletdb.DB, func(), error) {
dbName := fmt.Sprintf("exampleload%d.db", exampleNum)
dbPath := filepath.Join(os.TempDir(), dbName)
db, err := walletdb.Create("bdb", dbPath)
if err != nil {
return nil, nil, err
}
teardownFunc := func() {
db.Close()
os.Remove(dbPath)
}
exampleNum++
return db, teardownFunc, err
}
示例8: createDbNamespace
// createDbNamespace creates a new wallet database at the provided path and
// returns it along with the address manager namespace.
func createDbNamespace(dbPath string) (walletdb.DB, walletdb.Namespace, error) {
db, err := walletdb.Create("bdb", dbPath)
if err != nil {
fmt.Println("fuk")
return nil, nil, err
}
namespace, err := db.Namespace([]byte("waddr"))
if err != nil {
db.Close()
return nil, nil, err
}
return db, namespace, nil
}
示例9: TstCreatePool
// TstCreatePool creates a Pool on a fresh walletdb and returns it. It also
// returns the pool's waddrmgr.Manager (which uses the same walletdb, but with a
// different namespace) as a convenience, and a teardown function that closes
// the Manager and removes the directory used to store the database.
func TstCreatePool(t *testing.T) (tearDownFunc func(), mgr *waddrmgr.Manager, pool *Pool) {
// This should be moved somewhere else eventually as not all of our tests
// call this function, but right now the only option would be to have the
// t.Parallel() call in each of our tests.
t.Parallel()
// Create a new wallet DB and addr manager.
dir, err := ioutil.TempDir("", "pool_test")
if err != nil {
t.Fatalf("Failed to create db dir: %v", err)
}
db, err := walletdb.Create("bdb", filepath.Join(dir, "wallet.db"))
if err != nil {
t.Fatalf("Failed to create wallet DB: %v", err)
}
mgrNamespace, err := db.Namespace([]byte("waddrmgr"))
if err != nil {
t.Fatalf("Failed to create addr manager DB namespace: %v", err)
}
var fastScrypt = &waddrmgr.ScryptOptions{N: 16, R: 8, P: 1}
err = waddrmgr.Create(mgrNamespace, seed, pubPassphrase, privPassphrase,
&chaincfg.MainNetParams, fastScrypt)
if err == nil {
mgr, err = waddrmgr.Open(mgrNamespace, pubPassphrase,
&chaincfg.MainNetParams, nil)
}
if err != nil {
t.Fatalf("Failed to create addr manager: %v", err)
}
// Create a walletdb for votingpools.
vpNamespace, err := db.Namespace([]byte("votingpool"))
if err != nil {
t.Fatalf("Failed to create VotingPool DB namespace: %v", err)
}
pool, err = Create(vpNamespace, mgr, []byte{0x00})
if err != nil {
t.Fatalf("Voting Pool creation failed: %v", err)
}
tearDownFunc = func() {
db.Close()
mgr.Close()
os.RemoveAll(dir)
}
return tearDownFunc, mgr, pool
}
示例10: Create
// Create creates a wallet with the specified path, private key password and seed.
// Seed can be created using: hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
func Create(path, privPass string, seed []byte) (*Wallet, error) {
db, err := walletdb.Create("bdb", path)
if err != nil {
return nil, err
}
namespace, err := db.Namespace(waddrmgrNamespaceKey)
if err != nil {
return nil, err
}
manager, err := waddrmgr.Create(namespace, seed, nil,
[]byte(privPass), bitcoinNetwork.Params, nil)
if err != nil {
return nil, err
}
manager.Close()
return openWallet(db, privPass, seed)
}
示例11: createSimulationWallet
// createSimulationWallet is intended to be called from the rpcclient
// and used to create a wallet for actors involved in simulations.
func createSimulationWallet(cfg *config) error {
// Simulation wallet password is 'password'.
privPass := []byte("password")
// Public passphrase is the default.
pubPass := []byte(defaultPubPassphrase)
// Generate a random seed.
seed, err := hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
if err != nil {
return err
}
netDir := networkDir(cfg.DataDir, activeNet.Params)
// Create the wallet.
dbPath := filepath.Join(netDir, walletDbName)
fmt.Println("Creating the wallet...")
// Create the wallet database backed by bolt db.
db, err := walletdb.Create("bdb", dbPath)
if err != nil {
return err
}
defer db.Close()
// Create the address manager.
waddrmgrNamespace, err := db.Namespace(waddrmgrNamespaceKey)
if err != nil {
return err
}
manager, err := waddrmgr.Create(waddrmgrNamespace, seed, []byte(pubPass),
[]byte(privPass), activeNet.Params, nil)
if err != nil {
return err
}
manager.Close()
fmt.Println("The wallet has been created successfully.")
return nil
}
示例12: TstCreateTxStore
func TstCreateTxStore(t *testing.T) (store *wtxmgr.Store, tearDown func()) {
dir, err := ioutil.TempDir("", "pool_test_txstore")
if err != nil {
t.Fatalf("Failed to create txstore dir: %v", err)
}
db, err := walletdb.Create("bdb", filepath.Join(dir, "txstore.db"))
if err != nil {
t.Fatalf("Failed to create walletdb: %v", err)
}
wtxmgrNamespace, err := db.Namespace([]byte("testtxstore"))
if err != nil {
t.Fatalf("Failed to create walletdb namespace: %v", err)
}
s, err := wtxmgr.Create(wtxmgrNamespace)
if err != nil {
t.Fatalf("Failed to create txstore: %v", err)
}
return s, func() { os.RemoveAll(dir) }
}
示例13: exampleCreateTxStore
func exampleCreateTxStore() (*wtxmgr.Store, func(), error) {
dir, err := ioutil.TempDir("", "pool_test_txstore")
if err != nil {
return nil, nil, err
}
db, err := walletdb.Create("bdb", filepath.Join(dir, "txstore.db"))
if err != nil {
return nil, nil, err
}
wtxmgrNamespace, err := db.Namespace([]byte("testtxstore"))
if err != nil {
return nil, nil, err
}
s, err := wtxmgr.Create(wtxmgrNamespace)
if err != nil {
return nil, nil, err
}
return s, func() { os.RemoveAll(dir) }, nil
}
示例14: createWallet
// createWallet generates a new wallet. The new wallet will reside at the
// provided path.
// TODO(roasbeef): maybe pass in config after all for testing purposes?
func createWallet(privPass, pubPass, userSeed []byte,
dbPath string) error {
// TODO(roasbeef): replace with tadge's seed format?
hdSeed := userSeed
var seedErr error
if userSeed == nil {
hdSeed, seedErr = hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
if seedErr != nil {
return seedErr
}
}
// Create the wallet.
fmt.Println("Creating the wallet...")
// Create the wallet database backed by bolt db.
db, err := walletdb.Create("bdb", dbPath)
if err != nil {
return err
}
// Create the address manager.
namespace, err := db.Namespace(waddrmgrNamespaceKey)
if err != nil {
return err
}
manager, err := waddrmgr.Create(namespace, hdSeed, []byte(pubPass),
[]byte(privPass), ActiveNetParams, nil)
if err != nil {
return err
}
if err := manager.Close(); err != nil {
return err
}
if err := db.Close(); err != nil {
return err
}
fmt.Println("The lnwallet has been created successfully.")
return nil
}
示例15: TestCreateOpenUnsupported
// TestCreateOpenUnsupported ensures that attempting to create or open an
// unsupported database type is handled properly.
func TestCreateOpenUnsupported(t *testing.T) {
// Ensure creating a database with an unsupported type fails with the
// expected error.
dbType := "unsupported"
_, err := walletdb.Create(dbType)
if err != walletdb.ErrDbUnknownType {
t.Errorf("expected error not received - got: %v, want %v", err,
walletdb.ErrDbUnknownType)
return
}
// Ensure opening a database with the an unsupported type fails with the
// expected error.
_, err = walletdb.Open(dbType)
if err != walletdb.ErrDbUnknownType {
t.Errorf("expected error not received - got: %v, want %v", err,
walletdb.ErrDbUnknownType)
return
}
}