當前位置: 首頁>>代碼示例>>Golang>>正文


Golang walletdb.Create函數代碼示例

本文整理匯總了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
}
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:31,代碼來源:walletsetup.go

示例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
}
開發者ID:bclermont,項目名稱:btcwallet,代碼行數:27,代碼來源:tx_test.go

示例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
}
開發者ID:bclermont,項目名稱:btcwallet,代碼行數:8,代碼來源:tx_test.go

示例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)
}
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:15,代碼來源:driver_test.go

示例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
}
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:16,代碼來源:common_test.go

示例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
}
開發者ID:D-bank,項目名稱:btcwallet,代碼行數:15,代碼來源:example_test.go

示例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
}
開發者ID:D-bank,項目名稱:btcwallet,代碼行數:16,代碼來源:example_test.go

示例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
}
開發者ID:martindale,項目名稱:lnd,代碼行數:17,代碼來源:channel_test.go

示例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
}
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:50,代碼來源:factory_test.go

示例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)
}
開發者ID:littleli,項目名稱:go-electrum,代碼行數:20,代碼來源:wallet.go

示例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
}
開發者ID:runeaune,項目名稱:btcwallet,代碼行數:45,代碼來源:walletsetup.go

示例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) }
}
開發者ID:D-bank,項目名稱:btcwallet,代碼行數:19,代碼來源:factory_test.go

示例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
}
開發者ID:D-bank,項目名稱:btcwallet,代碼行數:19,代碼來源:example_test.go

示例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
}
開發者ID:PaulCapestany,項目名稱:lnd,代碼行數:45,代碼來源:setup.go

示例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
	}
}
開發者ID:D-bank,項目名稱:btcwallet,代碼行數:22,代碼來源:db_test.go


注:本文中的github.com/btcsuite/btcwallet/walletdb.Create函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。