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


Golang btcutil.AppDataDir函數代碼示例

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


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

示例1: main

func main() {
	fmt.Println("Creating random rpc config for btcd")
	t := template.Must(template.New("rpcOptions").Parse(autoRpcTemplate))

	randRpcOptions := basicRpcOptions{
		Username: randBase64string(*numRandBytes),
		Password: randBase64string(*numRandBytes),
	}

	var autoAuth bytes.Buffer
	if err := t.Execute(&autoAuth, randRpcOptions); err != nil {
		log.Fatalf("unable to generate random auth: %v")
	}

	btcdHomeDir := btcutil.AppDataDir("btcd", false)
	btcctlHomeDir := btcutil.AppDataDir("btcctl", false)
	btcdConfigPath := fmt.Sprintf("%s/btcd.conf", btcdHomeDir)
	btcctlConfigPath := fmt.Sprintf("%s/btcctl.conf", btcctlHomeDir)

	if err := ioutil.WriteFile(btcdConfigPath, autoAuth.Bytes(), 0644); err != nil {
		log.Fatalf("unable to write config for btcd: %v", err)
	}

	if err := ioutil.WriteFile(btcctlConfigPath, autoAuth.Bytes(), 0644); err != nil {
		log.Fatalf("unable to write config for btcctl: %v", err)
	}
	fmt.Println("fin.")
}
開發者ID:Roasbeef,項目名稱:btcd-in-a-box,代碼行數:28,代碼來源:initrpc.go

示例2: main

func main() {
	flag.Parse()

	// Connect to local btcd RPC server
	btcdHomeDir := btcutil.AppDataDir("btcd", false)
	certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
	if err != nil {
		log.Fatal(err)
	}
	connCfg := &btcrpcclient.ConnConfig{
		Host:         *host,
		Endpoint:     *protocol,
		User:         *user,
		Pass:         *pass,
		Certificates: certs,
	}
	client, err := btcrpcclient.New(connCfg, nil)
	if err != nil {
		log.Fatal(err)
	}
	addr, err := btcutil.DecodeAddress("1JZJaDDC44DCKLnezDsbW43Zf8LspCKBYP", nil)
	if err != nil {
		log.Fatal(err)
	}
	log.Println(btcinterned.LookupAddress(client, addr, btcinterned.SixMonths))
}
開發者ID:d4l3k,項目名稱:btcinterned,代碼行數:26,代碼來源:main.go

示例3: NewClient

func NewClient() (*btcrpcclient.Client, error) {
	var cerr error
	launchOnce.Do(func() {
		defer launchWG.Done()
		password := randString(40)
		go launchProc("btcd", "--testnet", "-u", RPCUser, "-P", password)
		go launchProc("btcwallet", "-u", RPCUser, "-P", password)

		time.Sleep(2 * time.Second)

		btcdHomeDir := btcutil.AppDataDir("btcd", false)
		certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
		if err != nil {
			cerr = err
			return
		}
		connCfg := &btcrpcclient.ConnConfig{
			Host:         "localhost:18334",
			Endpoint:     "ws",
			User:         RPCUser,
			Pass:         password,
			Certificates: certs,
		}
		_ = connCfg
		client, err = btcrpcclient.New(connCfg, nil) // handlers)
		if err != nil {
			cerr = err
			return
		}
	})
	launchWG.Wait()
	return client, cerr
}
開發者ID:nonempty,項目名稱:degdb,代碼行數:33,代碼來源:bitcoin.go

示例4: 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 *wire.ShaHash, height int32, time time.Time) {
			log.Printf("Block connected: %v (%d) %v", hash, height, time)
		},
		OnBlockDisconnected: func(hash *wire.ShaHash, height int32, time time.Time) {
			log.Printf("Block disconnected: %v (%d) %v", hash, height, time)
		},
	}

	// 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:murrekatt,項目名稱:btcrpcclient,代碼行數:59,代碼來源:main.go

示例5: GetBtcdConfig

func GetBtcdConfig() (cfg config, err error) {
	btcdHomeDir := btcutil.AppDataDir("btcd", false)
	defaultConfigFile := filepath.Join(btcdHomeDir, "btcd.conf")
	cfg = config{
		ConfigFile: defaultConfigFile,
	}
	parser := flags.NewParser(&cfg, flags.Default)
	err = flags.NewIniParser(parser).ParseFile(cfg.ConfigFile)
	return
}
開發者ID:mkl-,項目名稱:lnd,代碼行數:10,代碼來源:btcdconf.go

示例6: main

func main() {
	// Only override the handlers for notifications you care about.
	// Also note most of the 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{
		OnAccountBalance: func(account string, balance btcutil.Amount, confirmed bool) {
			log.Printf("New balance for account %s: %v", account,
				balance)
		},
	}

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

	// Get the list of unspent transaction outputs (utxos) that the
	// connected wallet has at least one private key for.
	unspent, err := client.ListUnspent()
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Num unspent outputs (utxos): %d", len(unspent))
	if len(unspent) > 0 {
		log.Printf("First utxo:\n%v", spew.Sdump(unspent[0]))
	}

	// 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:Wishing-Wall,項目名稱:wishingwall,代碼行數:55,代碼來源:main.go

示例7: 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:Wishing-Wall,項目名稱:wishingwall,代碼行數:14,代碼來源:gencerts.go

示例8:

	"github.com/btcsuite/btcd/database"
	_ "github.com/btcsuite/btcd/database/ldb"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
	flags "github.com/btcsuite/go-flags"
)

const (
	minCandidates        = 1
	maxCandidates        = 20
	defaultNumCandidates = 5
	defaultDbType        = "leveldb"
)

var (
	btcdHomeDir     = btcutil.AppDataDir("btcd", false)
	defaultDataDir  = filepath.Join(btcdHomeDir, "data")
	knownDbTypes    = database.SupportedDBs()
	activeNetParams = &chaincfg.MainNetParams
)

// config defines the configuration options for findcheckpoint.
//
// See loadConfig for details on the configuration load process.
type config struct {
	DataDir        string `short:"b" long:"datadir" description:"Location of the btcd data directory"`
	DbType         string `long:"dbtype" description:"Database backend to use for the Block Chain"`
	TestNet3       bool   `long:"testnet" description:"Use the test network"`
	RegressionTest bool   `long:"regtest" description:"Use the regression test network"`
	SimNet         bool   `long:"simnet" description:"Use the simulation test network"`
	NumCandidates  int    `short:"n" long:"numcandidates" description:"Max num of checkpoint candidates to show {1-20}"`
開發者ID:Wishing-Wall,項目名稱:wishingwall,代碼行數:31,代碼來源:config.go

示例9:

	// defaultPubPassphrase is the default public wallet passphrase which is
	// used when the user indicates they do not want additional protection
	// provided by having all public data in the wallet encrypted by a
	// passphrase only known to them.
	defaultPubPassphrase = "public"

	// maxEmptyAccounts is the number of accounts to scan even if they have no
	// transaction history. This is a deviation from BIP044 to make account
	// creation easier by allowing a limited number of empty accounts.
	maxEmptyAccounts = 100

	walletDbName = "wallet.db"
)

var (
	btcdHomeDir        = btcutil.AppDataDir("btcd", false)
	btcwalletHomeDir   = btcutil.AppDataDir("btcwallet", false)
	btcdHomedirCAFile  = filepath.Join(btcdHomeDir, "rpc.cert")
	defaultConfigFile  = filepath.Join(btcwalletHomeDir, defaultConfigFilename)
	defaultDataDir     = btcwalletHomeDir
	defaultRPCKeyFile  = filepath.Join(btcwalletHomeDir, "rpc.key")
	defaultRPCCertFile = filepath.Join(btcwalletHomeDir, "rpc.cert")
	defaultLogDir      = filepath.Join(btcwalletHomeDir, defaultLogDirname)
)

type config struct {
	ShowVersion      bool     `short:"V" long:"version" description:"Display version information and exit"`
	Create           bool     `long:"create" description:"Create the wallet if it does not exist"`
	CreateTemp       bool     `long:"createtemp" description:"Create a temporary simulation wallet (pass=password) in the data directory indicated; must call with --datadir"`
	CAFile           string   `long:"cafile" description:"File containing root certificates to authenticate a TLS connections with btcd"`
	RPCConnect       string   `short:"c" long:"rpcconnect" description:"Hostname/IP and port of btcd RPC server to connect to (default localhost:18334, mainnet: localhost:8334, simnet: localhost:18556)"`
開發者ID:runeaune,項目名稱:btcwallet,代碼行數:31,代碼來源:config.go

示例10:

// 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:hfeeki,項目名稱:blocksafari,代碼行數:31,代碼來源:config.go

示例11: fatalf

	"github.com/btcsuite/btcd/btcjson"
	"github.com/btcsuite/btcd/chaincfg/chainhash"
	"github.com/btcsuite/btcd/txscript"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcrpcclient"
	"github.com/btcsuite/btcutil"
	"github.com/btcsuite/btcwallet/internal/cfgutil"
	"github.com/btcsuite/btcwallet/netparams"
	"github.com/btcsuite/btcwallet/wallet/txauthor"
	"github.com/btcsuite/btcwallet/wallet/txrules"
	"github.com/btcsuite/golangcrypto/ssh/terminal"
	"github.com/jessevdk/go-flags"
)

var (
	walletDataDirectory = btcutil.AppDataDir("btcwallet", false)
	newlineBytes        = []byte{'\n'}
)

func fatalf(format string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, format, args...)
	os.Stderr.Write(newlineBytes)
	os.Exit(1)
}

func errContext(err error, context string) error {
	return fmt.Errorf("%s: %v", context, err)
}

// Flags.
var opts = struct {
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:31,代碼來源:main.go

示例12: init

	maxBlockSize = flag.Int("maxblocksize", 999000, "Maximum block size in bytes used by the miner")

	// maxSplit defines the maximum number of pieces to divide a utxo into
	maxSplit = flag.Int("maxsplit", 100, "Maximum number of pieces to divide a utxo into")

	// profile
	profile = flag.String("profile", "6060", "Listen address for profiling server")

	// txCurvePath is the path to a CSV file containing the block, utxo count, tx count
	txCurvePath = flag.String("txcurve", "",
		"Path to the CSV File containing block, utxo count, tx count fields")
)

var (
	// AppDataDir is the path to the working directory set using btcutil.AppDataDir
	AppDataDir = btcutil.AppDataDir("btcsim", false)

	// CertFile is the path to the certificate file of a cert-key pair used for RPC connections
	CertFile = filepath.Join(AppDataDir, "rpc.cert")

	// KeyFile is the path to the key file of a cert-key pair used for RPC connections
	KeyFile = filepath.Join(AppDataDir, "rpc.key")
)

func init() {
	flag.Parse()

	// make sure the app data dir exists
	if !fileExists(AppDataDir) {
		if err := os.Mkdir(AppDataDir, 0700); err != nil {
			log.Fatalf("Cannot create app data dir: %v", err)
開發者ID:stormasm,項目名稱:btcsim1020,代碼行數:31,代碼來源:main.go

示例13:

	defaultPowHandler = "parallel"

	defaultMsgExpiry        = time.Hour * 60      // 2.5 days
	defaultBroadcastExpiry  = time.Hour * 48      // 2 days
	defaultPubkeyExpiry     = time.Hour * 24 * 14 // 14 days
	defaultGetpubkeyExpiry  = time.Hour * 24 * 14 // 14 days
	defaultUnknownObjExpiry = time.Hour * 24

	defaultLogConsole = true

	defaultGenKeys = -1
)

var (
	defaultDataDir     = btcutil.AppDataDir("bmagent", false)
	bmdDataDir         = btcutil.AppDataDir("bmd", false)
	bmdHomedirCAFile   = filepath.Join(bmdDataDir, "rpc.cert")
	defaultConfigFile  = filepath.Join(defaultDataDir, defaultConfigFilename)
	defaultTLSKeyFile  = filepath.Join(defaultDataDir, "tls.key")
	defaultTLSCertFile = filepath.Join(defaultDataDir, "tls.cert")
	defaultLogDir      = filepath.Join(defaultDataDir, defaultLogDirname)
)

// Config contains the configuration information read from the command line and
// from the config file.
type Config struct {
	ShowVersion bool   `short:"V" long:"version" description:"Display version information and exit"`
	DataDir     string `short:"D" long:"datadir" description:"Directory to store key file and the data store"`
	LogDir      string `long:"logdir" description:"Directory to log output"`
開發者ID:DanielKrawisz,項目名稱:bmagent,代碼行數:29,代碼來源:config.go

示例14: init

import (
	"bufio"
	"fmt"
	"os"
	"path/filepath"

	"github.com/btcsuite/btcutil"
	"github.com/btcsuite/btcwallet/walletdb"
	_ "github.com/btcsuite/btcwallet/walletdb/bdb"
	"github.com/jessevdk/go-flags"
)

const defaultNet = "mainnet"

var datadir = btcutil.AppDataDir("btcwallet", false)

// Flags.
var opts = struct {
	Force  bool   `short:"f" description:"Force removal without prompt"`
	DbPath string `long:"db" description:"Path to wallet database"`
}{
	Force:  false,
	DbPath: filepath.Join(datadir, defaultNet, "wallet.db"),
}

func init() {
	_, err := flags.Parse(&opts)
	if err != nil {
		os.Exit(1)
	}
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:30,代碼來源:main.go

示例15:

)

const (
	defaultCAFilename       = "btcd.cert"
	defaultConfigFilename   = "btcwallet.conf"
	defaultLogLevel         = "info"
	defaultLogDirname       = "logs"
	defaultLogFilename      = "btcwallet.log"
	defaultRPCMaxClients    = 10
	defaultRPCMaxWebsockets = 25

	walletDbName = "wallet.db"
)

var (
	btcdDefaultCAFile  = filepath.Join(btcutil.AppDataDir("btcd", false), "rpc.cert")
	defaultAppDataDir  = btcutil.AppDataDir("btcwallet", false)
	defaultConfigFile  = filepath.Join(defaultAppDataDir, defaultConfigFilename)
	defaultRPCKeyFile  = filepath.Join(defaultAppDataDir, "rpc.key")
	defaultRPCCertFile = filepath.Join(defaultAppDataDir, "rpc.cert")
	defaultLogDir      = filepath.Join(defaultAppDataDir, defaultLogDirname)
)

type config struct {
	// General application behavior
	ConfigFile    *cfgutil.ExplicitString `short:"C" long:"configfile" description:"Path to configuration file"`
	ShowVersion   bool                    `short:"V" long:"version" description:"Display version information and exit"`
	Create        bool                    `long:"create" description:"Create the wallet if it does not exist"`
	CreateTemp    bool                    `long:"createtemp" description:"Create a temporary simulation wallet (pass=password) in the data directory indicated; must call with --datadir"`
	AppDataDir    *cfgutil.ExplicitString `short:"A" long:"appdata" description:"Application data directory for wallet config, databases and logs"`
	TestNet3      bool                    `long:"testnet" description:"Use the test Bitcoin network (version 3) (default mainnet)"`
開發者ID:justusranvier,項目名稱:btcwallet,代碼行數:31,代碼來源:config.go


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