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


Golang crypto.NewKeyStorePassphrase函數代碼示例

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


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

示例1: New

// New creates a Ethereum client, pre-configured to one of the supported networks.
func New(datadir string, network EthereumNetwork) (*Geth, error) {
	// Tag the data dir with the network name
	switch network {
	case MainNet:
		datadir = filepath.Join(datadir, "mainnet")
	case TestNet:
		datadir = filepath.Join(datadir, "testnet")
	default:
		return nil, fmt.Errorf("unsupported network: %v", network)
	}
	// Select the bootstrap nodes based on the network
	bootnodes := utils.FrontierBootNodes
	if network == TestNet {
		bootnodes = utils.TestNetBootNodes
	}
	// Configure the node's service container
	stackConf := &node.Config{
		DataDir:        datadir,
		Name:           common.MakeName(NodeName, NodeVersion),
		BootstrapNodes: bootnodes,
		ListenAddr:     fmt.Sprintf(":%d", NodePort),
		MaxPeers:       NodeMaxPeers,
	}
	// Configure the bare-bone Ethereum service
	keystore := crypto.NewKeyStorePassphrase(filepath.Join(datadir, "keystore"), crypto.StandardScryptN, crypto.StandardScryptP)
	ethConf := &eth.Config{
		FastSync:       true,
		DatabaseCache:  64,
		NetworkId:      int(network),
		AccountManager: accounts.NewManager(keystore),

		// Blatantly initialize the gas oracle to the defaults from go-ethereum
		GpoMinGasPrice:          new(big.Int).Mul(big.NewInt(50), common.Shannon),
		GpoMaxGasPrice:          new(big.Int).Mul(big.NewInt(500), common.Shannon),
		GpoFullBlockRatio:       80,
		GpobaseStepDown:         10,
		GpobaseStepUp:           100,
		GpobaseCorrectionFactor: 110,
	}
	// Override any default configs in the test network
	if network == TestNet {
		ethConf.NetworkId = 2
		ethConf.Genesis = core.TestNetGenesisBlock()
		state.StartingNonce = 1048576 // (2**20)
		params.HomesteadBlock = params.TestNetHomesteadBlock
	}
	// Assemble and return the protocol stack
	stack, err := node.New(stackConf)
	if err != nil {
		return nil, fmt.Errorf("protocol stack: %v", err)
	}
	if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { return eth.New(ctx, ethConf) }); err != nil {
		return nil, fmt.Errorf("ethereum service: %v", err)
	}
	return &Geth{
		stack:    stack,
		keystore: keystore,
	}, nil
}
開發者ID:obscuren,項目名稱:etherapis,代碼行數:60,代碼來源:geth.go

示例2: testEthConfig

func testEthConfig() *eth.Config {
	ks := crypto.NewKeyStorePassphrase(path.Join(common.DefaultDataDir(), "keys"))

	return &eth.Config{
		DataDir:        common.DefaultDataDir(),
		LogLevel:       5,
		Etherbase:      "primary",
		AccountManager: accounts.NewManager(ks),
		NewDB:          func(path string) (common.Database, error) { return ethdb.NewMemDatabase() },
	}
}
開發者ID:CedarLogic,項目名稱:go-ethereum,代碼行數:11,代碼來源:block_test.go

示例3: makeEthConfig

func (test *BlockTest) makeEthConfig() *eth.Config {
	ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"))

	return &eth.Config{
		DataDir:        common.DefaultDataDir(),
		Verbosity:      5,
		Etherbase:      common.Address{},
		AccountManager: accounts.NewManager(ks),
		NewDB:          func(path string) (common.Database, error) { return ethdb.NewMemDatabase() },
	}
}
開發者ID:nilcons-contrib,項目名稱:go-ethereum,代碼行數:11,代碼來源:block_test_util.go

示例4: runBlockTest

func runBlockTest(test *BlockTest) error {
	ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"), crypto.StandardScryptN, crypto.StandardScryptP)
	am := accounts.NewManager(ks)
	db, _ := ethdb.NewMemDatabase()
	cfg := &eth.Config{
		DataDir:        common.DefaultDataDir(),
		Verbosity:      5,
		Etherbase:      common.Address{},
		AccountManager: am,
		NewDB:          func(path string) (ethdb.Database, error) { return db, nil },
	}

	cfg.GenesisBlock = test.Genesis

	// import pre accounts & construct test genesis block & state root
	_, err := test.InsertPreState(db, am)
	if err != nil {
		return fmt.Errorf("InsertPreState: %v", err)
	}

	ethereum, err := eth.New(cfg)
	if err != nil {
		return err
	}

	err = ethereum.Start()
	if err != nil {
		return err
	}

	cm := ethereum.BlockChain()
	validBlocks, err := test.TryBlocksInsert(cm)
	if err != nil {
		return err
	}

	lastblockhash := common.HexToHash(test.lastblockhash)
	cmlast := cm.LastBlockHash()
	if lastblockhash != cmlast {
		return fmt.Errorf("lastblockhash validation mismatch: want: %x, have: %x", lastblockhash, cmlast)
	}

	newDB, err := cm.State()
	if err != nil {
		return err
	}
	if err = test.ValidatePostState(newDB); err != nil {
		return fmt.Errorf("post state validation failed: %v", err)
	}

	return test.ValidateImportedHeaders(cm, validBlocks)
}
開發者ID:j4ustin,項目名稱:go-ethereum,代碼行數:52,代碼來源:block_test_util.go

示例5: MakeAccountManager

// MakeChain creates an account manager from set command line flags.
func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
	dataDir := MustDataDir(ctx)
	if ctx.GlobalBool(TestNetFlag.Name) {
		dataDir += "/testnet"
	}
	scryptN := crypto.StandardScryptN
	scryptP := crypto.StandardScryptP
	if ctx.GlobalBool(LightKDFFlag.Name) {
		scryptN = crypto.LightScryptN
		scryptP = crypto.LightScryptP
	}
	ks := crypto.NewKeyStorePassphrase(filepath.Join(dataDir, "keystore"), scryptN, scryptP)
	return accounts.NewManager(ks)
}
開發者ID:General-Beck,項目名稱:go-ethereum,代碼行數:15,代碼來源:flags.go

示例6: MakeAccountManager

// MakeAccountManager creates an account manager from set command line flags.
func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
	// Create the keystore crypto primitive, light if requested
	scryptN := crypto.StandardScryptN
	scryptP := crypto.StandardScryptP

	if ctx.GlobalBool(LightKDFFlag.Name) {
		scryptN = crypto.LightScryptN
		scryptP = crypto.LightScryptP
	}
	// Assemble an account manager using the configured datadir
	var (
		datadir  = MustMakeDataDir(ctx)
		keystore = crypto.NewKeyStorePassphrase(filepath.Join(datadir, "keystore"), scryptN, scryptP)
	)
	return accounts.NewManager(keystore)
}
開發者ID:karalabe,項目名稱:etherapis,代碼行數:17,代碼來源:flags.go

示例7: gethkey

func gethkey(ctx *cli.Context) {
	account := ctx.Args().First()
	if len(account) == 0 {
		utils.Fatalf("account address must be given as first argument")
	}
	keyfile := ctx.Args().Get(1)
	if len(keyfile) == 0 {
		utils.Fatalf("keyfile must be given as second argument")
	}
	keydir := ctx.GlobalString(keyDirFlag.Name)
	ks := crypto.NewKeyStorePassphrase(keydir)
	am := accounts.NewManager(ks)
	auth := unlockAccount(ctx, am, account)

	err := am.Export(keyfile, common.FromHex(account), auth)
	if err != nil {
		utils.Fatalf("Account export failed: %v", err)
	}
}
開發者ID:quukie,項目名稱:eth-utils,代碼行數:19,代碼來源:main.go

示例8: testEth

func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) {

	os.RemoveAll("/tmp/eth-natspec/")

	err = os.MkdirAll("/tmp/eth-natspec/keystore", os.ModePerm)
	if err != nil {
		panic(err)
	}

	// create a testAddress
	ks := crypto.NewKeyStorePassphrase("/tmp/eth-natspec/keystore")
	am := accounts.NewManager(ks)
	testAccount, err := am.NewAccount("password")
	if err != nil {
		panic(err)
	}

	testAddress := strings.TrimPrefix(testAccount.Address.Hex(), "0x")

	db, _ := ethdb.NewMemDatabase()
	// set up mock genesis with balance on the testAddress
	core.WriteGenesisBlockForTesting(db, core.GenesisAccount{common.HexToAddress(testAddress), common.String2Big(testBalance)})

	// only use minimalistic stack with no networking
	ethereum, err = eth.New(&eth.Config{
		DataDir:        "/tmp/eth-natspec",
		AccountManager: am,
		MaxPeers:       0,
		PowTest:        true,
		Etherbase:      common.HexToAddress(testAddress),
		NewDB:          func(path string) (ethdb.Database, error) { return db, nil },
	})

	if err != nil {
		panic(err)
	}

	return
}
開發者ID:NikonMcFly,項目名稱:go-ethereum,代碼行數:39,代碼來源:natspec_e2e_test.go

示例9: testEth

func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) {

	tmp, err := ioutil.TempDir("", "natspec-test")
	if err != nil {
		t.Fatal(err)
	}
	db, _ := ethdb.NewMemDatabase()
	addr := common.HexToAddress(testAddress)
	core.WriteGenesisBlockForTesting(db, core.GenesisAccount{addr, common.String2Big(testBalance)})
	ks := crypto.NewKeyStorePassphrase(filepath.Join(tmp, "keystore"), crypto.LightScryptN, crypto.LightScryptP)
	am := accounts.NewManager(ks)
	keyb, err := crypto.HexToECDSA(testKey)
	if err != nil {
		t.Fatal(err)
	}
	key := crypto.NewKeyFromECDSA(keyb)
	err = ks.StoreKey(key, "")
	if err != nil {
		t.Fatal(err)
	}

	err = am.Unlock(key.Address, "")
	if err != nil {
		t.Fatal(err)
	}

	// only use minimalistic stack with no networking
	return eth.New(&eth.Config{
		DataDir:                 tmp,
		AccountManager:          am,
		Etherbase:               common.HexToAddress(testAddress),
		MaxPeers:                0,
		PowTest:                 true,
		NewDB:                   func(path string) (ethdb.Database, error) { return db, nil },
		GpoMinGasPrice:          common.Big1,
		GpobaseCorrectionFactor: 1,
		GpoMaxGasPrice:          common.Big1,
	})
}
開發者ID:j4ustin,項目名稱:go-ethereum,代碼行數:39,代碼來源:natspec_e2e_test.go

示例10: testEth

func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) {

	os.RemoveAll("/tmp/eth-natspec/")

	err = os.MkdirAll("/tmp/eth-natspec/keystore", os.ModePerm)
	if err != nil {
		panic(err)
	}

	// create a testAddress
	ks := crypto.NewKeyStorePassphrase("/tmp/eth-natspec/keystore")
	am := accounts.NewManager(ks)
	testAccount, err := am.NewAccount("password")
	if err != nil {
		panic(err)
	}
	testAddress := strings.TrimPrefix(testAccount.Address.Hex(), "0x")

	// set up mock genesis with balance on the testAddress
	core.GenesisAccounts = []byte(`{
	"` + testAddress + `": {"balance": "` + testBalance + `"}
	}`)

	// only use minimalistic stack with no networking
	ethereum, err = eth.New(&eth.Config{
		DataDir:        "/tmp/eth-natspec",
		AccountManager: am,
		MaxPeers:       0,
		PowTest:        true,
		Etherbase:      common.HexToAddress(testAddress),
	})

	if err != nil {
		panic(err)
	}

	return
}
開發者ID:ruflin,項目名稱:go-ethereum,代碼行數:38,代碼來源:natspec_e2e_test.go

示例11: GetAccountManager

func GetAccountManager(ctx *cli.Context) *accounts.Manager {
	dataDir := ctx.GlobalString(DataDirFlag.Name)
	ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys"))
	return accounts.NewManager(ks)
}
開發者ID:CedarLogic,項目名稱:go-ethereum,代碼行數:5,代碼來源:flags.go


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