当前位置: 首页>>代码示例>>Golang>>正文


Golang btcutil.AppDataDir函数代码示例

本文整理汇总了Golang中github.com/conformal/btcutil.AppDataDir函数的典型用法代码示例。如果您正苦于以下问题:Golang AppDataDir函数的具体用法?Golang AppDataDir怎么用?Golang AppDataDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了AppDataDir函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CfgFromFile

func CfgFromFile() (*btcrpcclient.ConnConfig, bool, error) {
	fileconf := &BitcoinConf{}

	path := btcutil.AppDataDir("bitcoin", false) + "/bitcoin.conf"

	parser := flags.NewParser(fileconf, flags.IgnoreUnknown)
	err := flags.NewIniParser(parser).ParseFile(path)
	if err != nil {
		return nil, false, err
	}

	if !fileconf.RPCListen {
		return nil, false, errors.New("Bitcoind not listening for rpc commands")
	}

	// TODO make rpcaddr configurable
	var rpcaddr string
	if fileconf.Testnet {
		rpcaddr = "127.0.0.1:18332"
	} else {
		rpcaddr = "127.0.0.1:8332"
	}

	// TODO use tls!
	connCfg := &btcrpcclient.ConnConfig{
		Host:         rpcaddr,
		User:         fileconf.RPCUser,
		Pass:         fileconf.RPCPassword,
		HttpPostMode: true,
		DisableTLS:   true,
	}

	return connCfg, fileconf.Testnet, nil
}
开发者ID:bclermont,项目名称:btcbuilder,代码行数:34,代码来源:txutil.go

示例2: main

func main() {
	// Only override the handlers for notifications you care about.
	// Also note most of these handlers will only be called if you register
	// for notifications.  See the documentation of the btcrpcclient
	// NotificationHandlers type for more details about each handler.
	ntfnHandlers := btcrpcclient.NotificationHandlers{
		OnBlockConnected: func(hash *btcwire.ShaHash, height int32) {
			log.Printf("Block connected: %v (%d)", hash, height)
		},
		OnBlockDisconnected: func(hash *btcwire.ShaHash, height int32) {
			log.Printf("Block disconnected: %v (%d)", hash, height)
		},
	}

	// Connect to local btcd RPC server using websockets.
	btcdHomeDir := btcutil.AppDataDir("btcd", false)
	certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
	if err != nil {
		log.Fatal(err)
	}
	connCfg := &btcrpcclient.ConnConfig{
		Host:         "localhost:8334",
		Endpoint:     "ws",
		User:         "yourrpcuser",
		Pass:         "yourrpcpass",
		Certificates: certs,
	}
	client, err := btcrpcclient.New(connCfg, &ntfnHandlers)
	if err != nil {
		log.Fatal(err)
	}

	// Register for block connect and disconnect notifications.
	if err := client.NotifyBlocks(); err != nil {
		log.Fatal(err)
	}
	log.Println("NotifyBlocks: Registration Complete")

	// Get the current block count.
	blockCount, err := client.GetBlockCount()
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Block count: %d", blockCount)

	// For this example gracefully shutdown the client after 10 seconds.
	// Ordinarily when to shutdown the client is highly application
	// specific.
	log.Println("Client shutdown in 10 seconds...")
	time.AfterFunc(time.Second*10, func() {
		log.Println("Client shutting down...")
		client.Shutdown()
		log.Println("Client shutdown complete.")
	})

	// Wait until the client either shuts down gracefully (or the user
	// terminates the process with Ctrl+C).
	client.WaitForShutdown()
}
开发者ID:awt,项目名称:btcrpcclient,代码行数:59,代码来源:main.go

示例3: cleanAndExpandPath

// cleanAndExpandPath expands environement variables and leading ~ in the
// passed path, cleans the result, and returns it.
func cleanAndExpandPath(path string) string {
	// Expand initial ~ to OS specific home directory.
	if strings.HasPrefix(path, "~") {
		appHomeDir := btcutil.AppDataDir("gencerts", false)
		homeDir := filepath.Dir(appHomeDir)
		path = strings.Replace(path, "~", homeDir, 1)
	}

	// NOTE: The os.ExpandEnv doesn't work with Windows-style %VARIABLE%,
	// but they variables can still be expanded via POSIX-style $VARIABLE.
	return filepath.Clean(os.ExpandEnv(path))
}
开发者ID:RagnarDanneskjold,项目名称:btcd,代码行数:14,代码来源:gencerts.go

示例4: main

func main() {
	flag.Parse()

	ntfnHandlers := btcrpcclient.NotificationHandlers{
		OnTxAccepted: func(hash *btcwire.ShaHash, amount btcutil.Amount) {
			h.broadcast <- []byte(strconv.FormatFloat(amount.ToUnit(0), 'f', -1, 64))
			log.Printf("Tx Accepted: %v (%s)", hash, amount.String())
		},
	}

	var certFile string
	if *rpcCert != "" {
		certFile = *rpcCert
	} else {
		btcdHomeDir := btcutil.AppDataDir("btcd", false)
		filepath.Join(btcdHomeDir, "rpc.cert")
		certFile = filepath.Join(btcdHomeDir, "rpc.cert")
	}

	certs, _ := ioutil.ReadFile(certFile)

	connCfg := &btcrpcclient.ConnConfig{
		Host:         *rpcHost,
		Endpoint:     "ws",
		User:         *rpcUser,
		Pass:         *rpcPass,
		Certificates: certs,
	}

	// Connect to btcd server
	client, err := btcrpcclient.New(connCfg, &ntfnHandlers)
	if err != nil {
		log.Fatal(err)
	}

	client.NotifyNewTransactions(false)

	// Start Websocket server
	go h.run()
	http.HandleFunc("/", serveWs)
	err = http.ListenAndServe(*address, nil)
	if err != nil {
		log.Fatal("Error starting http listener: ", err)
	}
}
开发者ID:Beldur,项目名称:btcd-ws-proxy,代码行数:45,代码来源:main.go

示例5: main

func main() {
	var (
		dataDir = flag.String("datadir", filepath.Join(btcutil.AppDataDir("btcd", false), "data"), "BTCD: Data directory")
		dbType  = flag.String("dbtype", "leveldb", "BTCD: Database backend")
	)
	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	// Setup btcdb
	log, db, dbCleanup := btcdbSetup(*dataDir, *dbType)
	defer dbCleanup()

	duplicates := search(log, db)

	realDuplicates := make(map[string][]*rData)
	for k, v := range duplicates {
		if len(v) > 1 {
			realDuplicates[k] = v
		}
	}

	resultsFile, err := os.Create("blockchainr.json")
	if err != nil {
		log.Warnf("failed to create blockchainr.json: %v", err)
		return
	}
	if json.NewEncoder(resultsFile).Encode(realDuplicates) != nil {
		log.Warnf("failed to Encode the result: %v", err)
		return
	}
}
开发者ID:stoiclabs,项目名称:blockchainr,代码行数:39,代码来源:main.go

示例6: main

type config struct {
	DataDir    string `short:"b" long:"datadir" description:"Directory to store data"`
	DbType     string `long:"dbtype" description:"Database backend"`
	TestNet3   bool   `long:"testnet" description:"Use the test network"`
	OutFile    string `short:"o" description:"outfile"`
	Progress   bool   `short:"p" description:"show progress"`
	ShaString  string `short:"s" description:"Block SHA to process" required:"true"`
	EShaString string `short:"e" description:"End Block SHA to process"`
	RawBlock   bool   `short:"r" description:"Raw Block"`
	FmtBlock   bool   `short:"f" description:"Format Block"`
	ShowTx     bool   `short:"t" description:"Show transaction"`
}

var (
	btcdHomeDir    = btcutil.AppDataDir("btcd", false)
	defaultDataDir = filepath.Join(btcdHomeDir, "data")
	log            btclog.Logger
)

const (
	ArgSha = iota
	ArgHeight
)

func main() {
	end := int64(-1)

	cfg := config{
		DbType:  "leveldb",
		DataDir: defaultDataDir,
开发者ID:hsk81,项目名称:btcd,代码行数:30,代码来源:showblock.go

示例7:

	"log"
	"net"
	"os"
	"path/filepath"
	"strings"
)

const (
	defualtCAFilename     = "btcwallet.cert"
	defaultConfigFilename = "btcgui.conf"
	defaultDataDirname    = "data"
	defaultBtcNet         = btcwire.TestNet3
)

var (
	btcguiHomeDir          = btcutil.AppDataDir("btcgui", false)
	btcwalletHomeDir       = btcutil.AppDataDir("btcwallet", false)
	defaultCAFile          = filepath.Join(btcguiHomeDir, defualtCAFilename)
	btcwalletHomedirCAFile = filepath.Join(btcwalletHomeDir, "rpc.cert")
	defaultConfigFile      = filepath.Join(btcguiHomeDir, defaultConfigFilename)
	defaultDataDir         = filepath.Join(btcguiHomeDir, defaultDataDirname)
)

type config struct {
	ShowVersion bool   `short:"V" long:"version" description:"Display version information and exit"`
	CAFile      string `long:"cafile" description:"File containing root certificates to authenticate a TLS connections with btcwallet"`
	Connect     string `short:"c" long:"connect" description:"Server and port of btcwallet instance to connect to (default localhost:18332, mainnet: localhost:8332)"`
	ConfigFile  string `short:"C" long:"configfile" description:"Path to configuration file"`
	Username    string `short:"u" long:"username" description:"Username for btcwallet authorization"`
	Password    string `short:"P" long:"password" description:"Password for btcwallet authorization"`
	MainNet     bool   `long:"mainnet" description:"Use the main Bitcoin network (default testnet3)"`
开发者ID:hsk81,项目名称:btcgui,代码行数:31,代码来源:config.go

示例8:

package main

import (
	"fmt"
	"net"
	"os"
	"path/filepath"
	"strings"

	"github.com/conformal/btcutil"
	flags "github.com/conformal/go-flags"
)

var (
	btcdHomeDir           = btcutil.AppDataDir("btcd", false)
	btcctlHomeDir         = btcutil.AppDataDir("btcctl", false)
	btcwalletHomeDir      = btcutil.AppDataDir("btcwallet", false)
	defaultConfigFile     = filepath.Join(btcctlHomeDir, "btcctl.conf")
	defaultRPCServer      = "localhost"
	defaultRPCCertFile    = filepath.Join(btcdHomeDir, "rpc.cert")
	defaultWalletCertFile = filepath.Join(btcwalletHomeDir, "rpc.cert")
)

// config defines the configuration options for btcctl.
//
// See loadConfig for details on the configuration load process.
type config struct {
	ShowVersion   bool   `short:"V" long:"version" description:"Display version information and exit"`
	ConfigFile    string `short:"C" long:"configfile" description:"Path to configuration file"`
	RPCUser       string `short:"u" long:"rpcuser" description:"RPC username"`
	RPCPassword   string `short:"P" long:"rpcpass" default-mask:"-" description:"RPC password"`
开发者ID:RagnarDanneskjold,项目名称:btcd,代码行数:31,代码来源:config.go

示例9:

// See loadConfig for details on the configuration load process.
type config struct {
	ConfigFile  string   `short:"C" long:"configfile" description:"Path to configuration file"`
	Listeners   []string `long:"listen" description:"Add an interface/port to listen on"`
	RPCCert     string   `short:"c" long:"rpccert" description:"RPC server certificate chain for validation"`
	RPCServer   string   `short:"s" long:"rpcserver" description:"IP and port for rpcserver."`
	RPCUser     string   `short:"u" long:"rpcuser" description:"rpc username."`
	RPCPassword string   `short:"P" long:"rpcpass" description:"rpc password."`
}

const (
	defaultConfigFilename = "blocksafari.conf"
)

var (
	btcdHomeDir        = btcutil.AppDataDir("btcd", false)
	bsHomeDir          = btcutil.AppDataDir("blocksafari", false)
	cfg                *config
	defaultConfigFile  = filepath.Join(bsHomeDir, defaultConfigFilename)
	defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")

	pem []byte
)

// loadConfig initializes and parses the config using a config file and command
// line options.
//
// The configuration proceeds as follows:
//      1) Start with a default config with sane settings
//      2) Pre-parse the command line to check for an alternative config file
//      3) Load configuration file overwriting defaults with any specified options
开发者ID:bryceweiner,项目名称:blocksafari,代码行数:31,代码来源:config.go


注:本文中的github.com/conformal/btcutil.AppDataDir函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。