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


Golang walletdb.Create函數代碼示例

本文整理匯總了Golang中github.com/decred/dcrwallet/walletdb.Create函數的典型用法代碼示例。如果您正苦於以下問題:Golang Create函數的具體用法?Golang Create怎麽用?Golang Create使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Create函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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.TestNetParams)
	return s, teardown, err
}
開發者ID:jcvernaleo,項目名稱:btcwallet,代碼行數:27,代碼來源:tx_test.go

示例2: 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:frankbraun,項目名稱:dcrwallet,代碼行數:8,代碼來源:tx_test.go

示例3: createWatchingOnlyWallet

// createWatchingOnlyWallet
func createWatchingOnlyWallet(cfg *config) error {
	// Get the public key.
	reader := bufio.NewReader(os.Stdin)
	pubKeyString, err := promptHDPublicKey(reader)
	if err != nil {
		return err
	}

	// Ask if the user wants to encrypt the wallet with a password.
	pubPass, err := promptConsolePublicPass(reader, []byte{}, cfg)
	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.CreateWatchOnly(waddrmgrNamespace, pubKeyString,
		[]byte(pubPass), activeNet.Params, nil)
	if err != nil {
		return err
	}
	defer manager.Close()

	// Create the stake manager/store.
	wstakemgrNamespace, err := db.Namespace(wstakemgrNamespaceKey)
	if err != nil {
		return err
	}
	stakeStore, err := wstakemgr.Create(wstakemgrNamespace, manager,
		activeNet.Params)
	if err != nil {
		return err
	}
	defer stakeStore.Close()

	fmt.Println("The watching only wallet has been created successfully.")
	return nil
}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:56,代碼來源:walletsetup.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:frankbraun,項目名稱:dcrwallet,代碼行數:15,代碼來源:driver_test.go

示例5: CreateNewWallet

// CreateNewWallet creates a new wallet using the provided public and private
// passphrases.  The seed is optional.  If non-nil, addresses are derived from
// this seed.  If nil, a secure random seed is generated.
func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase, seed []byte) (*Wallet, error) {
	defer l.mu.Unlock()
	l.mu.Lock()

	if l.wallet != nil {
		return nil, ErrLoaded
	}

	dbPath := filepath.Join(l.dbDirPath, walletDbName)
	exists, err := fileExists(dbPath)
	if err != nil {
		return nil, err
	}
	if exists {
		return nil, ErrExists
	}

	// Create the wallet database backed by bolt db.
	err = os.MkdirAll(l.dbDirPath, 0700)
	if err != nil {
		return nil, err
	}
	db, err := walletdb.Create("bdb", dbPath)
	if err != nil {
		return nil, err
	}

	// Initialize the newly created database for the wallet before opening.
	err = Create(db, pubPassphrase, privPassphrase, seed, l.chainParams,
		l.unsafeMainNet)
	if err != nil {
		return nil, err
	}

	// Open the newly-created wallet.
	so := l.stakeOptions
	w, err := Open(db, pubPassphrase, nil, so.VoteBits, so.VoteBitsExtended,
		so.StakeMiningEnabled, so.BalanceToMaintain, so.AddressReuse,
		so.RollbackTest, so.PruneTickets, so.TicketAddress, so.TicketMaxPrice,
		so.TicketBuyFreq, so.PoolAddress, so.PoolFees, so.TicketFee,
		l.addrIdxScanLen, so.StakePoolColdExtKey, l.autoRepair,
		l.allowHighFees, l.relayFee, l.chainParams)
	if err != nil {
		return nil, err
	}
	w.Start()

	l.onLoaded(w, db)
	return w, nil
}
開發者ID:jcvernaleo,項目名稱:btcwallet,代碼行數:53,代碼來源:loader.go

示例6: 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:frankbraun,項目名稱:dcrwallet,代碼行數:16,代碼來源:common_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:frankbraun,項目名稱:dcrwallet,代碼行數:16,代碼來源:example_test.go

示例8: 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:frankbraun,項目名稱:dcrwallet,代碼行數:15,代碼來源:example_test.go

示例9: 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 := wallet.SimulationPassphrase

	// Public passphrase is the default.
	pubPass := []byte(wallet.InsecurePubPassphrase)

	// Generate a random seed.
	seed, err := hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
	if err != nil {
		return err
	}

	netDir := networkDir(cfg.AppDataDir, activeNet.Params)

	// Write the seed to disk, so that we can restore it later
	// if need be, for testing purposes.
	seedStr, err := pgpwordlist.ToStringChecksum(seed)
	if err != nil {
		return err
	}

	err = ioutil.WriteFile(filepath.Join(netDir, "seed"), []byte(seedStr), 0644)
	if err != nil {
		return err
	}

	// 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, seed, activeNet.Params, cfg.UnsafeMainNet)
	if err != nil {
		return err
	}

	fmt.Println("The wallet has been created successfully.")
	return nil
}
開發者ID:jcvernaleo,項目名稱:btcwallet,代碼行數:49,代碼來源:walletsetup.go

示例10: 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, &chaincfg.SimNetParams)
	if err != nil {
		return nil, nil, err
	}
	return s, func() { os.RemoveAll(dir) }, nil
}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:19,代碼來源:example_test.go

示例11: 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, &chaincfg.TestNetParams)
	if err != nil {
		t.Fatalf("Failed to create txstore: %v", err)
	}
	return s, func() { os.RemoveAll(dir) }
}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:19,代碼來源:factory_test.go

示例12: 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}
	mgr, err = waddrmgr.Create(mgrNamespace, seed, pubPassphrase, privPassphrase,
		&chaincfg.TestNetParams, fastScrypt)
	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:frankbraun,項目名稱:dcrwallet,代碼行數:46,代碼來源:factory_test.go

示例13: 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:frankbraun,項目名稱:dcrwallet,代碼行數:22,代碼來源:db_test.go

示例14: TestAddDuplicateDriver

// TestAddDuplicateDriver ensures that adding a duplicate driver does not
// overwrite an existing one.
func TestAddDuplicateDriver(t *testing.T) {
	supportedDrivers := walletdb.SupportedDrivers()
	if len(supportedDrivers) == 0 {
		t.Errorf("no backends to test")
		return
	}
	dbType := supportedDrivers[0]

	// bogusCreateDB is a function which acts as a bogus create and open
	// driver function and intentionally returns a failure that can be
	// detected if the interface allows a duplicate driver to overwrite an
	// existing one.
	bogusCreateDB := func(args ...interface{}) (walletdb.DB, error) {
		return nil, fmt.Errorf("duplicate driver allowed for database "+
			"type [%v]", dbType)
	}

	// Create a driver that tries to replace an existing one.  Set its
	// create and open functions to a function that causes a test failure if
	// they are invoked.
	driver := walletdb.Driver{
		DbType: dbType,
		Create: bogusCreateDB,
		Open:   bogusCreateDB,
	}
	err := walletdb.RegisterDriver(driver)
	if err != walletdb.ErrDbTypeRegistered {
		t.Errorf("unexpected duplicate driver registration error - "+
			"got %v, want %v", err, walletdb.ErrDbTypeRegistered)
	}

	dbPath := "dupdrivertest.db"
	db, err := walletdb.Create(dbType, dbPath)
	if err != nil {
		t.Errorf("failed to create database: %v", err)
		return
	}
	db.Close()
	_ = os.Remove(dbPath)

}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:43,代碼來源:db_test.go

示例15: newManager

// newManager creates a new waddrmgr and imports the given privKey into it.
func newManager(t *testing.T, privKeys []string, bs *waddrmgr.BlockStamp) *waddrmgr.Manager {
	dbPath := filepath.Join(os.TempDir(), "wallet.bin")
	os.Remove(dbPath)
	db, err := walletdb.Create("bdb", dbPath)
	if err != nil {
		t.Fatal(err)
	}

	namespace, err := db.Namespace(waddrmgrNamespaceKey)
	if err != nil {
		t.Fatal(err)
	}

	seed, err := hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
	if err != nil {
		t.Fatal(err)
	}

	pubPassphrase := []byte("pub")
	privPassphrase := []byte("priv")
	mgr, err := waddrmgr.Create(namespace, seed, pubPassphrase,
		privPassphrase, &chaincfg.TestNetParams, fastScrypt)
	if err != nil {
		t.Fatal(err)
	}

	for _, key := range privKeys {
		wif, err := dcrutil.DecodeWIF(key)
		if err != nil {
			t.Fatal(err)
		}
		if err = mgr.Unlock(privPassphrase); err != nil {
			t.Fatal(err)
		}
		_, err = mgr.ImportPrivateKey(wif, bs)
		if err != nil {
			t.Fatal(err)
		}
	}
	return mgr
}
開發者ID:frankbraun,項目名稱:dcrwallet,代碼行數:42,代碼來源:createtx_test.go


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