本文整理汇总了Golang中github.com/btcsuite/btcd/btcjson.Bool函数的典型用法代码示例。如果您正苦于以下问题:Golang Bool函数的具体用法?Golang Bool怎么用?Golang Bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bool函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetBlockVerboseTxAsync
// GetBlockVerboseTxAsync returns an instance of a type that can be used to get
// the result of the RPC at some future time by invoking the Receive function on
// the returned instance.
//
// See GetBlockVerboseTx or the blocking version and more details.
func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseResult {
hash := ""
if blockHash != nil {
hash = blockHash.String()
}
cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), btcjson.Bool(true))
return c.sendCmd(cmd)
}
示例2: ExampleMarshalCmd
// This example demonstrates how to create and marshal a command into a JSON-RPC
// request.
func ExampleMarshalCmd() {
// Create a new getblock command. Notice the nil parameter indicates
// to use the default parameter for that fields. This is a common
// pattern used in all of the New<Foo>Cmd functions in this package for
// optional fields. Also, notice the call to btcjson.Bool which is a
// convenience function for creating a pointer out of a primitive for
// optional parameters.
blockHash := "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
gbCmd := btcjson.NewGetBlockCmd(blockHash, btcjson.Bool(false), nil)
// Marshal the command to the format suitable for sending to the RPC
// server. Typically the client would increment the id here which is
// request so the response can be identified.
id := 1
marshalledBytes, err := btcjson.MarshalCmd(id, gbCmd)
if err != nil {
fmt.Println(err)
return
}
// Display the marshalled command. Ordinarily this would be sent across
// the wire to the RPC server, but for this example, just display it.
fmt.Printf("%s\n", marshalledBytes)
// Output:
// {"jsonrpc":"1.0","method":"getblock","params":["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",false],"id":1}
}
示例3: GetBlockAsync
// GetBlockAsync returns an instance of a type that can be used to get the
// result of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See GetBlock for the blocking version and more details.
func (c *Client) GetBlockAsync(blockHash *chainhash.Hash) FutureGetBlockResult {
hash := ""
if blockHash != nil {
hash = blockHash.String()
}
cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(false), nil)
return c.sendCmd(cmd)
}
示例4: GetBlockVerboseAsync
// GetBlockVerboseAsync returns an instance of a type that can be used to get
// the result of the RPC at some future time by invoking the Receive function on
// the returned instance.
//
// See GetBlockVerbose for the blocking version and more details.
func (c *Client) GetBlockVerboseAsync(blockHash *wire.ShaHash, verboseTx bool) FutureGetBlockVerboseResult {
hash := ""
if blockHash != nil {
hash = blockHash.String()
}
cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), &verboseTx)
return c.sendCmd(cmd)
}
示例5: TestWalletSvrCmds
//.........这里部分代码省略.........
return btcjson.NewGetReceivedByAddressCmd("1Address", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaddress","params":["1Address"],"id":1}`,
unmarshalled: &btcjson.GetReceivedByAddressCmd{
Address: "1Address",
MinConf: btcjson.Int(1),
},
},
{
name: "getreceivedbyaddress optional",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getreceivedbyaddress", "1Address", 6)
},
staticCmd: func() interface{} {
return btcjson.NewGetReceivedByAddressCmd("1Address", btcjson.Int(6))
},
marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaddress","params":["1Address",6],"id":1}`,
unmarshalled: &btcjson.GetReceivedByAddressCmd{
Address: "1Address",
MinConf: btcjson.Int(6),
},
},
{
name: "gettransaction",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("gettransaction", "123")
},
staticCmd: func() interface{} {
return btcjson.NewGetTransactionCmd("123", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"gettransaction","params":["123"],"id":1}`,
unmarshalled: &btcjson.GetTransactionCmd{
Txid: "123",
IncludeWatchOnly: btcjson.Bool(false),
},
},
{
name: "gettransaction optional",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("gettransaction", "123", true)
},
staticCmd: func() interface{} {
return btcjson.NewGetTransactionCmd("123", btcjson.Bool(true))
},
marshalled: `{"jsonrpc":"1.0","method":"gettransaction","params":["123",true],"id":1}`,
unmarshalled: &btcjson.GetTransactionCmd{
Txid: "123",
IncludeWatchOnly: btcjson.Bool(true),
},
},
{
name: "importprivkey",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("importprivkey", "abc")
},
staticCmd: func() interface{} {
return btcjson.NewImportPrivKeyCmd("abc", nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc"],"id":1}`,
unmarshalled: &btcjson.ImportPrivKeyCmd{
PrivKey: "abc",
Label: nil,
Rescan: btcjson.Bool(true),
},
},
{
示例6: TestChainSvrCmds
//.........这里部分代码省略.........
return btcjson.NewCmd("getaddednodeinfo", true, "127.0.0.1")
},
staticCmd: func() interface{} {
return btcjson.NewGetAddedNodeInfoCmd(true, btcjson.String("127.0.0.1"))
},
marshalled: `{"jsonrpc":"1.0","method":"getaddednodeinfo","params":[true,"127.0.0.1"],"id":1}`,
unmarshalled: &btcjson.GetAddedNodeInfoCmd{
DNS: true,
Node: btcjson.String("127.0.0.1"),
},
},
{
name: "getbestblockhash",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getbestblockhash")
},
staticCmd: func() interface{} {
return btcjson.NewGetBestBlockHashCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"getbestblockhash","params":[],"id":1}`,
unmarshalled: &btcjson.GetBestBlockHashCmd{},
},
{
name: "getblock",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getblock", "123")
},
staticCmd: func() interface{} {
return btcjson.NewGetBlockCmd("123", nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123"],"id":1}`,
unmarshalled: &btcjson.GetBlockCmd{
Hash: "123",
Verbose: btcjson.Bool(true),
VerboseTx: btcjson.Bool(false),
},
},
{
name: "getblock required optional1",
newCmd: func() (interface{}, error) {
// Intentionally use a source param that is
// more pointers than the destination to
// exercise that path.
verbosePtr := btcjson.Bool(true)
return btcjson.NewCmd("getblock", "123", &verbosePtr)
},
staticCmd: func() interface{} {
return btcjson.NewGetBlockCmd("123", btcjson.Bool(true), nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",true],"id":1}`,
unmarshalled: &btcjson.GetBlockCmd{
Hash: "123",
Verbose: btcjson.Bool(true),
VerboseTx: btcjson.Bool(false),
},
},
{
name: "getblock required optional2",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getblock", "123", true, true)
},
staticCmd: func() interface{} {
return btcjson.NewGetBlockCmd("123", btcjson.Bool(true), btcjson.Bool(true))
},
marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123",true,true],"id":1}`,
unmarshalled: &btcjson.GetBlockCmd{
示例7: TestChainSvrWsCmds
// TestChainSvrWsCmds tests all of the chain server websocket-specific commands
// marshal and unmarshal into valid results include handling of optional fields
// being omitted in the marshalled command, while optional fields with defaults
// have the default assigned on unmarshalled commands.
func TestChainSvrWsCmds(t *testing.T) {
t.Parallel()
testID := int(1)
tests := []struct {
name string
newCmd func() (interface{}, error)
staticCmd func() interface{}
marshalled string
unmarshalled interface{}
}{
{
name: "authenticate",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("authenticate", "user", "pass")
},
staticCmd: func() interface{} {
return btcjson.NewAuthenticateCmd("user", "pass")
},
marshalled: `{"jsonrpc":"1.0","method":"authenticate","params":["user","pass"],"id":1}`,
unmarshalled: &btcjson.AuthenticateCmd{Username: "user", Passphrase: "pass"},
},
{
name: "notifyblocks",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("notifyblocks")
},
staticCmd: func() interface{} {
return btcjson.NewNotifyBlocksCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"notifyblocks","params":[],"id":1}`,
unmarshalled: &btcjson.NotifyBlocksCmd{},
},
{
name: "stopnotifyblocks",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("stopnotifyblocks")
},
staticCmd: func() interface{} {
return btcjson.NewStopNotifyBlocksCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"stopnotifyblocks","params":[],"id":1}`,
unmarshalled: &btcjson.StopNotifyBlocksCmd{},
},
{
name: "notifynewtransactions",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("notifynewtransactions")
},
staticCmd: func() interface{} {
return btcjson.NewNotifyNewTransactionsCmd(nil)
},
marshalled: `{"jsonrpc":"1.0","method":"notifynewtransactions","params":[],"id":1}`,
unmarshalled: &btcjson.NotifyNewTransactionsCmd{
Verbose: btcjson.Bool(false),
},
},
{
name: "notifynewtransactions optional",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("notifynewtransactions", true)
},
staticCmd: func() interface{} {
return btcjson.NewNotifyNewTransactionsCmd(btcjson.Bool(true))
},
marshalled: `{"jsonrpc":"1.0","method":"notifynewtransactions","params":[true],"id":1}`,
unmarshalled: &btcjson.NotifyNewTransactionsCmd{
Verbose: btcjson.Bool(true),
},
},
{
name: "stopnotifynewtransactions",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("stopnotifynewtransactions")
},
staticCmd: func() interface{} {
return btcjson.NewStopNotifyNewTransactionsCmd()
},
marshalled: `{"jsonrpc":"1.0","method":"stopnotifynewtransactions","params":[],"id":1}`,
unmarshalled: &btcjson.StopNotifyNewTransactionsCmd{},
},
{
name: "notifyreceived",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("notifyreceived", []string{"1Address"})
},
staticCmd: func() interface{} {
return btcjson.NewNotifyReceivedCmd([]string{"1Address"})
},
marshalled: `{"jsonrpc":"1.0","method":"notifyreceived","params":[["1Address"]],"id":1}`,
unmarshalled: &btcjson.NotifyReceivedCmd{
Addresses: []string{"1Address"},
},
},
{
name: "stopnotifyreceived",
//.........这里部分代码省略.........
示例8: GetRawMempoolVerboseAsync
// GetRawMempoolVerboseAsync returns an instance of a type that can be used to
// get the result of the RPC at some future time by invoking the Receive
// function on the returned instance.
//
// See GetRawMempoolVerbose for the blocking version and more details.
func (c *Client) GetRawMempoolVerboseAsync() FutureGetRawMempoolVerboseResult {
cmd := btcjson.NewGetRawMempoolCmd(btcjson.Bool(true))
return c.sendCmd(cmd)
}
示例9: GetRawMempoolAsync
// GetRawMempoolAsync returns an instance of a type that can be used to get the
// result of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See GetRawMempool for the blocking version and more details.
func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult {
cmd := btcjson.NewGetRawMempoolCmd(btcjson.Bool(false))
return c.sendCmd(cmd)
}
示例10: TestHelpers
// TestHelpers tests the various helper functions which create pointers to
// primitive types.
func TestHelpers(t *testing.T) {
t.Parallel()
tests := []struct {
name string
f func() interface{}
expected interface{}
}{
{
name: "bool",
f: func() interface{} {
return btcjson.Bool(true)
},
expected: func() interface{} {
val := true
return &val
}(),
},
{
name: "int",
f: func() interface{} {
return btcjson.Int(5)
},
expected: func() interface{} {
val := int(5)
return &val
}(),
},
{
name: "uint",
f: func() interface{} {
return btcjson.Uint(5)
},
expected: func() interface{} {
val := uint(5)
return &val
}(),
},
{
name: "int32",
f: func() interface{} {
return btcjson.Int32(5)
},
expected: func() interface{} {
val := int32(5)
return &val
}(),
},
{
name: "uint32",
f: func() interface{} {
return btcjson.Uint32(5)
},
expected: func() interface{} {
val := uint32(5)
return &val
}(),
},
{
name: "int64",
f: func() interface{} {
return btcjson.Int64(5)
},
expected: func() interface{} {
val := int64(5)
return &val
}(),
},
{
name: "uint64",
f: func() interface{} {
return btcjson.Uint64(5)
},
expected: func() interface{} {
val := uint64(5)
return &val
}(),
},
{
name: "string",
f: func() interface{} {
return btcjson.String("abc")
},
expected: func() interface{} {
val := "abc"
return &val
}(),
},
}
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
result := test.f()
if !reflect.DeepEqual(result, test.expected) {
t.Errorf("Test #%d (%s) unexpected value - got %v, "+
"want %v", i, test.name, result, test.expected)
continue
}
//.........这里部分代码省略.........
示例11: TestBtcWalletExtCmds
// TestBtcWalletExtCmds tests all of the btcwallet extended commands marshal and
// unmarshal into valid results include handling of optional fields being
// omitted in the marshalled command, while optional fields with defaults have
// the default assigned on unmarshalled commands.
func TestBtcWalletExtCmds(t *testing.T) {
t.Parallel()
testID := int(1)
tests := []struct {
name string
newCmd func() (interface{}, error)
staticCmd func() interface{}
marshalled string
unmarshalled interface{}
}{
{
name: "createnewaccount",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("createnewaccount", "acct")
},
staticCmd: func() interface{} {
return btcjson.NewCreateNewAccountCmd("acct")
},
marshalled: `{"jsonrpc":"1.0","method":"createnewaccount","params":["acct"],"id":1}`,
unmarshalled: &btcjson.CreateNewAccountCmd{
Account: "acct",
},
},
{
name: "dumpwallet",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("dumpwallet", "filename")
},
staticCmd: func() interface{} {
return btcjson.NewDumpWalletCmd("filename")
},
marshalled: `{"jsonrpc":"1.0","method":"dumpwallet","params":["filename"],"id":1}`,
unmarshalled: &btcjson.DumpWalletCmd{
Filename: "filename",
},
},
{
name: "importaddress",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("importaddress", "1Address")
},
staticCmd: func() interface{} {
return btcjson.NewImportAddressCmd("1Address", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"importaddress","params":["1Address"],"id":1}`,
unmarshalled: &btcjson.ImportAddressCmd{
Address: "1Address",
Rescan: btcjson.Bool(true),
},
},
{
name: "importaddress optional",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("importaddress", "1Address", false)
},
staticCmd: func() interface{} {
return btcjson.NewImportAddressCmd("1Address", btcjson.Bool(false))
},
marshalled: `{"jsonrpc":"1.0","method":"importaddress","params":["1Address",false],"id":1}`,
unmarshalled: &btcjson.ImportAddressCmd{
Address: "1Address",
Rescan: btcjson.Bool(false),
},
},
{
name: "importpubkey",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("importpubkey", "031234")
},
staticCmd: func() interface{} {
return btcjson.NewImportPubKeyCmd("031234", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"importpubkey","params":["031234"],"id":1}`,
unmarshalled: &btcjson.ImportPubKeyCmd{
PubKey: "031234",
Rescan: btcjson.Bool(true),
},
},
{
name: "importpubkey optional",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("importpubkey", "031234", false)
},
staticCmd: func() interface{} {
return btcjson.NewImportPubKeyCmd("031234", btcjson.Bool(false))
},
marshalled: `{"jsonrpc":"1.0","method":"importpubkey","params":["031234",false],"id":1}`,
unmarshalled: &btcjson.ImportPubKeyCmd{
PubKey: "031234",
Rescan: btcjson.Bool(false),
},
},
{
name: "importwallet",
newCmd: func() (interface{}, error) {
//.........这里部分代码省略.........
示例12: ExportWatchingWalletAsync
// ExportWatchingWalletAsync returns an instance of a type that can be used to
// get the result of the RPC at some future time by invoking the Receive
// function on the returned instance.
//
// See ExportWatchingWallet for the blocking version and more details.
//
// NOTE: This is a btcwallet extension.
func (c *Client) ExportWatchingWalletAsync(account string) FutureExportWatchingWalletResult {
cmd := btcjson.NewExportWatchingWalletCmd(&account, btcjson.Bool(true))
return c.sendCmd(cmd)
}
示例13: TestWalletSvrWsCmds
// TestWalletSvrWsCmds tests all of the wallet server websocket-specific
// commands marshal and unmarshal into valid results include handling of
// optional fields being omitted in the marshalled command, while optional
// fields with defaults have the default assigned on unmarshalled commands.
func TestWalletSvrWsCmds(t *testing.T) {
t.Parallel()
testID := int(1)
tests := []struct {
name string
newCmd func() (interface{}, error)
staticCmd func() interface{}
marshalled string
unmarshalled interface{}
}{
{
name: "createencryptedwallet",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("createencryptedwallet", "pass")
},
staticCmd: func() interface{} {
return btcjson.NewCreateEncryptedWalletCmd("pass")
},
marshalled: `{"jsonrpc":"1.0","method":"createencryptedwallet","params":["pass"],"id":1}`,
unmarshalled: &btcjson.CreateEncryptedWalletCmd{Passphrase: "pass"},
},
{
name: "exportwatchingwallet",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("exportwatchingwallet")
},
staticCmd: func() interface{} {
return btcjson.NewExportWatchingWalletCmd(nil, nil)
},
marshalled: `{"jsonrpc":"1.0","method":"exportwatchingwallet","params":[],"id":1}`,
unmarshalled: &btcjson.ExportWatchingWalletCmd{
Account: nil,
Download: btcjson.Bool(false),
},
},
{
name: "exportwatchingwallet optional1",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("exportwatchingwallet", "acct")
},
staticCmd: func() interface{} {
return btcjson.NewExportWatchingWalletCmd(btcjson.String("acct"), nil)
},
marshalled: `{"jsonrpc":"1.0","method":"exportwatchingwallet","params":["acct"],"id":1}`,
unmarshalled: &btcjson.ExportWatchingWalletCmd{
Account: btcjson.String("acct"),
Download: btcjson.Bool(false),
},
},
{
name: "exportwatchingwallet optional2",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("exportwatchingwallet", "acct", true)
},
staticCmd: func() interface{} {
return btcjson.NewExportWatchingWalletCmd(btcjson.String("acct"),
btcjson.Bool(true))
},
marshalled: `{"jsonrpc":"1.0","method":"exportwatchingwallet","params":["acct",true],"id":1}`,
unmarshalled: &btcjson.ExportWatchingWalletCmd{
Account: btcjson.String("acct"),
Download: btcjson.Bool(true),
},
},
{
name: "getunconfirmedbalance",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getunconfirmedbalance")
},
staticCmd: func() interface{} {
return btcjson.NewGetUnconfirmedBalanceCmd(nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getunconfirmedbalance","params":[],"id":1}`,
unmarshalled: &btcjson.GetUnconfirmedBalanceCmd{
Account: nil,
},
},
{
name: "getunconfirmedbalance optional1",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getunconfirmedbalance", "acct")
},
staticCmd: func() interface{} {
return btcjson.NewGetUnconfirmedBalanceCmd(btcjson.String("acct"))
},
marshalled: `{"jsonrpc":"1.0","method":"getunconfirmedbalance","params":["acct"],"id":1}`,
unmarshalled: &btcjson.GetUnconfirmedBalanceCmd{
Account: btcjson.String("acct"),
},
},
{
name: "listaddresstransactions",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("listaddresstransactions", `["1Address"]`)
},
//.........这里部分代码省略.........