repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
btcsuite/btcd
rpcclient/wallet.go
GetUnconfirmedBalanceAsync
func (c *Client) GetUnconfirmedBalanceAsync(account string) FutureGetUnconfirmedBalanceResult { cmd := btcjson.NewGetUnconfirmedBalanceCmd(&account) return c.sendCmd(cmd) }
go
func (c *Client) GetUnconfirmedBalanceAsync(account string) FutureGetUnconfirmedBalanceResult { cmd := btcjson.NewGetUnconfirmedBalanceCmd(&account) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "GetUnconfirmedBalanceAsync", "(", "account", "string", ")", "FutureGetUnconfirmedBalanceResult", "{", "cmd", ":=", "btcjson", ".", "NewGetUnconfirmedBalanceCmd", "(", "&", "account", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// GetUnconfirmedBalanceAsync 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 GetUnconfirmedBalance for the blocking version and more details.
[ "GetUnconfirmedBalanceAsync", "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", "GetUnconfirmedBalance", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1608-L1611
train
btcsuite/btcd
rpcclient/wallet.go
GetUnconfirmedBalance
func (c *Client) GetUnconfirmedBalance(account string) (btcutil.Amount, error) { return c.GetUnconfirmedBalanceAsync(account).Receive() }
go
func (c *Client) GetUnconfirmedBalance(account string) (btcutil.Amount, error) { return c.GetUnconfirmedBalanceAsync(account).Receive() }
[ "func", "(", "c", "*", "Client", ")", "GetUnconfirmedBalance", "(", "account", "string", ")", "(", "btcutil", ".", "Amount", ",", "error", ")", "{", "return", "c", ".", "GetUnconfirmedBalanceAsync", "(", "account", ")", ".", "Receive", "(", ")", "\n", "}" ]
// GetUnconfirmedBalance returns the unconfirmed balance from the server for // the specified account.
[ "GetUnconfirmedBalance", "returns", "the", "unconfirmed", "balance", "from", "the", "server", "for", "the", "specified", "account", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1615-L1617
train
btcsuite/btcd
rpcclient/wallet.go
GetReceivedByAddressAsync
func (c *Client) GetReceivedByAddressAsync(address btcutil.Address) FutureGetReceivedByAddressResult { addr := address.EncodeAddress() cmd := btcjson.NewGetReceivedByAddressCmd(addr, nil) return c.sendCmd(cmd) }
go
func (c *Client) GetReceivedByAddressAsync(address btcutil.Address) FutureGetReceivedByAddressResult { addr := address.EncodeAddress() cmd := btcjson.NewGetReceivedByAddressCmd(addr, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "GetReceivedByAddressAsync", "(", "address", "btcutil", ".", "Address", ")", "FutureGetReceivedByAddressResult", "{", "addr", ":=", "address", ".", "EncodeAddress", "(", ")", "\n", "cmd", ":=", "btcjson", ".", "NewGetReceivedByAddressCmd", "(", "addr", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n\n", "}" ]
// GetReceivedByAddressAsync 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 GetReceivedByAddress for the blocking version and more details.
[ "GetReceivedByAddressAsync", "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", "GetReceivedByAddress", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1652-L1657
train
btcsuite/btcd
rpcclient/wallet.go
GetReceivedByAddress
func (c *Client) GetReceivedByAddress(address btcutil.Address) (btcutil.Amount, error) { return c.GetReceivedByAddressAsync(address).Receive() }
go
func (c *Client) GetReceivedByAddress(address btcutil.Address) (btcutil.Amount, error) { return c.GetReceivedByAddressAsync(address).Receive() }
[ "func", "(", "c", "*", "Client", ")", "GetReceivedByAddress", "(", "address", "btcutil", ".", "Address", ")", "(", "btcutil", ".", "Amount", ",", "error", ")", "{", "return", "c", ".", "GetReceivedByAddressAsync", "(", "address", ")", ".", "Receive", "(", ")", "\n", "}" ]
// GetReceivedByAddress returns the total amount received by the specified // address with at least the default number of minimum confirmations. // // See GetReceivedByAddressMinConf to override the minimum number of // confirmations.
[ "GetReceivedByAddress", "returns", "the", "total", "amount", "received", "by", "the", "specified", "address", "with", "at", "least", "the", "default", "number", "of", "minimum", "confirmations", ".", "See", "GetReceivedByAddressMinConf", "to", "override", "the", "minimum", "number", "of", "confirmations", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1664-L1666
train
btcsuite/btcd
rpcclient/wallet.go
GetReceivedByAddressMinConfAsync
func (c *Client) GetReceivedByAddressMinConfAsync(address btcutil.Address, minConfirms int) FutureGetReceivedByAddressResult { addr := address.EncodeAddress() cmd := btcjson.NewGetReceivedByAddressCmd(addr, &minConfirms) return c.sendCmd(cmd) }
go
func (c *Client) GetReceivedByAddressMinConfAsync(address btcutil.Address, minConfirms int) FutureGetReceivedByAddressResult { addr := address.EncodeAddress() cmd := btcjson.NewGetReceivedByAddressCmd(addr, &minConfirms) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "GetReceivedByAddressMinConfAsync", "(", "address", "btcutil", ".", "Address", ",", "minConfirms", "int", ")", "FutureGetReceivedByAddressResult", "{", "addr", ":=", "address", ".", "EncodeAddress", "(", ")", "\n", "cmd", ":=", "btcjson", ".", "NewGetReceivedByAddressCmd", "(", "addr", ",", "&", "minConfirms", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// GetReceivedByAddressMinConfAsync 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 GetReceivedByAddressMinConf for the blocking version and more details.
[ "GetReceivedByAddressMinConfAsync", "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", "GetReceivedByAddressMinConf", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1673-L1677
train
btcsuite/btcd
rpcclient/wallet.go
GetReceivedByAddressMinConf
func (c *Client) GetReceivedByAddressMinConf(address btcutil.Address, minConfirms int) (btcutil.Amount, error) { return c.GetReceivedByAddressMinConfAsync(address, minConfirms).Receive() }
go
func (c *Client) GetReceivedByAddressMinConf(address btcutil.Address, minConfirms int) (btcutil.Amount, error) { return c.GetReceivedByAddressMinConfAsync(address, minConfirms).Receive() }
[ "func", "(", "c", "*", "Client", ")", "GetReceivedByAddressMinConf", "(", "address", "btcutil", ".", "Address", ",", "minConfirms", "int", ")", "(", "btcutil", ".", "Amount", ",", "error", ")", "{", "return", "c", ".", "GetReceivedByAddressMinConfAsync", "(", "address", ",", "minConfirms", ")", ".", "Receive", "(", ")", "\n", "}" ]
// GetReceivedByAddressMinConf returns the total amount received by the specified // address with at least the specified number of minimum confirmations. // // See GetReceivedByAddress to use the default minimum number of confirmations.
[ "GetReceivedByAddressMinConf", "returns", "the", "total", "amount", "received", "by", "the", "specified", "address", "with", "at", "least", "the", "specified", "number", "of", "minimum", "confirmations", ".", "See", "GetReceivedByAddress", "to", "use", "the", "default", "minimum", "number", "of", "confirmations", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1683-L1685
train
btcsuite/btcd
rpcclient/wallet.go
Receive
func (r FutureListReceivedByAccountResult) Receive() ([]btcjson.ListReceivedByAccountResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal as an array of listreceivedbyaccount result objects. var received []btcjson.ListReceivedByAccountResult err = json.Unmarshal(res, &received) if err != nil { return nil, err } return received, nil }
go
func (r FutureListReceivedByAccountResult) Receive() ([]btcjson.ListReceivedByAccountResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal as an array of listreceivedbyaccount result objects. var received []btcjson.ListReceivedByAccountResult err = json.Unmarshal(res, &received) if err != nil { return nil, err } return received, nil }
[ "func", "(", "r", "FutureListReceivedByAccountResult", ")", "Receive", "(", ")", "(", "[", "]", "btcjson", ".", "ListReceivedByAccountResult", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Unmarshal as an array of listreceivedbyaccount result objects.", "var", "received", "[", "]", "btcjson", ".", "ListReceivedByAccountResult", "\n", "err", "=", "json", ".", "Unmarshal", "(", "res", ",", "&", "received", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "received", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns a list of // balances by account.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "a", "list", "of", "balances", "by", "account", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1695-L1709
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAccountAsync
func (c *Client) ListReceivedByAccountAsync() FutureListReceivedByAccountResult { cmd := btcjson.NewListReceivedByAccountCmd(nil, nil, nil) return c.sendCmd(cmd) }
go
func (c *Client) ListReceivedByAccountAsync() FutureListReceivedByAccountResult { cmd := btcjson.NewListReceivedByAccountCmd(nil, nil, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAccountAsync", "(", ")", "FutureListReceivedByAccountResult", "{", "cmd", ":=", "btcjson", ".", "NewListReceivedByAccountCmd", "(", "nil", ",", "nil", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ListReceivedByAccountAsync 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 ListReceivedByAccount for the blocking version and more details.
[ "ListReceivedByAccountAsync", "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", "ListReceivedByAccount", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1716-L1719
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAccountMinConfAsync
func (c *Client) ListReceivedByAccountMinConfAsync(minConfirms int) FutureListReceivedByAccountResult { cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, nil, nil) return c.sendCmd(cmd) }
go
func (c *Client) ListReceivedByAccountMinConfAsync(minConfirms int) FutureListReceivedByAccountResult { cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, nil, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAccountMinConfAsync", "(", "minConfirms", "int", ")", "FutureListReceivedByAccountResult", "{", "cmd", ":=", "btcjson", ".", "NewListReceivedByAccountCmd", "(", "&", "minConfirms", ",", "nil", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ListReceivedByAccountMinConfAsync 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 ListReceivedByAccountMinConf for the blocking version and more details.
[ "ListReceivedByAccountMinConfAsync", "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", "ListReceivedByAccountMinConf", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1737-L1740
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAccountMinConf
func (c *Client) ListReceivedByAccountMinConf(minConfirms int) ([]btcjson.ListReceivedByAccountResult, error) { return c.ListReceivedByAccountMinConfAsync(minConfirms).Receive() }
go
func (c *Client) ListReceivedByAccountMinConf(minConfirms int) ([]btcjson.ListReceivedByAccountResult, error) { return c.ListReceivedByAccountMinConfAsync(minConfirms).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAccountMinConf", "(", "minConfirms", "int", ")", "(", "[", "]", "btcjson", ".", "ListReceivedByAccountResult", ",", "error", ")", "{", "return", "c", ".", "ListReceivedByAccountMinConfAsync", "(", "minConfirms", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ListReceivedByAccountMinConf lists balances by account using the specified // number of minimum confirmations not including accounts that haven't received // any payments. // // See ListReceivedByAccount to use the default minimum number of confirmations // and ListReceivedByAccountIncludeEmpty to also include accounts that haven't // received any payments in the results.
[ "ListReceivedByAccountMinConf", "lists", "balances", "by", "account", "using", "the", "specified", "number", "of", "minimum", "confirmations", "not", "including", "accounts", "that", "haven", "t", "received", "any", "payments", ".", "See", "ListReceivedByAccount", "to", "use", "the", "default", "minimum", "number", "of", "confirmations", "and", "ListReceivedByAccountIncludeEmpty", "to", "also", "include", "accounts", "that", "haven", "t", "received", "any", "payments", "in", "the", "results", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1749-L1751
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAccountIncludeEmptyAsync
func (c *Client) ListReceivedByAccountIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAccountResult { cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, &includeEmpty, nil) return c.sendCmd(cmd) }
go
func (c *Client) ListReceivedByAccountIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAccountResult { cmd := btcjson.NewListReceivedByAccountCmd(&minConfirms, &includeEmpty, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAccountIncludeEmptyAsync", "(", "minConfirms", "int", ",", "includeEmpty", "bool", ")", "FutureListReceivedByAccountResult", "{", "cmd", ":=", "btcjson", ".", "NewListReceivedByAccountCmd", "(", "&", "minConfirms", ",", "&", "includeEmpty", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ListReceivedByAccountIncludeEmptyAsync 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 ListReceivedByAccountIncludeEmpty for the blocking version and more details.
[ "ListReceivedByAccountIncludeEmptyAsync", "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", "ListReceivedByAccountIncludeEmpty", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1758-L1762
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAccountIncludeEmpty
func (c *Client) ListReceivedByAccountIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAccountResult, error) { return c.ListReceivedByAccountIncludeEmptyAsync(minConfirms, includeEmpty).Receive() }
go
func (c *Client) ListReceivedByAccountIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAccountResult, error) { return c.ListReceivedByAccountIncludeEmptyAsync(minConfirms, includeEmpty).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAccountIncludeEmpty", "(", "minConfirms", "int", ",", "includeEmpty", "bool", ")", "(", "[", "]", "btcjson", ".", "ListReceivedByAccountResult", ",", "error", ")", "{", "return", "c", ".", "ListReceivedByAccountIncludeEmptyAsync", "(", "minConfirms", ",", "includeEmpty", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ListReceivedByAccountIncludeEmpty lists balances by account using the // specified number of minimum confirmations and including accounts that // haven't received any payments depending on specified flag. // // See ListReceivedByAccount and ListReceivedByAccountMinConf to use defaults.
[ "ListReceivedByAccountIncludeEmpty", "lists", "balances", "by", "account", "using", "the", "specified", "number", "of", "minimum", "confirmations", "and", "including", "accounts", "that", "haven", "t", "received", "any", "payments", "depending", "on", "specified", "flag", ".", "See", "ListReceivedByAccount", "and", "ListReceivedByAccountMinConf", "to", "use", "defaults", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1769-L1772
train
btcsuite/btcd
rpcclient/wallet.go
Receive
func (r FutureListReceivedByAddressResult) Receive() ([]btcjson.ListReceivedByAddressResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal as an array of listreceivedbyaddress result objects. var received []btcjson.ListReceivedByAddressResult err = json.Unmarshal(res, &received) if err != nil { return nil, err } return received, nil }
go
func (r FutureListReceivedByAddressResult) Receive() ([]btcjson.ListReceivedByAddressResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal as an array of listreceivedbyaddress result objects. var received []btcjson.ListReceivedByAddressResult err = json.Unmarshal(res, &received) if err != nil { return nil, err } return received, nil }
[ "func", "(", "r", "FutureListReceivedByAddressResult", ")", "Receive", "(", ")", "(", "[", "]", "btcjson", ".", "ListReceivedByAddressResult", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Unmarshal as an array of listreceivedbyaddress result objects.", "var", "received", "[", "]", "btcjson", ".", "ListReceivedByAddressResult", "\n", "err", "=", "json", ".", "Unmarshal", "(", "res", ",", "&", "received", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "received", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns a list of // balances by address.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "a", "list", "of", "balances", "by", "address", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1782-L1796
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAddressAsync
func (c *Client) ListReceivedByAddressAsync() FutureListReceivedByAddressResult { cmd := btcjson.NewListReceivedByAddressCmd(nil, nil, nil) return c.sendCmd(cmd) }
go
func (c *Client) ListReceivedByAddressAsync() FutureListReceivedByAddressResult { cmd := btcjson.NewListReceivedByAddressCmd(nil, nil, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAddressAsync", "(", ")", "FutureListReceivedByAddressResult", "{", "cmd", ":=", "btcjson", ".", "NewListReceivedByAddressCmd", "(", "nil", ",", "nil", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ListReceivedByAddressAsync 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 ListReceivedByAddress for the blocking version and more details.
[ "ListReceivedByAddressAsync", "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", "ListReceivedByAddress", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1803-L1806
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAddressMinConfAsync
func (c *Client) ListReceivedByAddressMinConfAsync(minConfirms int) FutureListReceivedByAddressResult { cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, nil, nil) return c.sendCmd(cmd) }
go
func (c *Client) ListReceivedByAddressMinConfAsync(minConfirms int) FutureListReceivedByAddressResult { cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, nil, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAddressMinConfAsync", "(", "minConfirms", "int", ")", "FutureListReceivedByAddressResult", "{", "cmd", ":=", "btcjson", ".", "NewListReceivedByAddressCmd", "(", "&", "minConfirms", ",", "nil", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ListReceivedByAddressMinConfAsync 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 ListReceivedByAddressMinConf for the blocking version and more details.
[ "ListReceivedByAddressMinConfAsync", "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", "ListReceivedByAddressMinConf", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1824-L1827
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAddressMinConf
func (c *Client) ListReceivedByAddressMinConf(minConfirms int) ([]btcjson.ListReceivedByAddressResult, error) { return c.ListReceivedByAddressMinConfAsync(minConfirms).Receive() }
go
func (c *Client) ListReceivedByAddressMinConf(minConfirms int) ([]btcjson.ListReceivedByAddressResult, error) { return c.ListReceivedByAddressMinConfAsync(minConfirms).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAddressMinConf", "(", "minConfirms", "int", ")", "(", "[", "]", "btcjson", ".", "ListReceivedByAddressResult", ",", "error", ")", "{", "return", "c", ".", "ListReceivedByAddressMinConfAsync", "(", "minConfirms", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ListReceivedByAddressMinConf lists balances by address using the specified // number of minimum confirmations not including addresses that haven't received // any payments. // // See ListReceivedByAddress to use the default minimum number of confirmations // and ListReceivedByAddressIncludeEmpty to also include addresses that haven't // received any payments in the results.
[ "ListReceivedByAddressMinConf", "lists", "balances", "by", "address", "using", "the", "specified", "number", "of", "minimum", "confirmations", "not", "including", "addresses", "that", "haven", "t", "received", "any", "payments", ".", "See", "ListReceivedByAddress", "to", "use", "the", "default", "minimum", "number", "of", "confirmations", "and", "ListReceivedByAddressIncludeEmpty", "to", "also", "include", "addresses", "that", "haven", "t", "received", "any", "payments", "in", "the", "results", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1836-L1838
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAddressIncludeEmptyAsync
func (c *Client) ListReceivedByAddressIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAddressResult { cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, &includeEmpty, nil) return c.sendCmd(cmd) }
go
func (c *Client) ListReceivedByAddressIncludeEmptyAsync(minConfirms int, includeEmpty bool) FutureListReceivedByAddressResult { cmd := btcjson.NewListReceivedByAddressCmd(&minConfirms, &includeEmpty, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAddressIncludeEmptyAsync", "(", "minConfirms", "int", ",", "includeEmpty", "bool", ")", "FutureListReceivedByAddressResult", "{", "cmd", ":=", "btcjson", ".", "NewListReceivedByAddressCmd", "(", "&", "minConfirms", ",", "&", "includeEmpty", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ListReceivedByAddressIncludeEmptyAsync 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 ListReceivedByAccountIncludeEmpty for the blocking version and more details.
[ "ListReceivedByAddressIncludeEmptyAsync", "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", "ListReceivedByAccountIncludeEmpty", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1845-L1849
train
btcsuite/btcd
rpcclient/wallet.go
ListReceivedByAddressIncludeEmpty
func (c *Client) ListReceivedByAddressIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAddressResult, error) { return c.ListReceivedByAddressIncludeEmptyAsync(minConfirms, includeEmpty).Receive() }
go
func (c *Client) ListReceivedByAddressIncludeEmpty(minConfirms int, includeEmpty bool) ([]btcjson.ListReceivedByAddressResult, error) { return c.ListReceivedByAddressIncludeEmptyAsync(minConfirms, includeEmpty).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ListReceivedByAddressIncludeEmpty", "(", "minConfirms", "int", ",", "includeEmpty", "bool", ")", "(", "[", "]", "btcjson", ".", "ListReceivedByAddressResult", ",", "error", ")", "{", "return", "c", ".", "ListReceivedByAddressIncludeEmptyAsync", "(", "minConfirms", ",", "includeEmpty", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ListReceivedByAddressIncludeEmpty lists balances by address using the // specified number of minimum confirmations and including addresses that // haven't received any payments depending on specified flag. // // See ListReceivedByAddress and ListReceivedByAddressMinConf to use defaults.
[ "ListReceivedByAddressIncludeEmpty", "lists", "balances", "by", "address", "using", "the", "specified", "number", "of", "minimum", "confirmations", "and", "including", "addresses", "that", "haven", "t", "received", "any", "payments", "depending", "on", "specified", "flag", ".", "See", "ListReceivedByAddress", "and", "ListReceivedByAddressMinConf", "to", "use", "defaults", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1856-L1859
train
btcsuite/btcd
rpcclient/wallet.go
WalletLockAsync
func (c *Client) WalletLockAsync() FutureWalletLockResult { cmd := btcjson.NewWalletLockCmd() return c.sendCmd(cmd) }
go
func (c *Client) WalletLockAsync() FutureWalletLockResult { cmd := btcjson.NewWalletLockCmd() return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "WalletLockAsync", "(", ")", "FutureWalletLockResult", "{", "cmd", ":=", "btcjson", ".", "NewWalletLockCmd", "(", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// WalletLockAsync 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 WalletLock for the blocking version and more details.
[ "WalletLockAsync", "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", "WalletLock", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1881-L1884
train
btcsuite/btcd
rpcclient/wallet.go
WalletPassphraseChangeAsync
func (c *Client) WalletPassphraseChangeAsync(old, new string) FutureWalletPassphraseChangeResult { cmd := btcjson.NewWalletPassphraseChangeCmd(old, new) return c.sendCmd(cmd) }
go
func (c *Client) WalletPassphraseChangeAsync(old, new string) FutureWalletPassphraseChangeResult { cmd := btcjson.NewWalletPassphraseChangeCmd(old, new) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "WalletPassphraseChangeAsync", "(", "old", ",", "new", "string", ")", "FutureWalletPassphraseChangeResult", "{", "cmd", ":=", "btcjson", ".", "NewWalletPassphraseChangeCmd", "(", "old", ",", "new", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// WalletPassphraseChangeAsync 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 WalletPassphraseChange for the blocking version and more details.
[ "WalletPassphraseChangeAsync", "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", "WalletPassphraseChange", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1920-L1923
train
btcsuite/btcd
rpcclient/wallet.go
WalletPassphraseChange
func (c *Client) WalletPassphraseChange(old, new string) error { return c.WalletPassphraseChangeAsync(old, new).Receive() }
go
func (c *Client) WalletPassphraseChange(old, new string) error { return c.WalletPassphraseChangeAsync(old, new).Receive() }
[ "func", "(", "c", "*", "Client", ")", "WalletPassphraseChange", "(", "old", ",", "new", "string", ")", "error", "{", "return", "c", ".", "WalletPassphraseChangeAsync", "(", "old", ",", "new", ")", ".", "Receive", "(", ")", "\n", "}" ]
// WalletPassphraseChange changes the wallet passphrase from the specified old // to new passphrase.
[ "WalletPassphraseChange", "changes", "the", "wallet", "passphrase", "from", "the", "specified", "old", "to", "new", "passphrase", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1927-L1929
train
btcsuite/btcd
rpcclient/wallet.go
Receive
func (r FutureSignMessageResult) Receive() (string, error) { res, err := receiveFuture(r) if err != nil { return "", err } // Unmarshal result as a string. var b64 string err = json.Unmarshal(res, &b64) if err != nil { return "", err } return b64, nil }
go
func (r FutureSignMessageResult) Receive() (string, error) { res, err := receiveFuture(r) if err != nil { return "", err } // Unmarshal result as a string. var b64 string err = json.Unmarshal(res, &b64) if err != nil { return "", err } return b64, nil }
[ "func", "(", "r", "FutureSignMessageResult", ")", "Receive", "(", ")", "(", "string", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "// Unmarshal result as a string.", "var", "b64", "string", "\n", "err", "=", "json", ".", "Unmarshal", "(", "res", ",", "&", "b64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "b64", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns the message // signed with the private key of the specified address.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "the", "message", "signed", "with", "the", "private", "key", "of", "the", "specified", "address", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1941-L1955
train
btcsuite/btcd
rpcclient/wallet.go
SignMessageAsync
func (c *Client) SignMessageAsync(address btcutil.Address, message string) FutureSignMessageResult { addr := address.EncodeAddress() cmd := btcjson.NewSignMessageCmd(addr, message) return c.sendCmd(cmd) }
go
func (c *Client) SignMessageAsync(address btcutil.Address, message string) FutureSignMessageResult { addr := address.EncodeAddress() cmd := btcjson.NewSignMessageCmd(addr, message) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "SignMessageAsync", "(", "address", "btcutil", ".", "Address", ",", "message", "string", ")", "FutureSignMessageResult", "{", "addr", ":=", "address", ".", "EncodeAddress", "(", ")", "\n", "cmd", ":=", "btcjson", ".", "NewSignMessageCmd", "(", "addr", ",", "message", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// SignMessageAsync 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 SignMessage for the blocking version and more details.
[ "SignMessageAsync", "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", "SignMessage", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L1962-L1966
train
btcsuite/btcd
rpcclient/wallet.go
VerifyMessageAsync
func (c *Client) VerifyMessageAsync(address btcutil.Address, signature, message string) FutureVerifyMessageResult { addr := address.EncodeAddress() cmd := btcjson.NewVerifyMessageCmd(addr, signature, message) return c.sendCmd(cmd) }
go
func (c *Client) VerifyMessageAsync(address btcutil.Address, signature, message string) FutureVerifyMessageResult { addr := address.EncodeAddress() cmd := btcjson.NewVerifyMessageCmd(addr, signature, message) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "VerifyMessageAsync", "(", "address", "btcutil", ".", "Address", ",", "signature", ",", "message", "string", ")", "FutureVerifyMessageResult", "{", "addr", ":=", "address", ".", "EncodeAddress", "(", ")", "\n", "cmd", ":=", "btcjson", ".", "NewVerifyMessageCmd", "(", "addr", ",", "signature", ",", "message", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// VerifyMessageAsync 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 VerifyMessage for the blocking version and more details.
[ "VerifyMessageAsync", "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", "VerifyMessage", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2003-L2007
train
btcsuite/btcd
rpcclient/wallet.go
DumpPrivKeyAsync
func (c *Client) DumpPrivKeyAsync(address btcutil.Address) FutureDumpPrivKeyResult { addr := address.EncodeAddress() cmd := btcjson.NewDumpPrivKeyCmd(addr) return c.sendCmd(cmd) }
go
func (c *Client) DumpPrivKeyAsync(address btcutil.Address) FutureDumpPrivKeyResult { addr := address.EncodeAddress() cmd := btcjson.NewDumpPrivKeyCmd(addr) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "DumpPrivKeyAsync", "(", "address", "btcutil", ".", "Address", ")", "FutureDumpPrivKeyResult", "{", "addr", ":=", "address", ".", "EncodeAddress", "(", ")", "\n", "cmd", ":=", "btcjson", ".", "NewDumpPrivKeyCmd", "(", "addr", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// DumpPrivKeyAsync 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 DumpPrivKey for the blocking version and more details.
[ "DumpPrivKeyAsync", "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", "DumpPrivKey", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2049-L2053
train
btcsuite/btcd
rpcclient/wallet.go
ImportAddressAsync
func (c *Client) ImportAddressAsync(address string) FutureImportAddressResult { cmd := btcjson.NewImportAddressCmd(address, "", nil) return c.sendCmd(cmd) }
go
func (c *Client) ImportAddressAsync(address string) FutureImportAddressResult { cmd := btcjson.NewImportAddressCmd(address, "", nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ImportAddressAsync", "(", "address", "string", ")", "FutureImportAddressResult", "{", "cmd", ":=", "btcjson", ".", "NewImportAddressCmd", "(", "address", ",", "\"", "\"", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ImportAddressAsync 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 ImportAddress for the blocking version and more details.
[ "ImportAddressAsync", "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", "ImportAddress", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2080-L2083
train
btcsuite/btcd
rpcclient/wallet.go
ImportAddress
func (c *Client) ImportAddress(address string) error { return c.ImportAddressAsync(address).Receive() }
go
func (c *Client) ImportAddress(address string) error { return c.ImportAddressAsync(address).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ImportAddress", "(", "address", "string", ")", "error", "{", "return", "c", ".", "ImportAddressAsync", "(", "address", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ImportAddress imports the passed public address.
[ "ImportAddress", "imports", "the", "passed", "public", "address", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2086-L2088
train
btcsuite/btcd
rpcclient/wallet.go
ImportAddressRescanAsync
func (c *Client) ImportAddressRescanAsync(address string, account string, rescan bool) FutureImportAddressResult { cmd := btcjson.NewImportAddressCmd(address, account, &rescan) return c.sendCmd(cmd) }
go
func (c *Client) ImportAddressRescanAsync(address string, account string, rescan bool) FutureImportAddressResult { cmd := btcjson.NewImportAddressCmd(address, account, &rescan) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ImportAddressRescanAsync", "(", "address", "string", ",", "account", "string", ",", "rescan", "bool", ")", "FutureImportAddressResult", "{", "cmd", ":=", "btcjson", ".", "NewImportAddressCmd", "(", "address", ",", "account", ",", "&", "rescan", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ImportAddressRescanAsync 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 ImportAddress for the blocking version and more details.
[ "ImportAddressRescanAsync", "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", "ImportAddress", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2095-L2098
train
btcsuite/btcd
rpcclient/wallet.go
ImportAddressRescan
func (c *Client) ImportAddressRescan(address string, account string, rescan bool) error { return c.ImportAddressRescanAsync(address, account, rescan).Receive() }
go
func (c *Client) ImportAddressRescan(address string, account string, rescan bool) error { return c.ImportAddressRescanAsync(address, account, rescan).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ImportAddressRescan", "(", "address", "string", ",", "account", "string", ",", "rescan", "bool", ")", "error", "{", "return", "c", ".", "ImportAddressRescanAsync", "(", "address", ",", "account", ",", "rescan", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ImportAddressRescan imports the passed public address. When rescan is true, // the block history is scanned for transactions addressed to provided address.
[ "ImportAddressRescan", "imports", "the", "passed", "public", "address", ".", "When", "rescan", "is", "true", "the", "block", "history", "is", "scanned", "for", "transactions", "addressed", "to", "provided", "address", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2102-L2104
train
btcsuite/btcd
rpcclient/wallet.go
ImportPrivKeyAsync
func (c *Client) ImportPrivKeyAsync(privKeyWIF *btcutil.WIF) FutureImportPrivKeyResult { wif := "" if privKeyWIF != nil { wif = privKeyWIF.String() } cmd := btcjson.NewImportPrivKeyCmd(wif, nil, nil) return c.sendCmd(cmd) }
go
func (c *Client) ImportPrivKeyAsync(privKeyWIF *btcutil.WIF) FutureImportPrivKeyResult { wif := "" if privKeyWIF != nil { wif = privKeyWIF.String() } cmd := btcjson.NewImportPrivKeyCmd(wif, nil, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ImportPrivKeyAsync", "(", "privKeyWIF", "*", "btcutil", ".", "WIF", ")", "FutureImportPrivKeyResult", "{", "wif", ":=", "\"", "\"", "\n", "if", "privKeyWIF", "!=", "nil", "{", "wif", "=", "privKeyWIF", ".", "String", "(", ")", "\n", "}", "\n\n", "cmd", ":=", "btcjson", ".", "NewImportPrivKeyCmd", "(", "wif", ",", "nil", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ImportPrivKeyAsync 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 ImportPrivKey for the blocking version and more details.
[ "ImportPrivKeyAsync", "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", "ImportPrivKey", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2123-L2131
train
btcsuite/btcd
rpcclient/wallet.go
ImportPrivKeyLabelAsync
func (c *Client) ImportPrivKeyLabelAsync(privKeyWIF *btcutil.WIF, label string) FutureImportPrivKeyResult { wif := "" if privKeyWIF != nil { wif = privKeyWIF.String() } cmd := btcjson.NewImportPrivKeyCmd(wif, &label, nil) return c.sendCmd(cmd) }
go
func (c *Client) ImportPrivKeyLabelAsync(privKeyWIF *btcutil.WIF, label string) FutureImportPrivKeyResult { wif := "" if privKeyWIF != nil { wif = privKeyWIF.String() } cmd := btcjson.NewImportPrivKeyCmd(wif, &label, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ImportPrivKeyLabelAsync", "(", "privKeyWIF", "*", "btcutil", ".", "WIF", ",", "label", "string", ")", "FutureImportPrivKeyResult", "{", "wif", ":=", "\"", "\"", "\n", "if", "privKeyWIF", "!=", "nil", "{", "wif", "=", "privKeyWIF", ".", "String", "(", ")", "\n", "}", "\n\n", "cmd", ":=", "btcjson", ".", "NewImportPrivKeyCmd", "(", "wif", ",", "&", "label", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ImportPrivKeyLabelAsync 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 ImportPrivKey for the blocking version and more details.
[ "ImportPrivKeyLabelAsync", "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", "ImportPrivKey", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2144-L2152
train
btcsuite/btcd
rpcclient/wallet.go
ImportPrivKeyRescanAsync
func (c *Client) ImportPrivKeyRescanAsync(privKeyWIF *btcutil.WIF, label string, rescan bool) FutureImportPrivKeyResult { wif := "" if privKeyWIF != nil { wif = privKeyWIF.String() } cmd := btcjson.NewImportPrivKeyCmd(wif, &label, &rescan) return c.sendCmd(cmd) }
go
func (c *Client) ImportPrivKeyRescanAsync(privKeyWIF *btcutil.WIF, label string, rescan bool) FutureImportPrivKeyResult { wif := "" if privKeyWIF != nil { wif = privKeyWIF.String() } cmd := btcjson.NewImportPrivKeyCmd(wif, &label, &rescan) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ImportPrivKeyRescanAsync", "(", "privKeyWIF", "*", "btcutil", ".", "WIF", ",", "label", "string", ",", "rescan", "bool", ")", "FutureImportPrivKeyResult", "{", "wif", ":=", "\"", "\"", "\n", "if", "privKeyWIF", "!=", "nil", "{", "wif", "=", "privKeyWIF", ".", "String", "(", ")", "\n", "}", "\n\n", "cmd", ":=", "btcjson", ".", "NewImportPrivKeyCmd", "(", "wif", ",", "&", "label", ",", "&", "rescan", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ImportPrivKeyRescanAsync 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 ImportPrivKey for the blocking version and more details.
[ "ImportPrivKeyRescanAsync", "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", "ImportPrivKey", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2165-L2173
train
btcsuite/btcd
rpcclient/wallet.go
ImportPubKeyAsync
func (c *Client) ImportPubKeyAsync(pubKey string) FutureImportPubKeyResult { cmd := btcjson.NewImportPubKeyCmd(pubKey, nil) return c.sendCmd(cmd) }
go
func (c *Client) ImportPubKeyAsync(pubKey string) FutureImportPubKeyResult { cmd := btcjson.NewImportPubKeyCmd(pubKey, nil) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ImportPubKeyAsync", "(", "pubKey", "string", ")", "FutureImportPubKeyResult", "{", "cmd", ":=", "btcjson", ".", "NewImportPubKeyCmd", "(", "pubKey", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ImportPubKeyAsync 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 ImportPubKey for the blocking version and more details.
[ "ImportPubKeyAsync", "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", "ImportPubKey", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2198-L2201
train
btcsuite/btcd
rpcclient/wallet.go
ImportPubKey
func (c *Client) ImportPubKey(pubKey string) error { return c.ImportPubKeyAsync(pubKey).Receive() }
go
func (c *Client) ImportPubKey(pubKey string) error { return c.ImportPubKeyAsync(pubKey).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ImportPubKey", "(", "pubKey", "string", ")", "error", "{", "return", "c", ".", "ImportPubKeyAsync", "(", "pubKey", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ImportPubKey imports the passed public key.
[ "ImportPubKey", "imports", "the", "passed", "public", "key", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2204-L2206
train
btcsuite/btcd
rpcclient/wallet.go
ImportPubKeyRescanAsync
func (c *Client) ImportPubKeyRescanAsync(pubKey string, rescan bool) FutureImportPubKeyResult { cmd := btcjson.NewImportPubKeyCmd(pubKey, &rescan) return c.sendCmd(cmd) }
go
func (c *Client) ImportPubKeyRescanAsync(pubKey string, rescan bool) FutureImportPubKeyResult { cmd := btcjson.NewImportPubKeyCmd(pubKey, &rescan) return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "ImportPubKeyRescanAsync", "(", "pubKey", "string", ",", "rescan", "bool", ")", "FutureImportPubKeyResult", "{", "cmd", ":=", "btcjson", ".", "NewImportPubKeyCmd", "(", "pubKey", ",", "&", "rescan", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// ImportPubKeyRescanAsync 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 ImportPubKey for the blocking version and more details.
[ "ImportPubKeyRescanAsync", "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", "ImportPubKey", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2213-L2216
train
btcsuite/btcd
rpcclient/wallet.go
ImportPubKeyRescan
func (c *Client) ImportPubKeyRescan(pubKey string, rescan bool) error { return c.ImportPubKeyRescanAsync(pubKey, rescan).Receive() }
go
func (c *Client) ImportPubKeyRescan(pubKey string, rescan bool) error { return c.ImportPubKeyRescanAsync(pubKey, rescan).Receive() }
[ "func", "(", "c", "*", "Client", ")", "ImportPubKeyRescan", "(", "pubKey", "string", ",", "rescan", "bool", ")", "error", "{", "return", "c", ".", "ImportPubKeyRescanAsync", "(", "pubKey", ",", "rescan", ")", ".", "Receive", "(", ")", "\n", "}" ]
// ImportPubKeyRescan imports the passed public key. When rescan is true, the // block history is scanned for transactions addressed to provided pubkey.
[ "ImportPubKeyRescan", "imports", "the", "passed", "public", "key", ".", "When", "rescan", "is", "true", "the", "block", "history", "is", "scanned", "for", "transactions", "addressed", "to", "provided", "pubkey", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2220-L2222
train
btcsuite/btcd
rpcclient/wallet.go
GetInfoAsync
func (c *Client) GetInfoAsync() FutureGetInfoResult { cmd := btcjson.NewGetInfoCmd() return c.sendCmd(cmd) }
go
func (c *Client) GetInfoAsync() FutureGetInfoResult { cmd := btcjson.NewGetInfoCmd() return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "GetInfoAsync", "(", ")", "FutureGetInfoResult", "{", "cmd", ":=", "btcjson", ".", "NewGetInfoCmd", "(", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// GetInfoAsync 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 GetInfo for the blocking version and more details.
[ "GetInfoAsync", "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", "GetInfo", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/wallet.go#L2258-L2261
train
btcsuite/btcd
config.go
removeDuplicateAddresses
func removeDuplicateAddresses(addrs []string) []string { result := make([]string, 0, len(addrs)) seen := map[string]struct{}{} for _, val := range addrs { if _, ok := seen[val]; !ok { result = append(result, val) seen[val] = struct{}{} } } return result }
go
func removeDuplicateAddresses(addrs []string) []string { result := make([]string, 0, len(addrs)) seen := map[string]struct{}{} for _, val := range addrs { if _, ok := seen[val]; !ok { result = append(result, val) seen[val] = struct{}{} } } return result }
[ "func", "removeDuplicateAddresses", "(", "addrs", "[", "]", "string", ")", "[", "]", "string", "{", "result", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "addrs", ")", ")", "\n", "seen", ":=", "map", "[", "string", "]", "struct", "{", "}", "{", "}", "\n", "for", "_", ",", "val", ":=", "range", "addrs", "{", "if", "_", ",", "ok", ":=", "seen", "[", "val", "]", ";", "!", "ok", "{", "result", "=", "append", "(", "result", ",", "val", ")", "\n", "seen", "[", "val", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// removeDuplicateAddresses returns a new slice with all duplicate entries in // addrs removed.
[ "removeDuplicateAddresses", "returns", "a", "new", "slice", "with", "all", "duplicate", "entries", "in", "addrs", "removed", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/config.go#L294-L304
train
btcsuite/btcd
config.go
normalizeAddresses
func normalizeAddresses(addrs []string, defaultPort string) []string { for i, addr := range addrs { addrs[i] = normalizeAddress(addr, defaultPort) } return removeDuplicateAddresses(addrs) }
go
func normalizeAddresses(addrs []string, defaultPort string) []string { for i, addr := range addrs { addrs[i] = normalizeAddress(addr, defaultPort) } return removeDuplicateAddresses(addrs) }
[ "func", "normalizeAddresses", "(", "addrs", "[", "]", "string", ",", "defaultPort", "string", ")", "[", "]", "string", "{", "for", "i", ",", "addr", ":=", "range", "addrs", "{", "addrs", "[", "i", "]", "=", "normalizeAddress", "(", "addr", ",", "defaultPort", ")", "\n", "}", "\n\n", "return", "removeDuplicateAddresses", "(", "addrs", ")", "\n", "}" ]
// normalizeAddresses returns a new slice with all the passed peer addresses // normalized with the given default port, and all duplicates removed.
[ "normalizeAddresses", "returns", "a", "new", "slice", "with", "all", "the", "passed", "peer", "addresses", "normalized", "with", "the", "given", "default", "port", "and", "all", "duplicates", "removed", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/config.go#L318-L324
train
btcsuite/btcd
config.go
newConfigParser
func newConfigParser(cfg *config, so *serviceOptions, options flags.Options) *flags.Parser { parser := flags.NewParser(cfg, options) if runtime.GOOS == "windows" { parser.AddGroup("Service Options", "Service Options", so) } return parser }
go
func newConfigParser(cfg *config, so *serviceOptions, options flags.Options) *flags.Parser { parser := flags.NewParser(cfg, options) if runtime.GOOS == "windows" { parser.AddGroup("Service Options", "Service Options", so) } return parser }
[ "func", "newConfigParser", "(", "cfg", "*", "config", ",", "so", "*", "serviceOptions", ",", "options", "flags", ".", "Options", ")", "*", "flags", ".", "Parser", "{", "parser", ":=", "flags", ".", "NewParser", "(", "cfg", ",", "options", ")", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "parser", ".", "AddGroup", "(", "\"", "\"", ",", "\"", "\"", ",", "so", ")", "\n", "}", "\n", "return", "parser", "\n", "}" ]
// newConfigParser returns a new command line flags parser.
[ "newConfigParser", "returns", "a", "new", "command", "line", "flags", "parser", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/config.go#L385-L391
train
btcsuite/btcd
config.go
createDefaultConfigFile
func createDefaultConfigFile(destinationPath string) error { // Create the destination directory if it does not exists err := os.MkdirAll(filepath.Dir(destinationPath), 0700) if err != nil { return err } // We assume sample config file path is same as binary path, err := filepath.Abs(filepath.Dir(os.Args[0])) if err != nil { return err } sampleConfigPath := filepath.Join(path, sampleConfigFilename) // We generate a random user and password randomBytes := make([]byte, 20) _, err = rand.Read(randomBytes) if err != nil { return err } generatedRPCUser := base64.StdEncoding.EncodeToString(randomBytes) _, err = rand.Read(randomBytes) if err != nil { return err } generatedRPCPass := base64.StdEncoding.EncodeToString(randomBytes) src, err := os.Open(sampleConfigPath) if err != nil { return err } defer src.Close() dest, err := os.OpenFile(destinationPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } defer dest.Close() // We copy every line from the sample config file to the destination, // only replacing the two lines for rpcuser and rpcpass reader := bufio.NewReader(src) for err != io.EOF { var line string line, err = reader.ReadString('\n') if err != nil && err != io.EOF { return err } if strings.Contains(line, "rpcuser=") { line = "rpcuser=" + generatedRPCUser + "\n" } else if strings.Contains(line, "rpcpass=") { line = "rpcpass=" + generatedRPCPass + "\n" } if _, err := dest.WriteString(line); err != nil { return err } } return nil }
go
func createDefaultConfigFile(destinationPath string) error { // Create the destination directory if it does not exists err := os.MkdirAll(filepath.Dir(destinationPath), 0700) if err != nil { return err } // We assume sample config file path is same as binary path, err := filepath.Abs(filepath.Dir(os.Args[0])) if err != nil { return err } sampleConfigPath := filepath.Join(path, sampleConfigFilename) // We generate a random user and password randomBytes := make([]byte, 20) _, err = rand.Read(randomBytes) if err != nil { return err } generatedRPCUser := base64.StdEncoding.EncodeToString(randomBytes) _, err = rand.Read(randomBytes) if err != nil { return err } generatedRPCPass := base64.StdEncoding.EncodeToString(randomBytes) src, err := os.Open(sampleConfigPath) if err != nil { return err } defer src.Close() dest, err := os.OpenFile(destinationPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } defer dest.Close() // We copy every line from the sample config file to the destination, // only replacing the two lines for rpcuser and rpcpass reader := bufio.NewReader(src) for err != io.EOF { var line string line, err = reader.ReadString('\n') if err != nil && err != io.EOF { return err } if strings.Contains(line, "rpcuser=") { line = "rpcuser=" + generatedRPCUser + "\n" } else if strings.Contains(line, "rpcpass=") { line = "rpcpass=" + generatedRPCPass + "\n" } if _, err := dest.WriteString(line); err != nil { return err } } return nil }
[ "func", "createDefaultConfigFile", "(", "destinationPath", "string", ")", "error", "{", "// Create the destination directory if it does not exists", "err", ":=", "os", ".", "MkdirAll", "(", "filepath", ".", "Dir", "(", "destinationPath", ")", ",", "0700", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// We assume sample config file path is same as binary", "path", ",", "err", ":=", "filepath", ".", "Abs", "(", "filepath", ".", "Dir", "(", "os", ".", "Args", "[", "0", "]", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "sampleConfigPath", ":=", "filepath", ".", "Join", "(", "path", ",", "sampleConfigFilename", ")", "\n\n", "// We generate a random user and password", "randomBytes", ":=", "make", "(", "[", "]", "byte", ",", "20", ")", "\n", "_", ",", "err", "=", "rand", ".", "Read", "(", "randomBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "generatedRPCUser", ":=", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "randomBytes", ")", "\n\n", "_", ",", "err", "=", "rand", ".", "Read", "(", "randomBytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "generatedRPCPass", ":=", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "randomBytes", ")", "\n\n", "src", ",", "err", ":=", "os", ".", "Open", "(", "sampleConfigPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "src", ".", "Close", "(", ")", "\n\n", "dest", ",", "err", ":=", "os", ".", "OpenFile", "(", "destinationPath", ",", "os", ".", "O_RDWR", "|", "os", ".", "O_CREATE", "|", "os", ".", "O_TRUNC", ",", "0600", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "dest", ".", "Close", "(", ")", "\n\n", "// We copy every line from the sample config file to the destination,", "// only replacing the two lines for rpcuser and rpcpass", "reader", ":=", "bufio", ".", "NewReader", "(", "src", ")", "\n", "for", "err", "!=", "io", ".", "EOF", "{", "var", "line", "string", "\n", "line", ",", "err", "=", "reader", ".", "ReadString", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "io", ".", "EOF", "{", "return", "err", "\n", "}", "\n\n", "if", "strings", ".", "Contains", "(", "line", ",", "\"", "\"", ")", "{", "line", "=", "\"", "\"", "+", "generatedRPCUser", "+", "\"", "\\n", "\"", "\n", "}", "else", "if", "strings", ".", "Contains", "(", "line", ",", "\"", "\"", ")", "{", "line", "=", "\"", "\"", "+", "generatedRPCPass", "+", "\"", "\\n", "\"", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "dest", ".", "WriteString", "(", "line", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// createDefaultConfig copies the file sample-btcd.conf to the given destination path, // and populates it with some randomly generated RPC username and password.
[ "createDefaultConfig", "copies", "the", "file", "sample", "-", "btcd", ".", "conf", "to", "the", "given", "destination", "path", "and", "populates", "it", "with", "some", "randomly", "generated", "RPC", "username", "and", "password", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/config.go#L1093-L1156
train
btcsuite/btcd
wire/blockheader.go
BlockHash
func (h *BlockHeader) BlockHash() chainhash.Hash { // Encode the header and double sha256 everything prior to the number of // transactions. Ignore the error returns since there is no way the // encode could fail except being out of memory which would cause a // run-time panic. buf := bytes.NewBuffer(make([]byte, 0, MaxBlockHeaderPayload)) _ = writeBlockHeader(buf, 0, h) return chainhash.DoubleHashH(buf.Bytes()) }
go
func (h *BlockHeader) BlockHash() chainhash.Hash { // Encode the header and double sha256 everything prior to the number of // transactions. Ignore the error returns since there is no way the // encode could fail except being out of memory which would cause a // run-time panic. buf := bytes.NewBuffer(make([]byte, 0, MaxBlockHeaderPayload)) _ = writeBlockHeader(buf, 0, h) return chainhash.DoubleHashH(buf.Bytes()) }
[ "func", "(", "h", "*", "BlockHeader", ")", "BlockHash", "(", ")", "chainhash", ".", "Hash", "{", "// Encode the header and double sha256 everything prior to the number of", "// transactions. Ignore the error returns since there is no way the", "// encode could fail except being out of memory which would cause a", "// run-time panic.", "buf", ":=", "bytes", ".", "NewBuffer", "(", "make", "(", "[", "]", "byte", ",", "0", ",", "MaxBlockHeaderPayload", ")", ")", "\n", "_", "=", "writeBlockHeader", "(", "buf", ",", "0", ",", "h", ")", "\n\n", "return", "chainhash", ".", "DoubleHashH", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "}" ]
// BlockHash computes the block identifier hash for the given block header.
[ "BlockHash", "computes", "the", "block", "identifier", "hash", "for", "the", "given", "block", "header", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L48-L57
train
btcsuite/btcd
wire/blockheader.go
BtcDecode
func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error { return readBlockHeader(r, pver, h) }
go
func (h *BlockHeader) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error { return readBlockHeader(r, pver, h) }
[ "func", "(", "h", "*", "BlockHeader", ")", "BtcDecode", "(", "r", "io", ".", "Reader", ",", "pver", "uint32", ",", "enc", "MessageEncoding", ")", "error", "{", "return", "readBlockHeader", "(", "r", ",", "pver", ",", "h", ")", "\n", "}" ]
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver. // This is part of the Message interface implementation. // See Deserialize for decoding block headers stored to disk, such as in a // database, as opposed to decoding block headers from the wire.
[ "BtcDecode", "decodes", "r", "using", "the", "bitcoin", "protocol", "encoding", "into", "the", "receiver", ".", "This", "is", "part", "of", "the", "Message", "interface", "implementation", ".", "See", "Deserialize", "for", "decoding", "block", "headers", "stored", "to", "disk", "such", "as", "in", "a", "database", "as", "opposed", "to", "decoding", "block", "headers", "from", "the", "wire", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L63-L65
train
btcsuite/btcd
wire/blockheader.go
BtcEncode
func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error { return writeBlockHeader(w, pver, h) }
go
func (h *BlockHeader) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) error { return writeBlockHeader(w, pver, h) }
[ "func", "(", "h", "*", "BlockHeader", ")", "BtcEncode", "(", "w", "io", ".", "Writer", ",", "pver", "uint32", ",", "enc", "MessageEncoding", ")", "error", "{", "return", "writeBlockHeader", "(", "w", ",", "pver", ",", "h", ")", "\n", "}" ]
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding. // This is part of the Message interface implementation. // See Serialize for encoding block headers to be stored to disk, such as in a // database, as opposed to encoding block headers for the wire.
[ "BtcEncode", "encodes", "the", "receiver", "to", "w", "using", "the", "bitcoin", "protocol", "encoding", ".", "This", "is", "part", "of", "the", "Message", "interface", "implementation", ".", "See", "Serialize", "for", "encoding", "block", "headers", "to", "be", "stored", "to", "disk", "such", "as", "in", "a", "database", "as", "opposed", "to", "encoding", "block", "headers", "for", "the", "wire", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L71-L73
train
btcsuite/btcd
wire/blockheader.go
Deserialize
func (h *BlockHeader) Deserialize(r io.Reader) error { // At the current time, there is no difference between the wire encoding // at protocol version 0 and the stable long-term storage format. As // a result, make use of readBlockHeader. return readBlockHeader(r, 0, h) }
go
func (h *BlockHeader) Deserialize(r io.Reader) error { // At the current time, there is no difference between the wire encoding // at protocol version 0 and the stable long-term storage format. As // a result, make use of readBlockHeader. return readBlockHeader(r, 0, h) }
[ "func", "(", "h", "*", "BlockHeader", ")", "Deserialize", "(", "r", "io", ".", "Reader", ")", "error", "{", "// At the current time, there is no difference between the wire encoding", "// at protocol version 0 and the stable long-term storage format. As", "// a result, make use of readBlockHeader.", "return", "readBlockHeader", "(", "r", ",", "0", ",", "h", ")", "\n", "}" ]
// Deserialize decodes a block header from r into the receiver using a format // that is suitable for long-term storage such as a database while respecting // the Version field.
[ "Deserialize", "decodes", "a", "block", "header", "from", "r", "into", "the", "receiver", "using", "a", "format", "that", "is", "suitable", "for", "long", "-", "term", "storage", "such", "as", "a", "database", "while", "respecting", "the", "Version", "field", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L78-L83
train
btcsuite/btcd
wire/blockheader.go
Serialize
func (h *BlockHeader) Serialize(w io.Writer) error { // At the current time, there is no difference between the wire encoding // at protocol version 0 and the stable long-term storage format. As // a result, make use of writeBlockHeader. return writeBlockHeader(w, 0, h) }
go
func (h *BlockHeader) Serialize(w io.Writer) error { // At the current time, there is no difference between the wire encoding // at protocol version 0 and the stable long-term storage format. As // a result, make use of writeBlockHeader. return writeBlockHeader(w, 0, h) }
[ "func", "(", "h", "*", "BlockHeader", ")", "Serialize", "(", "w", "io", ".", "Writer", ")", "error", "{", "// At the current time, there is no difference between the wire encoding", "// at protocol version 0 and the stable long-term storage format. As", "// a result, make use of writeBlockHeader.", "return", "writeBlockHeader", "(", "w", ",", "0", ",", "h", ")", "\n", "}" ]
// Serialize encodes a block header from r into the receiver using a format // that is suitable for long-term storage such as a database while respecting // the Version field.
[ "Serialize", "encodes", "a", "block", "header", "from", "r", "into", "the", "receiver", "using", "a", "format", "that", "is", "suitable", "for", "long", "-", "term", "storage", "such", "as", "a", "database", "while", "respecting", "the", "Version", "field", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L88-L93
train
btcsuite/btcd
wire/blockheader.go
NewBlockHeader
func NewBlockHeader(version int32, prevHash, merkleRootHash *chainhash.Hash, bits uint32, nonce uint32) *BlockHeader { // Limit the timestamp to one second precision since the protocol // doesn't support better. return &BlockHeader{ Version: version, PrevBlock: *prevHash, MerkleRoot: *merkleRootHash, Timestamp: time.Unix(time.Now().Unix(), 0), Bits: bits, Nonce: nonce, } }
go
func NewBlockHeader(version int32, prevHash, merkleRootHash *chainhash.Hash, bits uint32, nonce uint32) *BlockHeader { // Limit the timestamp to one second precision since the protocol // doesn't support better. return &BlockHeader{ Version: version, PrevBlock: *prevHash, MerkleRoot: *merkleRootHash, Timestamp: time.Unix(time.Now().Unix(), 0), Bits: bits, Nonce: nonce, } }
[ "func", "NewBlockHeader", "(", "version", "int32", ",", "prevHash", ",", "merkleRootHash", "*", "chainhash", ".", "Hash", ",", "bits", "uint32", ",", "nonce", "uint32", ")", "*", "BlockHeader", "{", "// Limit the timestamp to one second precision since the protocol", "// doesn't support better.", "return", "&", "BlockHeader", "{", "Version", ":", "version", ",", "PrevBlock", ":", "*", "prevHash", ",", "MerkleRoot", ":", "*", "merkleRootHash", ",", "Timestamp", ":", "time", ".", "Unix", "(", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ",", "0", ")", ",", "Bits", ":", "bits", ",", "Nonce", ":", "nonce", ",", "}", "\n", "}" ]
// NewBlockHeader returns a new BlockHeader using the provided version, previous // block hash, merkle root hash, difficulty bits, and nonce used to generate the // block with defaults for the remaining fields.
[ "NewBlockHeader", "returns", "a", "new", "BlockHeader", "using", "the", "provided", "version", "previous", "block", "hash", "merkle", "root", "hash", "difficulty", "bits", "and", "nonce", "used", "to", "generate", "the", "block", "with", "defaults", "for", "the", "remaining", "fields", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L98-L111
train
btcsuite/btcd
wire/blockheader.go
readBlockHeader
func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error { return readElements(r, &bh.Version, &bh.PrevBlock, &bh.MerkleRoot, (*uint32Time)(&bh.Timestamp), &bh.Bits, &bh.Nonce) }
go
func readBlockHeader(r io.Reader, pver uint32, bh *BlockHeader) error { return readElements(r, &bh.Version, &bh.PrevBlock, &bh.MerkleRoot, (*uint32Time)(&bh.Timestamp), &bh.Bits, &bh.Nonce) }
[ "func", "readBlockHeader", "(", "r", "io", ".", "Reader", ",", "pver", "uint32", ",", "bh", "*", "BlockHeader", ")", "error", "{", "return", "readElements", "(", "r", ",", "&", "bh", ".", "Version", ",", "&", "bh", ".", "PrevBlock", ",", "&", "bh", ".", "MerkleRoot", ",", "(", "*", "uint32Time", ")", "(", "&", "bh", ".", "Timestamp", ")", ",", "&", "bh", ".", "Bits", ",", "&", "bh", ".", "Nonce", ")", "\n", "}" ]
// readBlockHeader reads a bitcoin block header from r. See Deserialize for // decoding block headers stored to disk, such as in a database, as opposed to // decoding from the wire.
[ "readBlockHeader", "reads", "a", "bitcoin", "block", "header", "from", "r", ".", "See", "Deserialize", "for", "decoding", "block", "headers", "stored", "to", "disk", "such", "as", "in", "a", "database", "as", "opposed", "to", "decoding", "from", "the", "wire", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L116-L119
train
btcsuite/btcd
wire/blockheader.go
writeBlockHeader
func writeBlockHeader(w io.Writer, pver uint32, bh *BlockHeader) error { sec := uint32(bh.Timestamp.Unix()) return writeElements(w, bh.Version, &bh.PrevBlock, &bh.MerkleRoot, sec, bh.Bits, bh.Nonce) }
go
func writeBlockHeader(w io.Writer, pver uint32, bh *BlockHeader) error { sec := uint32(bh.Timestamp.Unix()) return writeElements(w, bh.Version, &bh.PrevBlock, &bh.MerkleRoot, sec, bh.Bits, bh.Nonce) }
[ "func", "writeBlockHeader", "(", "w", "io", ".", "Writer", ",", "pver", "uint32", ",", "bh", "*", "BlockHeader", ")", "error", "{", "sec", ":=", "uint32", "(", "bh", ".", "Timestamp", ".", "Unix", "(", ")", ")", "\n", "return", "writeElements", "(", "w", ",", "bh", ".", "Version", ",", "&", "bh", ".", "PrevBlock", ",", "&", "bh", ".", "MerkleRoot", ",", "sec", ",", "bh", ".", "Bits", ",", "bh", ".", "Nonce", ")", "\n", "}" ]
// writeBlockHeader writes a bitcoin block header to w. See Serialize for // encoding block headers to be stored to disk, such as in a database, as // opposed to encoding for the wire.
[ "writeBlockHeader", "writes", "a", "bitcoin", "block", "header", "to", "w", ".", "See", "Serialize", "for", "encoding", "block", "headers", "to", "be", "stored", "to", "disk", "such", "as", "in", "a", "database", "as", "opposed", "to", "encoding", "for", "the", "wire", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/blockheader.go#L124-L128
train
btcsuite/btcd
connmgr/dynamicbanscore.go
init
func init() { for i := range precomputedFactor { precomputedFactor[i] = math.Exp(-1.0 * float64(i) * lambda) } }
go
func init() { for i := range precomputedFactor { precomputedFactor[i] = math.Exp(-1.0 * float64(i) * lambda) } }
[ "func", "init", "(", ")", "{", "for", "i", ":=", "range", "precomputedFactor", "{", "precomputedFactor", "[", "i", "]", "=", "math", ".", "Exp", "(", "-", "1.0", "*", "float64", "(", "i", ")", "*", "lambda", ")", "\n", "}", "\n", "}" ]
// init precomputes decay factors.
[ "init", "precomputes", "decay", "factors", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L36-L40
train
btcsuite/btcd
connmgr/dynamicbanscore.go
decayFactor
func decayFactor(t int64) float64 { if t < precomputedLen { return precomputedFactor[t] } return math.Exp(-1.0 * float64(t) * lambda) }
go
func decayFactor(t int64) float64 { if t < precomputedLen { return precomputedFactor[t] } return math.Exp(-1.0 * float64(t) * lambda) }
[ "func", "decayFactor", "(", "t", "int64", ")", "float64", "{", "if", "t", "<", "precomputedLen", "{", "return", "precomputedFactor", "[", "t", "]", "\n", "}", "\n", "return", "math", ".", "Exp", "(", "-", "1.0", "*", "float64", "(", "t", ")", "*", "lambda", ")", "\n", "}" ]
// decayFactor returns the decay factor at t seconds, using precalculated values // if available, or calculating the factor if needed.
[ "decayFactor", "returns", "the", "decay", "factor", "at", "t", "seconds", "using", "precalculated", "values", "if", "available", "or", "calculating", "the", "factor", "if", "needed", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L44-L49
train
btcsuite/btcd
connmgr/dynamicbanscore.go
String
func (s *DynamicBanScore) String() string { s.mtx.Lock() r := fmt.Sprintf("persistent %v + transient %v at %v = %v as of now", s.persistent, s.transient, s.lastUnix, s.Int()) s.mtx.Unlock() return r }
go
func (s *DynamicBanScore) String() string { s.mtx.Lock() r := fmt.Sprintf("persistent %v + transient %v at %v = %v as of now", s.persistent, s.transient, s.lastUnix, s.Int()) s.mtx.Unlock() return r }
[ "func", "(", "s", "*", "DynamicBanScore", ")", "String", "(", ")", "string", "{", "s", ".", "mtx", ".", "Lock", "(", ")", "\n", "r", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "persistent", ",", "s", ".", "transient", ",", "s", ".", "lastUnix", ",", "s", ".", "Int", "(", ")", ")", "\n", "s", ".", "mtx", ".", "Unlock", "(", ")", "\n", "return", "r", "\n", "}" ]
// String returns the ban score as a human-readable string.
[ "String", "returns", "the", "ban", "score", "as", "a", "human", "-", "readable", "string", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L71-L77
train
btcsuite/btcd
connmgr/dynamicbanscore.go
Int
func (s *DynamicBanScore) Int() uint32 { s.mtx.Lock() r := s.int(time.Now()) s.mtx.Unlock() return r }
go
func (s *DynamicBanScore) Int() uint32 { s.mtx.Lock() r := s.int(time.Now()) s.mtx.Unlock() return r }
[ "func", "(", "s", "*", "DynamicBanScore", ")", "Int", "(", ")", "uint32", "{", "s", ".", "mtx", ".", "Lock", "(", ")", "\n", "r", ":=", "s", ".", "int", "(", "time", ".", "Now", "(", ")", ")", "\n", "s", ".", "mtx", ".", "Unlock", "(", ")", "\n", "return", "r", "\n", "}" ]
// Int returns the current ban score, the sum of the persistent and decaying // scores. // // This function is safe for concurrent access.
[ "Int", "returns", "the", "current", "ban", "score", "the", "sum", "of", "the", "persistent", "and", "decaying", "scores", ".", "This", "function", "is", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L83-L88
train
btcsuite/btcd
connmgr/dynamicbanscore.go
Increase
func (s *DynamicBanScore) Increase(persistent, transient uint32) uint32 { s.mtx.Lock() r := s.increase(persistent, transient, time.Now()) s.mtx.Unlock() return r }
go
func (s *DynamicBanScore) Increase(persistent, transient uint32) uint32 { s.mtx.Lock() r := s.increase(persistent, transient, time.Now()) s.mtx.Unlock() return r }
[ "func", "(", "s", "*", "DynamicBanScore", ")", "Increase", "(", "persistent", ",", "transient", "uint32", ")", "uint32", "{", "s", ".", "mtx", ".", "Lock", "(", ")", "\n", "r", ":=", "s", ".", "increase", "(", "persistent", ",", "transient", ",", "time", ".", "Now", "(", ")", ")", "\n", "s", ".", "mtx", ".", "Unlock", "(", ")", "\n", "return", "r", "\n", "}" ]
// Increase increases both the persistent and decaying scores by the values // passed as parameters. The resulting score is returned. // // This function is safe for concurrent access.
[ "Increase", "increases", "both", "the", "persistent", "and", "decaying", "scores", "by", "the", "values", "passed", "as", "parameters", ".", "The", "resulting", "score", "is", "returned", ".", "This", "function", "is", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L94-L99
train
btcsuite/btcd
connmgr/dynamicbanscore.go
Reset
func (s *DynamicBanScore) Reset() { s.mtx.Lock() s.persistent = 0 s.transient = 0 s.lastUnix = 0 s.mtx.Unlock() }
go
func (s *DynamicBanScore) Reset() { s.mtx.Lock() s.persistent = 0 s.transient = 0 s.lastUnix = 0 s.mtx.Unlock() }
[ "func", "(", "s", "*", "DynamicBanScore", ")", "Reset", "(", ")", "{", "s", ".", "mtx", ".", "Lock", "(", ")", "\n", "s", ".", "persistent", "=", "0", "\n", "s", ".", "transient", "=", "0", "\n", "s", ".", "lastUnix", "=", "0", "\n", "s", ".", "mtx", ".", "Unlock", "(", ")", "\n", "}" ]
// Reset set both persistent and decaying scores to zero. // // This function is safe for concurrent access.
[ "Reset", "set", "both", "persistent", "and", "decaying", "scores", "to", "zero", ".", "This", "function", "is", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L104-L110
train
btcsuite/btcd
connmgr/dynamicbanscore.go
int
func (s *DynamicBanScore) int(t time.Time) uint32 { dt := t.Unix() - s.lastUnix if s.transient < 1 || dt < 0 || Lifetime < dt { return s.persistent } return s.persistent + uint32(s.transient*decayFactor(dt)) }
go
func (s *DynamicBanScore) int(t time.Time) uint32 { dt := t.Unix() - s.lastUnix if s.transient < 1 || dt < 0 || Lifetime < dt { return s.persistent } return s.persistent + uint32(s.transient*decayFactor(dt)) }
[ "func", "(", "s", "*", "DynamicBanScore", ")", "int", "(", "t", "time", ".", "Time", ")", "uint32", "{", "dt", ":=", "t", ".", "Unix", "(", ")", "-", "s", ".", "lastUnix", "\n", "if", "s", ".", "transient", "<", "1", "||", "dt", "<", "0", "||", "Lifetime", "<", "dt", "{", "return", "s", ".", "persistent", "\n", "}", "\n", "return", "s", ".", "persistent", "+", "uint32", "(", "s", ".", "transient", "*", "decayFactor", "(", "dt", ")", ")", "\n", "}" ]
// int returns the ban score, the sum of the persistent and decaying scores at a // given point in time. // // This function is not safe for concurrent access. It is intended to be used // internally and during testing.
[ "int", "returns", "the", "ban", "score", "the", "sum", "of", "the", "persistent", "and", "decaying", "scores", "at", "a", "given", "point", "in", "time", ".", "This", "function", "is", "not", "safe", "for", "concurrent", "access", ".", "It", "is", "intended", "to", "be", "used", "internally", "and", "during", "testing", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L117-L123
train
btcsuite/btcd
connmgr/dynamicbanscore.go
increase
func (s *DynamicBanScore) increase(persistent, transient uint32, t time.Time) uint32 { s.persistent += persistent tu := t.Unix() dt := tu - s.lastUnix if transient > 0 { if Lifetime < dt { s.transient = 0 } else if s.transient > 1 && dt > 0 { s.transient *= decayFactor(dt) } s.transient += float64(transient) s.lastUnix = tu } return s.persistent + uint32(s.transient) }
go
func (s *DynamicBanScore) increase(persistent, transient uint32, t time.Time) uint32 { s.persistent += persistent tu := t.Unix() dt := tu - s.lastUnix if transient > 0 { if Lifetime < dt { s.transient = 0 } else if s.transient > 1 && dt > 0 { s.transient *= decayFactor(dt) } s.transient += float64(transient) s.lastUnix = tu } return s.persistent + uint32(s.transient) }
[ "func", "(", "s", "*", "DynamicBanScore", ")", "increase", "(", "persistent", ",", "transient", "uint32", ",", "t", "time", ".", "Time", ")", "uint32", "{", "s", ".", "persistent", "+=", "persistent", "\n", "tu", ":=", "t", ".", "Unix", "(", ")", "\n", "dt", ":=", "tu", "-", "s", ".", "lastUnix", "\n\n", "if", "transient", ">", "0", "{", "if", "Lifetime", "<", "dt", "{", "s", ".", "transient", "=", "0", "\n", "}", "else", "if", "s", ".", "transient", ">", "1", "&&", "dt", ">", "0", "{", "s", ".", "transient", "*=", "decayFactor", "(", "dt", ")", "\n", "}", "\n", "s", ".", "transient", "+=", "float64", "(", "transient", ")", "\n", "s", ".", "lastUnix", "=", "tu", "\n", "}", "\n", "return", "s", ".", "persistent", "+", "uint32", "(", "s", ".", "transient", ")", "\n", "}" ]
// increase increases the persistent, the decaying or both scores by the values // passed as parameters. The resulting score is calculated as if the action was // carried out at the point time represented by the third parameter. The // resulting score is returned. // // This function is not safe for concurrent access.
[ "increase", "increases", "the", "persistent", "the", "decaying", "or", "both", "scores", "by", "the", "values", "passed", "as", "parameters", ".", "The", "resulting", "score", "is", "calculated", "as", "if", "the", "action", "was", "carried", "out", "at", "the", "point", "time", "represented", "by", "the", "third", "parameter", ".", "The", "resulting", "score", "is", "returned", ".", "This", "function", "is", "not", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/connmgr/dynamicbanscore.go#L131-L146
train
btcsuite/btcd
cmd/btcctl/httpclient.go
newHTTPClient
func newHTTPClient(cfg *config) (*http.Client, error) { // Configure proxy if needed. var dial func(network, addr string) (net.Conn, error) if cfg.Proxy != "" { proxy := &socks.Proxy{ Addr: cfg.Proxy, Username: cfg.ProxyUser, Password: cfg.ProxyPass, } dial = func(network, addr string) (net.Conn, error) { c, err := proxy.Dial(network, addr) if err != nil { return nil, err } return c, nil } } // Configure TLS if needed. var tlsConfig *tls.Config if !cfg.NoTLS && cfg.RPCCert != "" { pem, err := ioutil.ReadFile(cfg.RPCCert) if err != nil { return nil, err } pool := x509.NewCertPool() pool.AppendCertsFromPEM(pem) tlsConfig = &tls.Config{ RootCAs: pool, InsecureSkipVerify: cfg.TLSSkipVerify, } } // Create and return the new HTTP client potentially configured with a // proxy and TLS. client := http.Client{ Transport: &http.Transport{ Dial: dial, TLSClientConfig: tlsConfig, }, } return &client, nil }
go
func newHTTPClient(cfg *config) (*http.Client, error) { // Configure proxy if needed. var dial func(network, addr string) (net.Conn, error) if cfg.Proxy != "" { proxy := &socks.Proxy{ Addr: cfg.Proxy, Username: cfg.ProxyUser, Password: cfg.ProxyPass, } dial = func(network, addr string) (net.Conn, error) { c, err := proxy.Dial(network, addr) if err != nil { return nil, err } return c, nil } } // Configure TLS if needed. var tlsConfig *tls.Config if !cfg.NoTLS && cfg.RPCCert != "" { pem, err := ioutil.ReadFile(cfg.RPCCert) if err != nil { return nil, err } pool := x509.NewCertPool() pool.AppendCertsFromPEM(pem) tlsConfig = &tls.Config{ RootCAs: pool, InsecureSkipVerify: cfg.TLSSkipVerify, } } // Create and return the new HTTP client potentially configured with a // proxy and TLS. client := http.Client{ Transport: &http.Transport{ Dial: dial, TLSClientConfig: tlsConfig, }, } return &client, nil }
[ "func", "newHTTPClient", "(", "cfg", "*", "config", ")", "(", "*", "http", ".", "Client", ",", "error", ")", "{", "// Configure proxy if needed.", "var", "dial", "func", "(", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "\n", "if", "cfg", ".", "Proxy", "!=", "\"", "\"", "{", "proxy", ":=", "&", "socks", ".", "Proxy", "{", "Addr", ":", "cfg", ".", "Proxy", ",", "Username", ":", "cfg", ".", "ProxyUser", ",", "Password", ":", "cfg", ".", "ProxyPass", ",", "}", "\n", "dial", "=", "func", "(", "network", ",", "addr", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "c", ",", "err", ":=", "proxy", ".", "Dial", "(", "network", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "c", ",", "nil", "\n", "}", "\n", "}", "\n\n", "// Configure TLS if needed.", "var", "tlsConfig", "*", "tls", ".", "Config", "\n", "if", "!", "cfg", ".", "NoTLS", "&&", "cfg", ".", "RPCCert", "!=", "\"", "\"", "{", "pem", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "cfg", ".", "RPCCert", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "pool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "pool", ".", "AppendCertsFromPEM", "(", "pem", ")", "\n", "tlsConfig", "=", "&", "tls", ".", "Config", "{", "RootCAs", ":", "pool", ",", "InsecureSkipVerify", ":", "cfg", ".", "TLSSkipVerify", ",", "}", "\n", "}", "\n\n", "// Create and return the new HTTP client potentially configured with a", "// proxy and TLS.", "client", ":=", "http", ".", "Client", "{", "Transport", ":", "&", "http", ".", "Transport", "{", "Dial", ":", "dial", ",", "TLSClientConfig", ":", "tlsConfig", ",", "}", ",", "}", "\n", "return", "&", "client", ",", "nil", "\n", "}" ]
// newHTTPClient returns a new HTTP client that is configured according to the // proxy and TLS settings in the associated connection configuration.
[ "newHTTPClient", "returns", "a", "new", "HTTP", "client", "that", "is", "configured", "according", "to", "the", "proxy", "and", "TLS", "settings", "in", "the", "associated", "connection", "configuration", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/cmd/btcctl/httpclient.go#L19-L62
train
btcsuite/btcd
cmd/btcctl/httpclient.go
sendPostRequest
func sendPostRequest(marshalledJSON []byte, cfg *config) ([]byte, error) { // Generate a request to the configured RPC server. protocol := "http" if !cfg.NoTLS { protocol = "https" } url := protocol + "://" + cfg.RPCServer bodyReader := bytes.NewReader(marshalledJSON) httpRequest, err := http.NewRequest("POST", url, bodyReader) if err != nil { return nil, err } httpRequest.Close = true httpRequest.Header.Set("Content-Type", "application/json") // Configure basic access authorization. httpRequest.SetBasicAuth(cfg.RPCUser, cfg.RPCPassword) // Create the new HTTP client that is configured according to the user- // specified options and submit the request. httpClient, err := newHTTPClient(cfg) if err != nil { return nil, err } httpResponse, err := httpClient.Do(httpRequest) if err != nil { return nil, err } // Read the raw bytes and close the response. respBytes, err := ioutil.ReadAll(httpResponse.Body) httpResponse.Body.Close() if err != nil { err = fmt.Errorf("error reading json reply: %v", err) return nil, err } // Handle unsuccessful HTTP responses if httpResponse.StatusCode < 200 || httpResponse.StatusCode >= 300 { // Generate a standard error to return if the server body is // empty. This should not happen very often, but it's better // than showing nothing in case the target server has a poor // implementation. if len(respBytes) == 0 { return nil, fmt.Errorf("%d %s", httpResponse.StatusCode, http.StatusText(httpResponse.StatusCode)) } return nil, fmt.Errorf("%s", respBytes) } // Unmarshal the response. var resp btcjson.Response if err := json.Unmarshal(respBytes, &resp); err != nil { return nil, err } if resp.Error != nil { return nil, resp.Error } return resp.Result, nil }
go
func sendPostRequest(marshalledJSON []byte, cfg *config) ([]byte, error) { // Generate a request to the configured RPC server. protocol := "http" if !cfg.NoTLS { protocol = "https" } url := protocol + "://" + cfg.RPCServer bodyReader := bytes.NewReader(marshalledJSON) httpRequest, err := http.NewRequest("POST", url, bodyReader) if err != nil { return nil, err } httpRequest.Close = true httpRequest.Header.Set("Content-Type", "application/json") // Configure basic access authorization. httpRequest.SetBasicAuth(cfg.RPCUser, cfg.RPCPassword) // Create the new HTTP client that is configured according to the user- // specified options and submit the request. httpClient, err := newHTTPClient(cfg) if err != nil { return nil, err } httpResponse, err := httpClient.Do(httpRequest) if err != nil { return nil, err } // Read the raw bytes and close the response. respBytes, err := ioutil.ReadAll(httpResponse.Body) httpResponse.Body.Close() if err != nil { err = fmt.Errorf("error reading json reply: %v", err) return nil, err } // Handle unsuccessful HTTP responses if httpResponse.StatusCode < 200 || httpResponse.StatusCode >= 300 { // Generate a standard error to return if the server body is // empty. This should not happen very often, but it's better // than showing nothing in case the target server has a poor // implementation. if len(respBytes) == 0 { return nil, fmt.Errorf("%d %s", httpResponse.StatusCode, http.StatusText(httpResponse.StatusCode)) } return nil, fmt.Errorf("%s", respBytes) } // Unmarshal the response. var resp btcjson.Response if err := json.Unmarshal(respBytes, &resp); err != nil { return nil, err } if resp.Error != nil { return nil, resp.Error } return resp.Result, nil }
[ "func", "sendPostRequest", "(", "marshalledJSON", "[", "]", "byte", ",", "cfg", "*", "config", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Generate a request to the configured RPC server.", "protocol", ":=", "\"", "\"", "\n", "if", "!", "cfg", ".", "NoTLS", "{", "protocol", "=", "\"", "\"", "\n", "}", "\n", "url", ":=", "protocol", "+", "\"", "\"", "+", "cfg", ".", "RPCServer", "\n", "bodyReader", ":=", "bytes", ".", "NewReader", "(", "marshalledJSON", ")", "\n", "httpRequest", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "url", ",", "bodyReader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "httpRequest", ".", "Close", "=", "true", "\n", "httpRequest", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Configure basic access authorization.", "httpRequest", ".", "SetBasicAuth", "(", "cfg", ".", "RPCUser", ",", "cfg", ".", "RPCPassword", ")", "\n\n", "// Create the new HTTP client that is configured according to the user-", "// specified options and submit the request.", "httpClient", ",", "err", ":=", "newHTTPClient", "(", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "httpResponse", ",", "err", ":=", "httpClient", ".", "Do", "(", "httpRequest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Read the raw bytes and close the response.", "respBytes", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "httpResponse", ".", "Body", ")", "\n", "httpResponse", ".", "Body", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Handle unsuccessful HTTP responses", "if", "httpResponse", ".", "StatusCode", "<", "200", "||", "httpResponse", ".", "StatusCode", ">=", "300", "{", "// Generate a standard error to return if the server body is", "// empty. This should not happen very often, but it's better", "// than showing nothing in case the target server has a poor", "// implementation.", "if", "len", "(", "respBytes", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "httpResponse", ".", "StatusCode", ",", "http", ".", "StatusText", "(", "httpResponse", ".", "StatusCode", ")", ")", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "respBytes", ")", "\n", "}", "\n\n", "// Unmarshal the response.", "var", "resp", "btcjson", ".", "Response", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "respBytes", ",", "&", "resp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "resp", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "resp", ".", "Error", "\n", "}", "\n", "return", "resp", ".", "Result", ",", "nil", "\n", "}" ]
// sendPostRequest sends the marshalled JSON-RPC command using HTTP-POST mode // to the server described in the passed config struct. It also attempts to // unmarshal the response as a JSON-RPC response and returns either the result // field or the error field depending on whether or not there is an error.
[ "sendPostRequest", "sends", "the", "marshalled", "JSON", "-", "RPC", "command", "using", "HTTP", "-", "POST", "mode", "to", "the", "server", "described", "in", "the", "passed", "config", "struct", ".", "It", "also", "attempts", "to", "unmarshal", "the", "response", "as", "a", "JSON", "-", "RPC", "response", "and", "returns", "either", "the", "result", "field", "or", "the", "error", "field", "depending", "on", "whether", "or", "not", "there", "is", "an", "error", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/cmd/btcctl/httpclient.go#L68-L128
train
btcsuite/btcd
rpcclient/infrastructure.go
addRequest
func (c *Client) addRequest(jReq *jsonRequest) error { c.requestLock.Lock() defer c.requestLock.Unlock() // A non-blocking read of the shutdown channel with the request lock // held avoids adding the request to the client's internal data // structures if the client is in the process of shutting down (and // has not yet grabbed the request lock), or has finished shutdown // already (responding to each outstanding request with // ErrClientShutdown). select { case <-c.shutdown: return ErrClientShutdown default: } element := c.requestList.PushBack(jReq) c.requestMap[jReq.id] = element return nil }
go
func (c *Client) addRequest(jReq *jsonRequest) error { c.requestLock.Lock() defer c.requestLock.Unlock() // A non-blocking read of the shutdown channel with the request lock // held avoids adding the request to the client's internal data // structures if the client is in the process of shutting down (and // has not yet grabbed the request lock), or has finished shutdown // already (responding to each outstanding request with // ErrClientShutdown). select { case <-c.shutdown: return ErrClientShutdown default: } element := c.requestList.PushBack(jReq) c.requestMap[jReq.id] = element return nil }
[ "func", "(", "c", "*", "Client", ")", "addRequest", "(", "jReq", "*", "jsonRequest", ")", "error", "{", "c", ".", "requestLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "requestLock", ".", "Unlock", "(", ")", "\n\n", "// A non-blocking read of the shutdown channel with the request lock", "// held avoids adding the request to the client's internal data", "// structures if the client is in the process of shutting down (and", "// has not yet grabbed the request lock), or has finished shutdown", "// already (responding to each outstanding request with", "// ErrClientShutdown).", "select", "{", "case", "<-", "c", ".", "shutdown", ":", "return", "ErrClientShutdown", "\n", "default", ":", "}", "\n\n", "element", ":=", "c", ".", "requestList", ".", "PushBack", "(", "jReq", ")", "\n", "c", ".", "requestMap", "[", "jReq", ".", "id", "]", "=", "element", "\n", "return", "nil", "\n", "}" ]
// addRequest associates the passed jsonRequest with its id. This allows the // response from the remote server to be unmarshalled to the appropriate type // and sent to the specified channel when it is received. // // If the client has already begun shutting down, ErrClientShutdown is returned // and the request is not added. // // This function is safe for concurrent access.
[ "addRequest", "associates", "the", "passed", "jsonRequest", "with", "its", "id", ".", "This", "allows", "the", "response", "from", "the", "remote", "server", "to", "be", "unmarshalled", "to", "the", "appropriate", "type", "and", "sent", "to", "the", "specified", "channel", "when", "it", "is", "received", ".", "If", "the", "client", "has", "already", "begun", "shutting", "down", "ErrClientShutdown", "is", "returned", "and", "the", "request", "is", "not", "added", ".", "This", "function", "is", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L179-L198
train
btcsuite/btcd
rpcclient/infrastructure.go
removeRequest
func (c *Client) removeRequest(id uint64) *jsonRequest { c.requestLock.Lock() defer c.requestLock.Unlock() element := c.requestMap[id] if element != nil { delete(c.requestMap, id) request := c.requestList.Remove(element).(*jsonRequest) return request } return nil }
go
func (c *Client) removeRequest(id uint64) *jsonRequest { c.requestLock.Lock() defer c.requestLock.Unlock() element := c.requestMap[id] if element != nil { delete(c.requestMap, id) request := c.requestList.Remove(element).(*jsonRequest) return request } return nil }
[ "func", "(", "c", "*", "Client", ")", "removeRequest", "(", "id", "uint64", ")", "*", "jsonRequest", "{", "c", ".", "requestLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "requestLock", ".", "Unlock", "(", ")", "\n\n", "element", ":=", "c", ".", "requestMap", "[", "id", "]", "\n", "if", "element", "!=", "nil", "{", "delete", "(", "c", ".", "requestMap", ",", "id", ")", "\n", "request", ":=", "c", ".", "requestList", ".", "Remove", "(", "element", ")", ".", "(", "*", "jsonRequest", ")", "\n", "return", "request", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// removeRequest returns and removes the jsonRequest which contains the response // channel and original method associated with the passed id or nil if there is // no association. // // This function is safe for concurrent access.
[ "removeRequest", "returns", "and", "removes", "the", "jsonRequest", "which", "contains", "the", "response", "channel", "and", "original", "method", "associated", "with", "the", "passed", "id", "or", "nil", "if", "there", "is", "no", "association", ".", "This", "function", "is", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L205-L217
train
btcsuite/btcd
rpcclient/infrastructure.go
removeAllRequests
func (c *Client) removeAllRequests() { c.requestMap = make(map[uint64]*list.Element) c.requestList.Init() }
go
func (c *Client) removeAllRequests() { c.requestMap = make(map[uint64]*list.Element) c.requestList.Init() }
[ "func", "(", "c", "*", "Client", ")", "removeAllRequests", "(", ")", "{", "c", ".", "requestMap", "=", "make", "(", "map", "[", "uint64", "]", "*", "list", ".", "Element", ")", "\n", "c", ".", "requestList", ".", "Init", "(", ")", "\n", "}" ]
// removeAllRequests removes all the jsonRequests which contain the response // channels for outstanding requests. // // This function MUST be called with the request lock held.
[ "removeAllRequests", "removes", "all", "the", "jsonRequests", "which", "contain", "the", "response", "channels", "for", "outstanding", "requests", ".", "This", "function", "MUST", "be", "called", "with", "the", "request", "lock", "held", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L223-L226
train
btcsuite/btcd
rpcclient/infrastructure.go
trackRegisteredNtfns
func (c *Client) trackRegisteredNtfns(cmd interface{}) { // Nothing to do if the caller is not interested in notifications. if c.ntfnHandlers == nil { return } c.ntfnStateLock.Lock() defer c.ntfnStateLock.Unlock() switch bcmd := cmd.(type) { case *btcjson.NotifyBlocksCmd: c.ntfnState.notifyBlocks = true case *btcjson.NotifyNewTransactionsCmd: if bcmd.Verbose != nil && *bcmd.Verbose { c.ntfnState.notifyNewTxVerbose = true } else { c.ntfnState.notifyNewTx = true } case *btcjson.NotifySpentCmd: for _, op := range bcmd.OutPoints { c.ntfnState.notifySpent[op] = struct{}{} } case *btcjson.NotifyReceivedCmd: for _, addr := range bcmd.Addresses { c.ntfnState.notifyReceived[addr] = struct{}{} } } }
go
func (c *Client) trackRegisteredNtfns(cmd interface{}) { // Nothing to do if the caller is not interested in notifications. if c.ntfnHandlers == nil { return } c.ntfnStateLock.Lock() defer c.ntfnStateLock.Unlock() switch bcmd := cmd.(type) { case *btcjson.NotifyBlocksCmd: c.ntfnState.notifyBlocks = true case *btcjson.NotifyNewTransactionsCmd: if bcmd.Verbose != nil && *bcmd.Verbose { c.ntfnState.notifyNewTxVerbose = true } else { c.ntfnState.notifyNewTx = true } case *btcjson.NotifySpentCmd: for _, op := range bcmd.OutPoints { c.ntfnState.notifySpent[op] = struct{}{} } case *btcjson.NotifyReceivedCmd: for _, addr := range bcmd.Addresses { c.ntfnState.notifyReceived[addr] = struct{}{} } } }
[ "func", "(", "c", "*", "Client", ")", "trackRegisteredNtfns", "(", "cmd", "interface", "{", "}", ")", "{", "// Nothing to do if the caller is not interested in notifications.", "if", "c", ".", "ntfnHandlers", "==", "nil", "{", "return", "\n", "}", "\n\n", "c", ".", "ntfnStateLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "ntfnStateLock", ".", "Unlock", "(", ")", "\n\n", "switch", "bcmd", ":=", "cmd", ".", "(", "type", ")", "{", "case", "*", "btcjson", ".", "NotifyBlocksCmd", ":", "c", ".", "ntfnState", ".", "notifyBlocks", "=", "true", "\n\n", "case", "*", "btcjson", ".", "NotifyNewTransactionsCmd", ":", "if", "bcmd", ".", "Verbose", "!=", "nil", "&&", "*", "bcmd", ".", "Verbose", "{", "c", ".", "ntfnState", ".", "notifyNewTxVerbose", "=", "true", "\n", "}", "else", "{", "c", ".", "ntfnState", ".", "notifyNewTx", "=", "true", "\n\n", "}", "\n\n", "case", "*", "btcjson", ".", "NotifySpentCmd", ":", "for", "_", ",", "op", ":=", "range", "bcmd", ".", "OutPoints", "{", "c", ".", "ntfnState", ".", "notifySpent", "[", "op", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n\n", "case", "*", "btcjson", ".", "NotifyReceivedCmd", ":", "for", "_", ",", "addr", ":=", "range", "bcmd", ".", "Addresses", "{", "c", ".", "ntfnState", ".", "notifyReceived", "[", "addr", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}", "\n", "}" ]
// trackRegisteredNtfns examines the passed command to see if it is one of // the notification commands and updates the notification state that is used // to automatically re-establish registered notifications on reconnects.
[ "trackRegisteredNtfns", "examines", "the", "passed", "command", "to", "see", "if", "it", "is", "one", "of", "the", "notification", "commands", "and", "updates", "the", "notification", "state", "that", "is", "used", "to", "automatically", "re", "-", "establish", "registered", "notifications", "on", "reconnects", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L231-L262
train
btcsuite/btcd
rpcclient/infrastructure.go
handleMessage
func (c *Client) handleMessage(msg []byte) { // Attempt to unmarshal the message as either a notification or // response. var in inMessage in.rawResponse = new(rawResponse) in.rawNotification = new(rawNotification) err := json.Unmarshal(msg, &in) if err != nil { log.Warnf("Remote server sent invalid message: %v", err) return } // JSON-RPC 1.0 notifications are requests with a null id. if in.ID == nil { ntfn := in.rawNotification if ntfn == nil { log.Warn("Malformed notification: missing " + "method and parameters") return } if ntfn.Method == "" { log.Warn("Malformed notification: missing method") return } // params are not optional: nil isn't valid (but len == 0 is) if ntfn.Params == nil { log.Warn("Malformed notification: missing params") return } // Deliver the notification. log.Tracef("Received notification [%s]", in.Method) c.handleNotification(in.rawNotification) return } // ensure that in.ID can be converted to an integer without loss of precision if *in.ID < 0 || *in.ID != math.Trunc(*in.ID) { log.Warn("Malformed response: invalid identifier") return } if in.rawResponse == nil { log.Warn("Malformed response: missing result and error") return } id := uint64(*in.ID) log.Tracef("Received response for id %d (result %s)", id, in.Result) request := c.removeRequest(id) // Nothing more to do if there is no request associated with this reply. if request == nil || request.responseChan == nil { log.Warnf("Received unexpected reply: %s (id %d)", in.Result, id) return } // Since the command was successful, examine it to see if it's a // notification, and if is, add it to the notification state so it // can automatically be re-established on reconnect. c.trackRegisteredNtfns(request.cmd) // Deliver the response. result, err := in.rawResponse.result() request.responseChan <- &response{result: result, err: err} }
go
func (c *Client) handleMessage(msg []byte) { // Attempt to unmarshal the message as either a notification or // response. var in inMessage in.rawResponse = new(rawResponse) in.rawNotification = new(rawNotification) err := json.Unmarshal(msg, &in) if err != nil { log.Warnf("Remote server sent invalid message: %v", err) return } // JSON-RPC 1.0 notifications are requests with a null id. if in.ID == nil { ntfn := in.rawNotification if ntfn == nil { log.Warn("Malformed notification: missing " + "method and parameters") return } if ntfn.Method == "" { log.Warn("Malformed notification: missing method") return } // params are not optional: nil isn't valid (but len == 0 is) if ntfn.Params == nil { log.Warn("Malformed notification: missing params") return } // Deliver the notification. log.Tracef("Received notification [%s]", in.Method) c.handleNotification(in.rawNotification) return } // ensure that in.ID can be converted to an integer without loss of precision if *in.ID < 0 || *in.ID != math.Trunc(*in.ID) { log.Warn("Malformed response: invalid identifier") return } if in.rawResponse == nil { log.Warn("Malformed response: missing result and error") return } id := uint64(*in.ID) log.Tracef("Received response for id %d (result %s)", id, in.Result) request := c.removeRequest(id) // Nothing more to do if there is no request associated with this reply. if request == nil || request.responseChan == nil { log.Warnf("Received unexpected reply: %s (id %d)", in.Result, id) return } // Since the command was successful, examine it to see if it's a // notification, and if is, add it to the notification state so it // can automatically be re-established on reconnect. c.trackRegisteredNtfns(request.cmd) // Deliver the response. result, err := in.rawResponse.result() request.responseChan <- &response{result: result, err: err} }
[ "func", "(", "c", "*", "Client", ")", "handleMessage", "(", "msg", "[", "]", "byte", ")", "{", "// Attempt to unmarshal the message as either a notification or", "// response.", "var", "in", "inMessage", "\n", "in", ".", "rawResponse", "=", "new", "(", "rawResponse", ")", "\n", "in", ".", "rawNotification", "=", "new", "(", "rawNotification", ")", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "msg", ",", "&", "in", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "// JSON-RPC 1.0 notifications are requests with a null id.", "if", "in", ".", "ID", "==", "nil", "{", "ntfn", ":=", "in", ".", "rawNotification", "\n", "if", "ntfn", "==", "nil", "{", "log", ".", "Warn", "(", "\"", "\"", "+", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "if", "ntfn", ".", "Method", "==", "\"", "\"", "{", "log", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "// params are not optional: nil isn't valid (but len == 0 is)", "if", "ntfn", ".", "Params", "==", "nil", "{", "log", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "// Deliver the notification.", "log", ".", "Tracef", "(", "\"", "\"", ",", "in", ".", "Method", ")", "\n", "c", ".", "handleNotification", "(", "in", ".", "rawNotification", ")", "\n", "return", "\n", "}", "\n\n", "// ensure that in.ID can be converted to an integer without loss of precision", "if", "*", "in", ".", "ID", "<", "0", "||", "*", "in", ".", "ID", "!=", "math", ".", "Trunc", "(", "*", "in", ".", "ID", ")", "{", "log", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "if", "in", ".", "rawResponse", "==", "nil", "{", "log", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "id", ":=", "uint64", "(", "*", "in", ".", "ID", ")", "\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "id", ",", "in", ".", "Result", ")", "\n", "request", ":=", "c", ".", "removeRequest", "(", "id", ")", "\n\n", "// Nothing more to do if there is no request associated with this reply.", "if", "request", "==", "nil", "||", "request", ".", "responseChan", "==", "nil", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "in", ".", "Result", ",", "id", ")", "\n", "return", "\n", "}", "\n\n", "// Since the command was successful, examine it to see if it's a", "// notification, and if is, add it to the notification state so it", "// can automatically be re-established on reconnect.", "c", ".", "trackRegisteredNtfns", "(", "request", ".", "cmd", ")", "\n\n", "// Deliver the response.", "result", ",", "err", ":=", "in", ".", "rawResponse", ".", "result", "(", ")", "\n", "request", ".", "responseChan", "<-", "&", "response", "{", "result", ":", "result", ",", "err", ":", "err", "}", "\n", "}" ]
// handleMessage is the main handler for incoming notifications and responses.
[ "handleMessage", "is", "the", "main", "handler", "for", "incoming", "notifications", "and", "responses", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L309-L374
train
btcsuite/btcd
rpcclient/infrastructure.go
shouldLogReadError
func (c *Client) shouldLogReadError(err error) bool { // No logging when the connetion is being forcibly disconnected. select { case <-c.shutdown: return false default: } // No logging when the connection has been disconnected. if err == io.EOF { return false } if opErr, ok := err.(*net.OpError); ok && !opErr.Temporary() { return false } return true }
go
func (c *Client) shouldLogReadError(err error) bool { // No logging when the connetion is being forcibly disconnected. select { case <-c.shutdown: return false default: } // No logging when the connection has been disconnected. if err == io.EOF { return false } if opErr, ok := err.(*net.OpError); ok && !opErr.Temporary() { return false } return true }
[ "func", "(", "c", "*", "Client", ")", "shouldLogReadError", "(", "err", "error", ")", "bool", "{", "// No logging when the connetion is being forcibly disconnected.", "select", "{", "case", "<-", "c", ".", "shutdown", ":", "return", "false", "\n", "default", ":", "}", "\n\n", "// No logging when the connection has been disconnected.", "if", "err", "==", "io", ".", "EOF", "{", "return", "false", "\n", "}", "\n", "if", "opErr", ",", "ok", ":=", "err", ".", "(", "*", "net", ".", "OpError", ")", ";", "ok", "&&", "!", "opErr", ".", "Temporary", "(", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// shouldLogReadError returns whether or not the passed error, which is expected // to have come from reading from the websocket connection in wsInHandler, // should be logged.
[ "shouldLogReadError", "returns", "whether", "or", "not", "the", "passed", "error", "which", "is", "expected", "to", "have", "come", "from", "reading", "from", "the", "websocket", "connection", "in", "wsInHandler", "should", "be", "logged", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L379-L396
train
btcsuite/btcd
rpcclient/infrastructure.go
wsInHandler
func (c *Client) wsInHandler() { out: for { // Break out of the loop once the shutdown channel has been // closed. Use a non-blocking select here so we fall through // otherwise. select { case <-c.shutdown: break out default: } _, msg, err := c.wsConn.ReadMessage() if err != nil { // Log the error if it's not due to disconnecting. if c.shouldLogReadError(err) { log.Errorf("Websocket receive error from "+ "%s: %v", c.config.Host, err) } break out } c.handleMessage(msg) } // Ensure the connection is closed. c.Disconnect() c.wg.Done() log.Tracef("RPC client input handler done for %s", c.config.Host) }
go
func (c *Client) wsInHandler() { out: for { // Break out of the loop once the shutdown channel has been // closed. Use a non-blocking select here so we fall through // otherwise. select { case <-c.shutdown: break out default: } _, msg, err := c.wsConn.ReadMessage() if err != nil { // Log the error if it's not due to disconnecting. if c.shouldLogReadError(err) { log.Errorf("Websocket receive error from "+ "%s: %v", c.config.Host, err) } break out } c.handleMessage(msg) } // Ensure the connection is closed. c.Disconnect() c.wg.Done() log.Tracef("RPC client input handler done for %s", c.config.Host) }
[ "func", "(", "c", "*", "Client", ")", "wsInHandler", "(", ")", "{", "out", ":", "for", "{", "// Break out of the loop once the shutdown channel has been", "// closed. Use a non-blocking select here so we fall through", "// otherwise.", "select", "{", "case", "<-", "c", ".", "shutdown", ":", "break", "out", "\n", "default", ":", "}", "\n\n", "_", ",", "msg", ",", "err", ":=", "c", ".", "wsConn", ".", "ReadMessage", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// Log the error if it's not due to disconnecting.", "if", "c", ".", "shouldLogReadError", "(", "err", ")", "{", "log", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "c", ".", "config", ".", "Host", ",", "err", ")", "\n", "}", "\n", "break", "out", "\n", "}", "\n", "c", ".", "handleMessage", "(", "msg", ")", "\n", "}", "\n\n", "// Ensure the connection is closed.", "c", ".", "Disconnect", "(", ")", "\n", "c", ".", "wg", ".", "Done", "(", ")", "\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "c", ".", "config", ".", "Host", ")", "\n", "}" ]
// wsInHandler handles all incoming messages for the websocket connection // associated with the client. It must be run as a goroutine.
[ "wsInHandler", "handles", "all", "incoming", "messages", "for", "the", "websocket", "connection", "associated", "with", "the", "client", ".", "It", "must", "be", "run", "as", "a", "goroutine", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L400-L428
train
btcsuite/btcd
rpcclient/infrastructure.go
disconnectChan
func (c *Client) disconnectChan() <-chan struct{} { c.mtx.Lock() ch := c.disconnect c.mtx.Unlock() return ch }
go
func (c *Client) disconnectChan() <-chan struct{} { c.mtx.Lock() ch := c.disconnect c.mtx.Unlock() return ch }
[ "func", "(", "c", "*", "Client", ")", "disconnectChan", "(", ")", "<-", "chan", "struct", "{", "}", "{", "c", ".", "mtx", ".", "Lock", "(", ")", "\n", "ch", ":=", "c", ".", "disconnect", "\n", "c", ".", "mtx", ".", "Unlock", "(", ")", "\n", "return", "ch", "\n", "}" ]
// disconnectChan returns a copy of the current disconnect channel. The channel // is read protected by the client mutex, and is safe to call while the channel // is being reassigned during a reconnect.
[ "disconnectChan", "returns", "a", "copy", "of", "the", "current", "disconnect", "channel", ".", "The", "channel", "is", "read", "protected", "by", "the", "client", "mutex", "and", "is", "safe", "to", "call", "while", "the", "channel", "is", "being", "reassigned", "during", "a", "reconnect", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L433-L438
train
btcsuite/btcd
rpcclient/infrastructure.go
wsOutHandler
func (c *Client) wsOutHandler() { out: for { // Send any messages ready for send until the client is // disconnected closed. select { case msg := <-c.sendChan: err := c.wsConn.WriteMessage(websocket.TextMessage, msg) if err != nil { c.Disconnect() break out } case <-c.disconnectChan(): break out } } // Drain any channels before exiting so nothing is left waiting around // to send. cleanup: for { select { case <-c.sendChan: default: break cleanup } } c.wg.Done() log.Tracef("RPC client output handler done for %s", c.config.Host) }
go
func (c *Client) wsOutHandler() { out: for { // Send any messages ready for send until the client is // disconnected closed. select { case msg := <-c.sendChan: err := c.wsConn.WriteMessage(websocket.TextMessage, msg) if err != nil { c.Disconnect() break out } case <-c.disconnectChan(): break out } } // Drain any channels before exiting so nothing is left waiting around // to send. cleanup: for { select { case <-c.sendChan: default: break cleanup } } c.wg.Done() log.Tracef("RPC client output handler done for %s", c.config.Host) }
[ "func", "(", "c", "*", "Client", ")", "wsOutHandler", "(", ")", "{", "out", ":", "for", "{", "// Send any messages ready for send until the client is", "// disconnected closed.", "select", "{", "case", "msg", ":=", "<-", "c", ".", "sendChan", ":", "err", ":=", "c", ".", "wsConn", ".", "WriteMessage", "(", "websocket", ".", "TextMessage", ",", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "c", ".", "Disconnect", "(", ")", "\n", "break", "out", "\n", "}", "\n\n", "case", "<-", "c", ".", "disconnectChan", "(", ")", ":", "break", "out", "\n", "}", "\n", "}", "\n\n", "// Drain any channels before exiting so nothing is left waiting around", "// to send.", "cleanup", ":", "for", "{", "select", "{", "case", "<-", "c", ".", "sendChan", ":", "default", ":", "break", "cleanup", "\n", "}", "\n", "}", "\n", "c", ".", "wg", ".", "Done", "(", ")", "\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "c", ".", "config", ".", "Host", ")", "\n", "}" ]
// wsOutHandler handles all outgoing messages for the websocket connection. It // uses a buffered channel to serialize output messages while allowing the // sender to continue running asynchronously. It must be run as a goroutine.
[ "wsOutHandler", "handles", "all", "outgoing", "messages", "for", "the", "websocket", "connection", ".", "It", "uses", "a", "buffered", "channel", "to", "serialize", "output", "messages", "while", "allowing", "the", "sender", "to", "continue", "running", "asynchronously", ".", "It", "must", "be", "run", "as", "a", "goroutine", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L443-L473
train
btcsuite/btcd
rpcclient/infrastructure.go
sendMessage
func (c *Client) sendMessage(marshalledJSON []byte) { // Don't send the message if disconnected. select { case c.sendChan <- marshalledJSON: case <-c.disconnectChan(): return } }
go
func (c *Client) sendMessage(marshalledJSON []byte) { // Don't send the message if disconnected. select { case c.sendChan <- marshalledJSON: case <-c.disconnectChan(): return } }
[ "func", "(", "c", "*", "Client", ")", "sendMessage", "(", "marshalledJSON", "[", "]", "byte", ")", "{", "// Don't send the message if disconnected.", "select", "{", "case", "c", ".", "sendChan", "<-", "marshalledJSON", ":", "case", "<-", "c", ".", "disconnectChan", "(", ")", ":", "return", "\n", "}", "\n", "}" ]
// sendMessage sends the passed JSON to the connected server using the // websocket connection. It is backed by a buffered channel, so it will not // block until the send channel is full.
[ "sendMessage", "sends", "the", "passed", "JSON", "to", "the", "connected", "server", "using", "the", "websocket", "connection", ".", "It", "is", "backed", "by", "a", "buffered", "channel", "so", "it", "will", "not", "block", "until", "the", "send", "channel", "is", "full", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L478-L485
train
btcsuite/btcd
rpcclient/infrastructure.go
reregisterNtfns
func (c *Client) reregisterNtfns() error { // Nothing to do if the caller is not interested in notifications. if c.ntfnHandlers == nil { return nil } // In order to avoid holding the lock on the notification state for the // entire time of the potentially long running RPCs issued below, make a // copy of it and work from that. // // Also, other commands will be running concurrently which could modify // the notification state (while not under the lock of course) which // also register it with the remote RPC server, so this prevents double // registrations. c.ntfnStateLock.Lock() stateCopy := c.ntfnState.Copy() c.ntfnStateLock.Unlock() // Reregister notifyblocks if needed. if stateCopy.notifyBlocks { log.Debugf("Reregistering [notifyblocks]") if err := c.NotifyBlocks(); err != nil { return err } } // Reregister notifynewtransactions if needed. if stateCopy.notifyNewTx || stateCopy.notifyNewTxVerbose { log.Debugf("Reregistering [notifynewtransactions] (verbose=%v)", stateCopy.notifyNewTxVerbose) err := c.NotifyNewTransactions(stateCopy.notifyNewTxVerbose) if err != nil { return err } } // Reregister the combination of all previously registered notifyspent // outpoints in one command if needed. nslen := len(stateCopy.notifySpent) if nslen > 0 { outpoints := make([]btcjson.OutPoint, 0, nslen) for op := range stateCopy.notifySpent { outpoints = append(outpoints, op) } log.Debugf("Reregistering [notifyspent] outpoints: %v", outpoints) if err := c.notifySpentInternal(outpoints).Receive(); err != nil { return err } } // Reregister the combination of all previously registered // notifyreceived addresses in one command if needed. nrlen := len(stateCopy.notifyReceived) if nrlen > 0 { addresses := make([]string, 0, nrlen) for addr := range stateCopy.notifyReceived { addresses = append(addresses, addr) } log.Debugf("Reregistering [notifyreceived] addresses: %v", addresses) if err := c.notifyReceivedInternal(addresses).Receive(); err != nil { return err } } return nil }
go
func (c *Client) reregisterNtfns() error { // Nothing to do if the caller is not interested in notifications. if c.ntfnHandlers == nil { return nil } // In order to avoid holding the lock on the notification state for the // entire time of the potentially long running RPCs issued below, make a // copy of it and work from that. // // Also, other commands will be running concurrently which could modify // the notification state (while not under the lock of course) which // also register it with the remote RPC server, so this prevents double // registrations. c.ntfnStateLock.Lock() stateCopy := c.ntfnState.Copy() c.ntfnStateLock.Unlock() // Reregister notifyblocks if needed. if stateCopy.notifyBlocks { log.Debugf("Reregistering [notifyblocks]") if err := c.NotifyBlocks(); err != nil { return err } } // Reregister notifynewtransactions if needed. if stateCopy.notifyNewTx || stateCopy.notifyNewTxVerbose { log.Debugf("Reregistering [notifynewtransactions] (verbose=%v)", stateCopy.notifyNewTxVerbose) err := c.NotifyNewTransactions(stateCopy.notifyNewTxVerbose) if err != nil { return err } } // Reregister the combination of all previously registered notifyspent // outpoints in one command if needed. nslen := len(stateCopy.notifySpent) if nslen > 0 { outpoints := make([]btcjson.OutPoint, 0, nslen) for op := range stateCopy.notifySpent { outpoints = append(outpoints, op) } log.Debugf("Reregistering [notifyspent] outpoints: %v", outpoints) if err := c.notifySpentInternal(outpoints).Receive(); err != nil { return err } } // Reregister the combination of all previously registered // notifyreceived addresses in one command if needed. nrlen := len(stateCopy.notifyReceived) if nrlen > 0 { addresses := make([]string, 0, nrlen) for addr := range stateCopy.notifyReceived { addresses = append(addresses, addr) } log.Debugf("Reregistering [notifyreceived] addresses: %v", addresses) if err := c.notifyReceivedInternal(addresses).Receive(); err != nil { return err } } return nil }
[ "func", "(", "c", "*", "Client", ")", "reregisterNtfns", "(", ")", "error", "{", "// Nothing to do if the caller is not interested in notifications.", "if", "c", ".", "ntfnHandlers", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "// In order to avoid holding the lock on the notification state for the", "// entire time of the potentially long running RPCs issued below, make a", "// copy of it and work from that.", "//", "// Also, other commands will be running concurrently which could modify", "// the notification state (while not under the lock of course) which", "// also register it with the remote RPC server, so this prevents double", "// registrations.", "c", ".", "ntfnStateLock", ".", "Lock", "(", ")", "\n", "stateCopy", ":=", "c", ".", "ntfnState", ".", "Copy", "(", ")", "\n", "c", ".", "ntfnStateLock", ".", "Unlock", "(", ")", "\n\n", "// Reregister notifyblocks if needed.", "if", "stateCopy", ".", "notifyBlocks", "{", "log", ".", "Debugf", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "c", ".", "NotifyBlocks", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Reregister notifynewtransactions if needed.", "if", "stateCopy", ".", "notifyNewTx", "||", "stateCopy", ".", "notifyNewTxVerbose", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "stateCopy", ".", "notifyNewTxVerbose", ")", "\n", "err", ":=", "c", ".", "NotifyNewTransactions", "(", "stateCopy", ".", "notifyNewTxVerbose", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Reregister the combination of all previously registered notifyspent", "// outpoints in one command if needed.", "nslen", ":=", "len", "(", "stateCopy", ".", "notifySpent", ")", "\n", "if", "nslen", ">", "0", "{", "outpoints", ":=", "make", "(", "[", "]", "btcjson", ".", "OutPoint", ",", "0", ",", "nslen", ")", "\n", "for", "op", ":=", "range", "stateCopy", ".", "notifySpent", "{", "outpoints", "=", "append", "(", "outpoints", ",", "op", ")", "\n", "}", "\n", "log", ".", "Debugf", "(", "\"", "\"", ",", "outpoints", ")", "\n", "if", "err", ":=", "c", ".", "notifySpentInternal", "(", "outpoints", ")", ".", "Receive", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Reregister the combination of all previously registered", "// notifyreceived addresses in one command if needed.", "nrlen", ":=", "len", "(", "stateCopy", ".", "notifyReceived", ")", "\n", "if", "nrlen", ">", "0", "{", "addresses", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "nrlen", ")", "\n", "for", "addr", ":=", "range", "stateCopy", ".", "notifyReceived", "{", "addresses", "=", "append", "(", "addresses", ",", "addr", ")", "\n", "}", "\n", "log", ".", "Debugf", "(", "\"", "\"", ",", "addresses", ")", "\n", "if", "err", ":=", "c", ".", "notifyReceivedInternal", "(", "addresses", ")", ".", "Receive", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// reregisterNtfns creates and sends commands needed to re-establish the current // notification state associated with the client. It should only be called on // on reconnect by the resendRequests function.
[ "reregisterNtfns", "creates", "and", "sends", "commands", "needed", "to", "re", "-", "establish", "the", "current", "notification", "state", "associated", "with", "the", "client", ".", "It", "should", "only", "be", "called", "on", "on", "reconnect", "by", "the", "resendRequests", "function", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L490-L555
train
btcsuite/btcd
rpcclient/infrastructure.go
resendRequests
func (c *Client) resendRequests() { // Set the notification state back up. If anything goes wrong, // disconnect the client. if err := c.reregisterNtfns(); err != nil { log.Warnf("Unable to re-establish notification state: %v", err) c.Disconnect() return } // Since it's possible to block on send and more requests might be // added by the caller while resending, make a copy of all of the // requests that need to be resent now and work from the copy. This // also allows the lock to be released quickly. c.requestLock.Lock() resendReqs := make([]*jsonRequest, 0, c.requestList.Len()) var nextElem *list.Element for e := c.requestList.Front(); e != nil; e = nextElem { nextElem = e.Next() jReq := e.Value.(*jsonRequest) if _, ok := ignoreResends[jReq.method]; ok { // If a request is not sent on reconnect, remove it // from the request structures, since no reply is // expected. delete(c.requestMap, jReq.id) c.requestList.Remove(e) } else { resendReqs = append(resendReqs, jReq) } } c.requestLock.Unlock() for _, jReq := range resendReqs { // Stop resending commands if the client disconnected again // since the next reconnect will handle them. if c.Disconnected() { return } log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) c.sendMessage(jReq.marshalledJSON) } }
go
func (c *Client) resendRequests() { // Set the notification state back up. If anything goes wrong, // disconnect the client. if err := c.reregisterNtfns(); err != nil { log.Warnf("Unable to re-establish notification state: %v", err) c.Disconnect() return } // Since it's possible to block on send and more requests might be // added by the caller while resending, make a copy of all of the // requests that need to be resent now and work from the copy. This // also allows the lock to be released quickly. c.requestLock.Lock() resendReqs := make([]*jsonRequest, 0, c.requestList.Len()) var nextElem *list.Element for e := c.requestList.Front(); e != nil; e = nextElem { nextElem = e.Next() jReq := e.Value.(*jsonRequest) if _, ok := ignoreResends[jReq.method]; ok { // If a request is not sent on reconnect, remove it // from the request structures, since no reply is // expected. delete(c.requestMap, jReq.id) c.requestList.Remove(e) } else { resendReqs = append(resendReqs, jReq) } } c.requestLock.Unlock() for _, jReq := range resendReqs { // Stop resending commands if the client disconnected again // since the next reconnect will handle them. if c.Disconnected() { return } log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) c.sendMessage(jReq.marshalledJSON) } }
[ "func", "(", "c", "*", "Client", ")", "resendRequests", "(", ")", "{", "// Set the notification state back up. If anything goes wrong,", "// disconnect the client.", "if", "err", ":=", "c", ".", "reregisterNtfns", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n", "c", ".", "Disconnect", "(", ")", "\n", "return", "\n", "}", "\n\n", "// Since it's possible to block on send and more requests might be", "// added by the caller while resending, make a copy of all of the", "// requests that need to be resent now and work from the copy. This", "// also allows the lock to be released quickly.", "c", ".", "requestLock", ".", "Lock", "(", ")", "\n", "resendReqs", ":=", "make", "(", "[", "]", "*", "jsonRequest", ",", "0", ",", "c", ".", "requestList", ".", "Len", "(", ")", ")", "\n", "var", "nextElem", "*", "list", ".", "Element", "\n", "for", "e", ":=", "c", ".", "requestList", ".", "Front", "(", ")", ";", "e", "!=", "nil", ";", "e", "=", "nextElem", "{", "nextElem", "=", "e", ".", "Next", "(", ")", "\n\n", "jReq", ":=", "e", ".", "Value", ".", "(", "*", "jsonRequest", ")", "\n", "if", "_", ",", "ok", ":=", "ignoreResends", "[", "jReq", ".", "method", "]", ";", "ok", "{", "// If a request is not sent on reconnect, remove it", "// from the request structures, since no reply is", "// expected.", "delete", "(", "c", ".", "requestMap", ",", "jReq", ".", "id", ")", "\n", "c", ".", "requestList", ".", "Remove", "(", "e", ")", "\n", "}", "else", "{", "resendReqs", "=", "append", "(", "resendReqs", ",", "jReq", ")", "\n", "}", "\n", "}", "\n", "c", ".", "requestLock", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "jReq", ":=", "range", "resendReqs", "{", "// Stop resending commands if the client disconnected again", "// since the next reconnect will handle them.", "if", "c", ".", "Disconnected", "(", ")", "{", "return", "\n", "}", "\n\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "jReq", ".", "method", ",", "jReq", ".", "id", ")", "\n", "c", ".", "sendMessage", "(", "jReq", ".", "marshalledJSON", ")", "\n", "}", "\n", "}" ]
// resendRequests resends any requests that had not completed when the client // disconnected. It is intended to be called once the client has reconnected as // a separate goroutine.
[ "resendRequests", "resends", "any", "requests", "that", "had", "not", "completed", "when", "the", "client", "disconnected", ".", "It", "is", "intended", "to", "be", "called", "once", "the", "client", "has", "reconnected", "as", "a", "separate", "goroutine", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L566-L609
train
btcsuite/btcd
rpcclient/infrastructure.go
handleSendPostMessage
func (c *Client) handleSendPostMessage(details *sendPostDetails) { jReq := details.jsonRequest log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) httpResponse, err := c.httpClient.Do(details.httpRequest) if err != nil { jReq.responseChan <- &response{err: err} return } // Read the raw bytes and close the response. respBytes, err := ioutil.ReadAll(httpResponse.Body) httpResponse.Body.Close() if err != nil { err = fmt.Errorf("error reading json reply: %v", err) jReq.responseChan <- &response{err: err} return } // Try to unmarshal the response as a regular JSON-RPC response. var resp rawResponse err = json.Unmarshal(respBytes, &resp) if err != nil { // When the response itself isn't a valid JSON-RPC response // return an error which includes the HTTP status code and raw // response bytes. err = fmt.Errorf("status code: %d, response: %q", httpResponse.StatusCode, string(respBytes)) jReq.responseChan <- &response{err: err} return } res, err := resp.result() jReq.responseChan <- &response{result: res, err: err} }
go
func (c *Client) handleSendPostMessage(details *sendPostDetails) { jReq := details.jsonRequest log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) httpResponse, err := c.httpClient.Do(details.httpRequest) if err != nil { jReq.responseChan <- &response{err: err} return } // Read the raw bytes and close the response. respBytes, err := ioutil.ReadAll(httpResponse.Body) httpResponse.Body.Close() if err != nil { err = fmt.Errorf("error reading json reply: %v", err) jReq.responseChan <- &response{err: err} return } // Try to unmarshal the response as a regular JSON-RPC response. var resp rawResponse err = json.Unmarshal(respBytes, &resp) if err != nil { // When the response itself isn't a valid JSON-RPC response // return an error which includes the HTTP status code and raw // response bytes. err = fmt.Errorf("status code: %d, response: %q", httpResponse.StatusCode, string(respBytes)) jReq.responseChan <- &response{err: err} return } res, err := resp.result() jReq.responseChan <- &response{result: res, err: err} }
[ "func", "(", "c", "*", "Client", ")", "handleSendPostMessage", "(", "details", "*", "sendPostDetails", ")", "{", "jReq", ":=", "details", ".", "jsonRequest", "\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "jReq", ".", "method", ",", "jReq", ".", "id", ")", "\n", "httpResponse", ",", "err", ":=", "c", ".", "httpClient", ".", "Do", "(", "details", ".", "httpRequest", ")", "\n", "if", "err", "!=", "nil", "{", "jReq", ".", "responseChan", "<-", "&", "response", "{", "err", ":", "err", "}", "\n", "return", "\n", "}", "\n\n", "// Read the raw bytes and close the response.", "respBytes", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "httpResponse", ".", "Body", ")", "\n", "httpResponse", ".", "Body", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "jReq", ".", "responseChan", "<-", "&", "response", "{", "err", ":", "err", "}", "\n", "return", "\n", "}", "\n\n", "// Try to unmarshal the response as a regular JSON-RPC response.", "var", "resp", "rawResponse", "\n", "err", "=", "json", ".", "Unmarshal", "(", "respBytes", ",", "&", "resp", ")", "\n", "if", "err", "!=", "nil", "{", "// When the response itself isn't a valid JSON-RPC response", "// return an error which includes the HTTP status code and raw", "// response bytes.", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "httpResponse", ".", "StatusCode", ",", "string", "(", "respBytes", ")", ")", "\n", "jReq", ".", "responseChan", "<-", "&", "response", "{", "err", ":", "err", "}", "\n", "return", "\n", "}", "\n\n", "res", ",", "err", ":=", "resp", ".", "result", "(", ")", "\n", "jReq", ".", "responseChan", "<-", "&", "response", "{", "result", ":", "res", ",", "err", ":", "err", "}", "\n", "}" ]
// handleSendPostMessage handles performing the passed HTTP request, reading the // result, unmarshalling it, and delivering the unmarshalled result to the // provided response channel.
[ "handleSendPostMessage", "handles", "performing", "the", "passed", "HTTP", "request", "reading", "the", "result", "unmarshalling", "it", "and", "delivering", "the", "unmarshalled", "result", "to", "the", "provided", "response", "channel", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L692-L725
train
btcsuite/btcd
rpcclient/infrastructure.go
sendPostHandler
func (c *Client) sendPostHandler() { out: for { // Send any messages ready for send until the shutdown channel // is closed. select { case details := <-c.sendPostChan: c.handleSendPostMessage(details) case <-c.shutdown: break out } } // Drain any wait channels before exiting so nothing is left waiting // around to send. cleanup: for { select { case details := <-c.sendPostChan: details.jsonRequest.responseChan <- &response{ result: nil, err: ErrClientShutdown, } default: break cleanup } } c.wg.Done() log.Tracef("RPC client send handler done for %s", c.config.Host) }
go
func (c *Client) sendPostHandler() { out: for { // Send any messages ready for send until the shutdown channel // is closed. select { case details := <-c.sendPostChan: c.handleSendPostMessage(details) case <-c.shutdown: break out } } // Drain any wait channels before exiting so nothing is left waiting // around to send. cleanup: for { select { case details := <-c.sendPostChan: details.jsonRequest.responseChan <- &response{ result: nil, err: ErrClientShutdown, } default: break cleanup } } c.wg.Done() log.Tracef("RPC client send handler done for %s", c.config.Host) }
[ "func", "(", "c", "*", "Client", ")", "sendPostHandler", "(", ")", "{", "out", ":", "for", "{", "// Send any messages ready for send until the shutdown channel", "// is closed.", "select", "{", "case", "details", ":=", "<-", "c", ".", "sendPostChan", ":", "c", ".", "handleSendPostMessage", "(", "details", ")", "\n\n", "case", "<-", "c", ".", "shutdown", ":", "break", "out", "\n", "}", "\n", "}", "\n\n", "// Drain any wait channels before exiting so nothing is left waiting", "// around to send.", "cleanup", ":", "for", "{", "select", "{", "case", "details", ":=", "<-", "c", ".", "sendPostChan", ":", "details", ".", "jsonRequest", ".", "responseChan", "<-", "&", "response", "{", "result", ":", "nil", ",", "err", ":", "ErrClientShutdown", ",", "}", "\n\n", "default", ":", "break", "cleanup", "\n", "}", "\n", "}", "\n", "c", ".", "wg", ".", "Done", "(", ")", "\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "c", ".", "config", ".", "Host", ")", "\n\n", "}" ]
// sendPostHandler handles all outgoing messages when the client is running // in HTTP POST mode. It uses a buffered channel to serialize output messages // while allowing the sender to continue running asynchronously. It must be run // as a goroutine.
[ "sendPostHandler", "handles", "all", "outgoing", "messages", "when", "the", "client", "is", "running", "in", "HTTP", "POST", "mode", ".", "It", "uses", "a", "buffered", "channel", "to", "serialize", "output", "messages", "while", "allowing", "the", "sender", "to", "continue", "running", "asynchronously", ".", "It", "must", "be", "run", "as", "a", "goroutine", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L731-L763
train
btcsuite/btcd
rpcclient/infrastructure.go
sendPostRequest
func (c *Client) sendPostRequest(httpReq *http.Request, jReq *jsonRequest) { // Don't send the message if shutting down. select { case <-c.shutdown: jReq.responseChan <- &response{result: nil, err: ErrClientShutdown} default: } c.sendPostChan <- &sendPostDetails{ jsonRequest: jReq, httpRequest: httpReq, } }
go
func (c *Client) sendPostRequest(httpReq *http.Request, jReq *jsonRequest) { // Don't send the message if shutting down. select { case <-c.shutdown: jReq.responseChan <- &response{result: nil, err: ErrClientShutdown} default: } c.sendPostChan <- &sendPostDetails{ jsonRequest: jReq, httpRequest: httpReq, } }
[ "func", "(", "c", "*", "Client", ")", "sendPostRequest", "(", "httpReq", "*", "http", ".", "Request", ",", "jReq", "*", "jsonRequest", ")", "{", "// Don't send the message if shutting down.", "select", "{", "case", "<-", "c", ".", "shutdown", ":", "jReq", ".", "responseChan", "<-", "&", "response", "{", "result", ":", "nil", ",", "err", ":", "ErrClientShutdown", "}", "\n", "default", ":", "}", "\n\n", "c", ".", "sendPostChan", "<-", "&", "sendPostDetails", "{", "jsonRequest", ":", "jReq", ",", "httpRequest", ":", "httpReq", ",", "}", "\n", "}" ]
// sendPostRequest sends the passed HTTP request to the RPC server using the // HTTP client associated with the client. It is backed by a buffered channel, // so it will not block until the send channel is full.
[ "sendPostRequest", "sends", "the", "passed", "HTTP", "request", "to", "the", "RPC", "server", "using", "the", "HTTP", "client", "associated", "with", "the", "client", ".", "It", "is", "backed", "by", "a", "buffered", "channel", "so", "it", "will", "not", "block", "until", "the", "send", "channel", "is", "full", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L768-L780
train
btcsuite/btcd
rpcclient/infrastructure.go
newFutureError
func newFutureError(err error) chan *response { responseChan := make(chan *response, 1) responseChan <- &response{err: err} return responseChan }
go
func newFutureError(err error) chan *response { responseChan := make(chan *response, 1) responseChan <- &response{err: err} return responseChan }
[ "func", "newFutureError", "(", "err", "error", ")", "chan", "*", "response", "{", "responseChan", ":=", "make", "(", "chan", "*", "response", ",", "1", ")", "\n", "responseChan", "<-", "&", "response", "{", "err", ":", "err", "}", "\n", "return", "responseChan", "\n", "}" ]
// newFutureError returns a new future result channel that already has the // passed error waitin on the channel with the reply set to nil. This is useful // to easily return errors from the various Async functions.
[ "newFutureError", "returns", "a", "new", "future", "result", "channel", "that", "already", "has", "the", "passed", "error", "waitin", "on", "the", "channel", "with", "the", "reply", "set", "to", "nil", ".", "This", "is", "useful", "to", "easily", "return", "errors", "from", "the", "various", "Async", "functions", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L785-L789
train
btcsuite/btcd
rpcclient/infrastructure.go
receiveFuture
func receiveFuture(f chan *response) ([]byte, error) { // Wait for a response on the returned channel. r := <-f return r.result, r.err }
go
func receiveFuture(f chan *response) ([]byte, error) { // Wait for a response on the returned channel. r := <-f return r.result, r.err }
[ "func", "receiveFuture", "(", "f", "chan", "*", "response", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// Wait for a response on the returned channel.", "r", ":=", "<-", "f", "\n", "return", "r", ".", "result", ",", "r", ".", "err", "\n", "}" ]
// receiveFuture receives from the passed futureResult channel to extract a // reply or any errors. The examined errors include an error in the // futureResult and the error in the reply from the server. This will block // until the result is available on the passed channel.
[ "receiveFuture", "receives", "from", "the", "passed", "futureResult", "channel", "to", "extract", "a", "reply", "or", "any", "errors", ".", "The", "examined", "errors", "include", "an", "error", "in", "the", "futureResult", "and", "the", "error", "in", "the", "reply", "from", "the", "server", ".", "This", "will", "block", "until", "the", "result", "is", "available", "on", "the", "passed", "channel", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L795-L799
train
btcsuite/btcd
rpcclient/infrastructure.go
sendPost
func (c *Client) sendPost(jReq *jsonRequest) { // Generate a request to the configured RPC server. protocol := "http" if !c.config.DisableTLS { protocol = "https" } url := protocol + "://" + c.config.Host bodyReader := bytes.NewReader(jReq.marshalledJSON) httpReq, err := http.NewRequest("POST", url, bodyReader) if err != nil { jReq.responseChan <- &response{result: nil, err: err} return } httpReq.Close = true httpReq.Header.Set("Content-Type", "application/json") // Configure basic access authorization. httpReq.SetBasicAuth(c.config.User, c.config.Pass) log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) c.sendPostRequest(httpReq, jReq) }
go
func (c *Client) sendPost(jReq *jsonRequest) { // Generate a request to the configured RPC server. protocol := "http" if !c.config.DisableTLS { protocol = "https" } url := protocol + "://" + c.config.Host bodyReader := bytes.NewReader(jReq.marshalledJSON) httpReq, err := http.NewRequest("POST", url, bodyReader) if err != nil { jReq.responseChan <- &response{result: nil, err: err} return } httpReq.Close = true httpReq.Header.Set("Content-Type", "application/json") // Configure basic access authorization. httpReq.SetBasicAuth(c.config.User, c.config.Pass) log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) c.sendPostRequest(httpReq, jReq) }
[ "func", "(", "c", "*", "Client", ")", "sendPost", "(", "jReq", "*", "jsonRequest", ")", "{", "// Generate a request to the configured RPC server.", "protocol", ":=", "\"", "\"", "\n", "if", "!", "c", ".", "config", ".", "DisableTLS", "{", "protocol", "=", "\"", "\"", "\n", "}", "\n", "url", ":=", "protocol", "+", "\"", "\"", "+", "c", ".", "config", ".", "Host", "\n", "bodyReader", ":=", "bytes", ".", "NewReader", "(", "jReq", ".", "marshalledJSON", ")", "\n", "httpReq", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "url", ",", "bodyReader", ")", "\n", "if", "err", "!=", "nil", "{", "jReq", ".", "responseChan", "<-", "&", "response", "{", "result", ":", "nil", ",", "err", ":", "err", "}", "\n", "return", "\n", "}", "\n", "httpReq", ".", "Close", "=", "true", "\n", "httpReq", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Configure basic access authorization.", "httpReq", ".", "SetBasicAuth", "(", "c", ".", "config", ".", "User", ",", "c", ".", "config", ".", "Pass", ")", "\n\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "jReq", ".", "method", ",", "jReq", ".", "id", ")", "\n", "c", ".", "sendPostRequest", "(", "httpReq", ",", "jReq", ")", "\n", "}" ]
// sendPost sends the passed request to the server by issuing an HTTP POST // request using the provided response channel for the reply. Typically a new // connection is opened and closed for each command when using this method, // however, the underlying HTTP client might coalesce multiple commands // depending on several factors including the remote server configuration.
[ "sendPost", "sends", "the", "passed", "request", "to", "the", "server", "by", "issuing", "an", "HTTP", "POST", "request", "using", "the", "provided", "response", "channel", "for", "the", "reply", ".", "Typically", "a", "new", "connection", "is", "opened", "and", "closed", "for", "each", "command", "when", "using", "this", "method", "however", "the", "underlying", "HTTP", "client", "might", "coalesce", "multiple", "commands", "depending", "on", "several", "factors", "including", "the", "remote", "server", "configuration", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L806-L827
train
btcsuite/btcd
rpcclient/infrastructure.go
sendRequest
func (c *Client) sendRequest(jReq *jsonRequest) { // Choose which marshal and send function to use depending on whether // the client running in HTTP POST mode or not. When running in HTTP // POST mode, the command is issued via an HTTP client. Otherwise, // the command is issued via the asynchronous websocket channels. if c.config.HTTPPostMode { c.sendPost(jReq) return } // Check whether the websocket connection has never been established, // in which case the handler goroutines are not running. select { case <-c.connEstablished: default: jReq.responseChan <- &response{err: ErrClientNotConnected} return } // Add the request to the internal tracking map so the response from the // remote server can be properly detected and routed to the response // channel. Then send the marshalled request via the websocket // connection. if err := c.addRequest(jReq); err != nil { jReq.responseChan <- &response{err: err} return } log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) c.sendMessage(jReq.marshalledJSON) }
go
func (c *Client) sendRequest(jReq *jsonRequest) { // Choose which marshal and send function to use depending on whether // the client running in HTTP POST mode or not. When running in HTTP // POST mode, the command is issued via an HTTP client. Otherwise, // the command is issued via the asynchronous websocket channels. if c.config.HTTPPostMode { c.sendPost(jReq) return } // Check whether the websocket connection has never been established, // in which case the handler goroutines are not running. select { case <-c.connEstablished: default: jReq.responseChan <- &response{err: ErrClientNotConnected} return } // Add the request to the internal tracking map so the response from the // remote server can be properly detected and routed to the response // channel. Then send the marshalled request via the websocket // connection. if err := c.addRequest(jReq); err != nil { jReq.responseChan <- &response{err: err} return } log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) c.sendMessage(jReq.marshalledJSON) }
[ "func", "(", "c", "*", "Client", ")", "sendRequest", "(", "jReq", "*", "jsonRequest", ")", "{", "// Choose which marshal and send function to use depending on whether", "// the client running in HTTP POST mode or not. When running in HTTP", "// POST mode, the command is issued via an HTTP client. Otherwise,", "// the command is issued via the asynchronous websocket channels.", "if", "c", ".", "config", ".", "HTTPPostMode", "{", "c", ".", "sendPost", "(", "jReq", ")", "\n", "return", "\n", "}", "\n\n", "// Check whether the websocket connection has never been established,", "// in which case the handler goroutines are not running.", "select", "{", "case", "<-", "c", ".", "connEstablished", ":", "default", ":", "jReq", ".", "responseChan", "<-", "&", "response", "{", "err", ":", "ErrClientNotConnected", "}", "\n", "return", "\n", "}", "\n\n", "// Add the request to the internal tracking map so the response from the", "// remote server can be properly detected and routed to the response", "// channel. Then send the marshalled request via the websocket", "// connection.", "if", "err", ":=", "c", ".", "addRequest", "(", "jReq", ")", ";", "err", "!=", "nil", "{", "jReq", ".", "responseChan", "<-", "&", "response", "{", "err", ":", "err", "}", "\n", "return", "\n", "}", "\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "jReq", ".", "method", ",", "jReq", ".", "id", ")", "\n", "c", ".", "sendMessage", "(", "jReq", ".", "marshalledJSON", ")", "\n", "}" ]
// sendRequest sends the passed json request to the associated server using the // provided response channel for the reply. It handles both websocket and HTTP // POST mode depending on the configuration of the client.
[ "sendRequest", "sends", "the", "passed", "json", "request", "to", "the", "associated", "server", "using", "the", "provided", "response", "channel", "for", "the", "reply", ".", "It", "handles", "both", "websocket", "and", "HTTP", "POST", "mode", "depending", "on", "the", "configuration", "of", "the", "client", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L832-L861
train
btcsuite/btcd
rpcclient/infrastructure.go
sendCmd
func (c *Client) sendCmd(cmd interface{}) chan *response { // Get the method associated with the command. method, err := btcjson.CmdMethod(cmd) if err != nil { return newFutureError(err) } // Marshal the command. id := c.NextID() marshalledJSON, err := btcjson.MarshalCmd(id, cmd) if err != nil { return newFutureError(err) } // Generate the request and send it along with a channel to respond on. responseChan := make(chan *response, 1) jReq := &jsonRequest{ id: id, method: method, cmd: cmd, marshalledJSON: marshalledJSON, responseChan: responseChan, } c.sendRequest(jReq) return responseChan }
go
func (c *Client) sendCmd(cmd interface{}) chan *response { // Get the method associated with the command. method, err := btcjson.CmdMethod(cmd) if err != nil { return newFutureError(err) } // Marshal the command. id := c.NextID() marshalledJSON, err := btcjson.MarshalCmd(id, cmd) if err != nil { return newFutureError(err) } // Generate the request and send it along with a channel to respond on. responseChan := make(chan *response, 1) jReq := &jsonRequest{ id: id, method: method, cmd: cmd, marshalledJSON: marshalledJSON, responseChan: responseChan, } c.sendRequest(jReq) return responseChan }
[ "func", "(", "c", "*", "Client", ")", "sendCmd", "(", "cmd", "interface", "{", "}", ")", "chan", "*", "response", "{", "// Get the method associated with the command.", "method", ",", "err", ":=", "btcjson", ".", "CmdMethod", "(", "cmd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "newFutureError", "(", "err", ")", "\n", "}", "\n\n", "// Marshal the command.", "id", ":=", "c", ".", "NextID", "(", ")", "\n", "marshalledJSON", ",", "err", ":=", "btcjson", ".", "MarshalCmd", "(", "id", ",", "cmd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "newFutureError", "(", "err", ")", "\n", "}", "\n\n", "// Generate the request and send it along with a channel to respond on.", "responseChan", ":=", "make", "(", "chan", "*", "response", ",", "1", ")", "\n", "jReq", ":=", "&", "jsonRequest", "{", "id", ":", "id", ",", "method", ":", "method", ",", "cmd", ":", "cmd", ",", "marshalledJSON", ":", "marshalledJSON", ",", "responseChan", ":", "responseChan", ",", "}", "\n", "c", ".", "sendRequest", "(", "jReq", ")", "\n\n", "return", "responseChan", "\n", "}" ]
// sendCmd sends the passed command to the associated server and returns a // response channel on which the reply will be delivered at some point in the // future. It handles both websocket and HTTP POST mode depending on the // configuration of the client.
[ "sendCmd", "sends", "the", "passed", "command", "to", "the", "associated", "server", "and", "returns", "a", "response", "channel", "on", "which", "the", "reply", "will", "be", "delivered", "at", "some", "point", "in", "the", "future", ".", "It", "handles", "both", "websocket", "and", "HTTP", "POST", "mode", "depending", "on", "the", "configuration", "of", "the", "client", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L867-L893
train
btcsuite/btcd
rpcclient/infrastructure.go
Disconnected
func (c *Client) Disconnected() bool { c.mtx.Lock() defer c.mtx.Unlock() select { case <-c.connEstablished: return c.disconnected default: return false } }
go
func (c *Client) Disconnected() bool { c.mtx.Lock() defer c.mtx.Unlock() select { case <-c.connEstablished: return c.disconnected default: return false } }
[ "func", "(", "c", "*", "Client", ")", "Disconnected", "(", ")", "bool", "{", "c", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mtx", ".", "Unlock", "(", ")", "\n\n", "select", "{", "case", "<-", "c", ".", "connEstablished", ":", "return", "c", ".", "disconnected", "\n", "default", ":", "return", "false", "\n", "}", "\n", "}" ]
// Disconnected returns whether or not the server is disconnected. If a // websocket client was created but never connected, this also returns false.
[ "Disconnected", "returns", "whether", "or", "not", "the", "server", "is", "disconnected", ".", "If", "a", "websocket", "client", "was", "created", "but", "never", "connected", "this", "also", "returns", "false", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L906-L916
train
btcsuite/btcd
rpcclient/infrastructure.go
doDisconnect
func (c *Client) doDisconnect() bool { if c.config.HTTPPostMode { return false } c.mtx.Lock() defer c.mtx.Unlock() // Nothing to do if already disconnected. if c.disconnected { return false } log.Tracef("Disconnecting RPC client %s", c.config.Host) close(c.disconnect) if c.wsConn != nil { c.wsConn.Close() } c.disconnected = true return true }
go
func (c *Client) doDisconnect() bool { if c.config.HTTPPostMode { return false } c.mtx.Lock() defer c.mtx.Unlock() // Nothing to do if already disconnected. if c.disconnected { return false } log.Tracef("Disconnecting RPC client %s", c.config.Host) close(c.disconnect) if c.wsConn != nil { c.wsConn.Close() } c.disconnected = true return true }
[ "func", "(", "c", "*", "Client", ")", "doDisconnect", "(", ")", "bool", "{", "if", "c", ".", "config", ".", "HTTPPostMode", "{", "return", "false", "\n", "}", "\n\n", "c", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mtx", ".", "Unlock", "(", ")", "\n\n", "// Nothing to do if already disconnected.", "if", "c", ".", "disconnected", "{", "return", "false", "\n", "}", "\n\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "c", ".", "config", ".", "Host", ")", "\n", "close", "(", "c", ".", "disconnect", ")", "\n", "if", "c", ".", "wsConn", "!=", "nil", "{", "c", ".", "wsConn", ".", "Close", "(", ")", "\n", "}", "\n", "c", ".", "disconnected", "=", "true", "\n", "return", "true", "\n", "}" ]
// doDisconnect disconnects the websocket associated with the client if it // hasn't already been disconnected. It will return false if the disconnect is // not needed or the client is running in HTTP POST mode. // // This function is safe for concurrent access.
[ "doDisconnect", "disconnects", "the", "websocket", "associated", "with", "the", "client", "if", "it", "hasn", "t", "already", "been", "disconnected", ".", "It", "will", "return", "false", "if", "the", "disconnect", "is", "not", "needed", "or", "the", "client", "is", "running", "in", "HTTP", "POST", "mode", ".", "This", "function", "is", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L923-L943
train
btcsuite/btcd
rpcclient/infrastructure.go
doShutdown
func (c *Client) doShutdown() bool { // Ignore the shutdown request if the client is already in the process // of shutting down or already shutdown. select { case <-c.shutdown: return false default: } log.Tracef("Shutting down RPC client %s", c.config.Host) close(c.shutdown) return true }
go
func (c *Client) doShutdown() bool { // Ignore the shutdown request if the client is already in the process // of shutting down or already shutdown. select { case <-c.shutdown: return false default: } log.Tracef("Shutting down RPC client %s", c.config.Host) close(c.shutdown) return true }
[ "func", "(", "c", "*", "Client", ")", "doShutdown", "(", ")", "bool", "{", "// Ignore the shutdown request if the client is already in the process", "// of shutting down or already shutdown.", "select", "{", "case", "<-", "c", ".", "shutdown", ":", "return", "false", "\n", "default", ":", "}", "\n\n", "log", ".", "Tracef", "(", "\"", "\"", ",", "c", ".", "config", ".", "Host", ")", "\n", "close", "(", "c", ".", "shutdown", ")", "\n", "return", "true", "\n", "}" ]
// doShutdown closes the shutdown channel and logs the shutdown unless shutdown // is already in progress. It will return false if the shutdown is not needed. // // This function is safe for concurrent access.
[ "doShutdown", "closes", "the", "shutdown", "channel", "and", "logs", "the", "shutdown", "unless", "shutdown", "is", "already", "in", "progress", ".", "It", "will", "return", "false", "if", "the", "shutdown", "is", "not", "needed", ".", "This", "function", "is", "safe", "for", "concurrent", "access", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L949-L961
train
btcsuite/btcd
rpcclient/infrastructure.go
Disconnect
func (c *Client) Disconnect() { // Nothing to do if already disconnected or running in HTTP POST mode. if !c.doDisconnect() { return } c.requestLock.Lock() defer c.requestLock.Unlock() // When operating without auto reconnect, send errors to any pending // requests and shutdown the client. if c.config.DisableAutoReconnect { for e := c.requestList.Front(); e != nil; e = e.Next() { req := e.Value.(*jsonRequest) req.responseChan <- &response{ result: nil, err: ErrClientDisconnect, } } c.removeAllRequests() c.doShutdown() } }
go
func (c *Client) Disconnect() { // Nothing to do if already disconnected or running in HTTP POST mode. if !c.doDisconnect() { return } c.requestLock.Lock() defer c.requestLock.Unlock() // When operating without auto reconnect, send errors to any pending // requests and shutdown the client. if c.config.DisableAutoReconnect { for e := c.requestList.Front(); e != nil; e = e.Next() { req := e.Value.(*jsonRequest) req.responseChan <- &response{ result: nil, err: ErrClientDisconnect, } } c.removeAllRequests() c.doShutdown() } }
[ "func", "(", "c", "*", "Client", ")", "Disconnect", "(", ")", "{", "// Nothing to do if already disconnected or running in HTTP POST mode.", "if", "!", "c", ".", "doDisconnect", "(", ")", "{", "return", "\n", "}", "\n\n", "c", ".", "requestLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "requestLock", ".", "Unlock", "(", ")", "\n\n", "// When operating without auto reconnect, send errors to any pending", "// requests and shutdown the client.", "if", "c", ".", "config", ".", "DisableAutoReconnect", "{", "for", "e", ":=", "c", ".", "requestList", ".", "Front", "(", ")", ";", "e", "!=", "nil", ";", "e", "=", "e", ".", "Next", "(", ")", "{", "req", ":=", "e", ".", "Value", ".", "(", "*", "jsonRequest", ")", "\n", "req", ".", "responseChan", "<-", "&", "response", "{", "result", ":", "nil", ",", "err", ":", "ErrClientDisconnect", ",", "}", "\n", "}", "\n", "c", ".", "removeAllRequests", "(", ")", "\n", "c", ".", "doShutdown", "(", ")", "\n", "}", "\n", "}" ]
// Disconnect disconnects the current websocket associated with the client. The // connection will automatically be re-established unless the client was // created with the DisableAutoReconnect flag. // // This function has no effect when the client is running in HTTP POST mode.
[ "Disconnect", "disconnects", "the", "current", "websocket", "associated", "with", "the", "client", ".", "The", "connection", "will", "automatically", "be", "re", "-", "established", "unless", "the", "client", "was", "created", "with", "the", "DisableAutoReconnect", "flag", ".", "This", "function", "has", "no", "effect", "when", "the", "client", "is", "running", "in", "HTTP", "POST", "mode", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L968-L990
train
btcsuite/btcd
rpcclient/infrastructure.go
Shutdown
func (c *Client) Shutdown() { // Do the shutdown under the request lock to prevent clients from // adding new requests while the client shutdown process is initiated. c.requestLock.Lock() defer c.requestLock.Unlock() // Ignore the shutdown request if the client is already in the process // of shutting down or already shutdown. if !c.doShutdown() { return } // Send the ErrClientShutdown error to any pending requests. for e := c.requestList.Front(); e != nil; e = e.Next() { req := e.Value.(*jsonRequest) req.responseChan <- &response{ result: nil, err: ErrClientShutdown, } } c.removeAllRequests() // Disconnect the client if needed. c.doDisconnect() }
go
func (c *Client) Shutdown() { // Do the shutdown under the request lock to prevent clients from // adding new requests while the client shutdown process is initiated. c.requestLock.Lock() defer c.requestLock.Unlock() // Ignore the shutdown request if the client is already in the process // of shutting down or already shutdown. if !c.doShutdown() { return } // Send the ErrClientShutdown error to any pending requests. for e := c.requestList.Front(); e != nil; e = e.Next() { req := e.Value.(*jsonRequest) req.responseChan <- &response{ result: nil, err: ErrClientShutdown, } } c.removeAllRequests() // Disconnect the client if needed. c.doDisconnect() }
[ "func", "(", "c", "*", "Client", ")", "Shutdown", "(", ")", "{", "// Do the shutdown under the request lock to prevent clients from", "// adding new requests while the client shutdown process is initiated.", "c", ".", "requestLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "requestLock", ".", "Unlock", "(", ")", "\n\n", "// Ignore the shutdown request if the client is already in the process", "// of shutting down or already shutdown.", "if", "!", "c", ".", "doShutdown", "(", ")", "{", "return", "\n", "}", "\n\n", "// Send the ErrClientShutdown error to any pending requests.", "for", "e", ":=", "c", ".", "requestList", ".", "Front", "(", ")", ";", "e", "!=", "nil", ";", "e", "=", "e", ".", "Next", "(", ")", "{", "req", ":=", "e", ".", "Value", ".", "(", "*", "jsonRequest", ")", "\n", "req", ".", "responseChan", "<-", "&", "response", "{", "result", ":", "nil", ",", "err", ":", "ErrClientShutdown", ",", "}", "\n", "}", "\n", "c", ".", "removeAllRequests", "(", ")", "\n\n", "// Disconnect the client if needed.", "c", ".", "doDisconnect", "(", ")", "\n", "}" ]
// Shutdown shuts down the client by disconnecting any connections associated // with the client and, when automatic reconnect is enabled, preventing future // attempts to reconnect. It also stops all goroutines.
[ "Shutdown", "shuts", "down", "the", "client", "by", "disconnecting", "any", "connections", "associated", "with", "the", "client", "and", "when", "automatic", "reconnect", "is", "enabled", "preventing", "future", "attempts", "to", "reconnect", ".", "It", "also", "stops", "all", "goroutines", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L995-L1019
train
btcsuite/btcd
rpcclient/infrastructure.go
newHTTPClient
func newHTTPClient(config *ConnConfig) (*http.Client, error) { // Set proxy function if there is a proxy configured. var proxyFunc func(*http.Request) (*url.URL, error) if config.Proxy != "" { proxyURL, err := url.Parse(config.Proxy) if err != nil { return nil, err } proxyFunc = http.ProxyURL(proxyURL) } // Configure TLS if needed. var tlsConfig *tls.Config if !config.DisableTLS { if len(config.Certificates) > 0 { pool := x509.NewCertPool() pool.AppendCertsFromPEM(config.Certificates) tlsConfig = &tls.Config{ RootCAs: pool, } } } client := http.Client{ Transport: &http.Transport{ Proxy: proxyFunc, TLSClientConfig: tlsConfig, }, } return &client, nil }
go
func newHTTPClient(config *ConnConfig) (*http.Client, error) { // Set proxy function if there is a proxy configured. var proxyFunc func(*http.Request) (*url.URL, error) if config.Proxy != "" { proxyURL, err := url.Parse(config.Proxy) if err != nil { return nil, err } proxyFunc = http.ProxyURL(proxyURL) } // Configure TLS if needed. var tlsConfig *tls.Config if !config.DisableTLS { if len(config.Certificates) > 0 { pool := x509.NewCertPool() pool.AppendCertsFromPEM(config.Certificates) tlsConfig = &tls.Config{ RootCAs: pool, } } } client := http.Client{ Transport: &http.Transport{ Proxy: proxyFunc, TLSClientConfig: tlsConfig, }, } return &client, nil }
[ "func", "newHTTPClient", "(", "config", "*", "ConnConfig", ")", "(", "*", "http", ".", "Client", ",", "error", ")", "{", "// Set proxy function if there is a proxy configured.", "var", "proxyFunc", "func", "(", "*", "http", ".", "Request", ")", "(", "*", "url", ".", "URL", ",", "error", ")", "\n", "if", "config", ".", "Proxy", "!=", "\"", "\"", "{", "proxyURL", ",", "err", ":=", "url", ".", "Parse", "(", "config", ".", "Proxy", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "proxyFunc", "=", "http", ".", "ProxyURL", "(", "proxyURL", ")", "\n", "}", "\n\n", "// Configure TLS if needed.", "var", "tlsConfig", "*", "tls", ".", "Config", "\n", "if", "!", "config", ".", "DisableTLS", "{", "if", "len", "(", "config", ".", "Certificates", ")", ">", "0", "{", "pool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "pool", ".", "AppendCertsFromPEM", "(", "config", ".", "Certificates", ")", "\n", "tlsConfig", "=", "&", "tls", ".", "Config", "{", "RootCAs", ":", "pool", ",", "}", "\n", "}", "\n", "}", "\n\n", "client", ":=", "http", ".", "Client", "{", "Transport", ":", "&", "http", ".", "Transport", "{", "Proxy", ":", "proxyFunc", ",", "TLSClientConfig", ":", "tlsConfig", ",", "}", ",", "}", "\n\n", "return", "&", "client", ",", "nil", "\n", "}" ]
// newHTTPClient returns a new http client that is configured according to the // proxy and TLS settings in the associated connection configuration.
[ "newHTTPClient", "returns", "a", "new", "http", "client", "that", "is", "configured", "according", "to", "the", "proxy", "and", "TLS", "settings", "in", "the", "associated", "connection", "configuration", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L1118-L1149
train
btcsuite/btcd
rpcclient/infrastructure.go
dial
func dial(config *ConnConfig) (*websocket.Conn, error) { // Setup TLS if not disabled. var tlsConfig *tls.Config var scheme = "ws" if !config.DisableTLS { tlsConfig = &tls.Config{ MinVersion: tls.VersionTLS12, } if len(config.Certificates) > 0 { pool := x509.NewCertPool() pool.AppendCertsFromPEM(config.Certificates) tlsConfig.RootCAs = pool } scheme = "wss" } // Create a websocket dialer that will be used to make the connection. // It is modified by the proxy setting below as needed. dialer := websocket.Dialer{TLSClientConfig: tlsConfig} // Setup the proxy if one is configured. if config.Proxy != "" { proxy := &socks.Proxy{ Addr: config.Proxy, Username: config.ProxyUser, Password: config.ProxyPass, } dialer.NetDial = proxy.Dial } // The RPC server requires basic authorization, so create a custom // request header with the Authorization header set. login := config.User + ":" + config.Pass auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login)) requestHeader := make(http.Header) requestHeader.Add("Authorization", auth) // Dial the connection. url := fmt.Sprintf("%s://%s/%s", scheme, config.Host, config.Endpoint) wsConn, resp, err := dialer.Dial(url, requestHeader) if err != nil { if err != websocket.ErrBadHandshake || resp == nil { return nil, err } // Detect HTTP authentication error status codes. if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden { return nil, ErrInvalidAuth } // The connection was authenticated and the status response was // ok, but the websocket handshake still failed, so the endpoint // is invalid in some way. if resp.StatusCode == http.StatusOK { return nil, ErrInvalidEndpoint } // Return the status text from the server if none of the special // cases above apply. return nil, errors.New(resp.Status) } return wsConn, nil }
go
func dial(config *ConnConfig) (*websocket.Conn, error) { // Setup TLS if not disabled. var tlsConfig *tls.Config var scheme = "ws" if !config.DisableTLS { tlsConfig = &tls.Config{ MinVersion: tls.VersionTLS12, } if len(config.Certificates) > 0 { pool := x509.NewCertPool() pool.AppendCertsFromPEM(config.Certificates) tlsConfig.RootCAs = pool } scheme = "wss" } // Create a websocket dialer that will be used to make the connection. // It is modified by the proxy setting below as needed. dialer := websocket.Dialer{TLSClientConfig: tlsConfig} // Setup the proxy if one is configured. if config.Proxy != "" { proxy := &socks.Proxy{ Addr: config.Proxy, Username: config.ProxyUser, Password: config.ProxyPass, } dialer.NetDial = proxy.Dial } // The RPC server requires basic authorization, so create a custom // request header with the Authorization header set. login := config.User + ":" + config.Pass auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login)) requestHeader := make(http.Header) requestHeader.Add("Authorization", auth) // Dial the connection. url := fmt.Sprintf("%s://%s/%s", scheme, config.Host, config.Endpoint) wsConn, resp, err := dialer.Dial(url, requestHeader) if err != nil { if err != websocket.ErrBadHandshake || resp == nil { return nil, err } // Detect HTTP authentication error status codes. if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden { return nil, ErrInvalidAuth } // The connection was authenticated and the status response was // ok, but the websocket handshake still failed, so the endpoint // is invalid in some way. if resp.StatusCode == http.StatusOK { return nil, ErrInvalidEndpoint } // Return the status text from the server if none of the special // cases above apply. return nil, errors.New(resp.Status) } return wsConn, nil }
[ "func", "dial", "(", "config", "*", "ConnConfig", ")", "(", "*", "websocket", ".", "Conn", ",", "error", ")", "{", "// Setup TLS if not disabled.", "var", "tlsConfig", "*", "tls", ".", "Config", "\n", "var", "scheme", "=", "\"", "\"", "\n", "if", "!", "config", ".", "DisableTLS", "{", "tlsConfig", "=", "&", "tls", ".", "Config", "{", "MinVersion", ":", "tls", ".", "VersionTLS12", ",", "}", "\n", "if", "len", "(", "config", ".", "Certificates", ")", ">", "0", "{", "pool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "pool", ".", "AppendCertsFromPEM", "(", "config", ".", "Certificates", ")", "\n", "tlsConfig", ".", "RootCAs", "=", "pool", "\n", "}", "\n", "scheme", "=", "\"", "\"", "\n", "}", "\n\n", "// Create a websocket dialer that will be used to make the connection.", "// It is modified by the proxy setting below as needed.", "dialer", ":=", "websocket", ".", "Dialer", "{", "TLSClientConfig", ":", "tlsConfig", "}", "\n\n", "// Setup the proxy if one is configured.", "if", "config", ".", "Proxy", "!=", "\"", "\"", "{", "proxy", ":=", "&", "socks", ".", "Proxy", "{", "Addr", ":", "config", ".", "Proxy", ",", "Username", ":", "config", ".", "ProxyUser", ",", "Password", ":", "config", ".", "ProxyPass", ",", "}", "\n", "dialer", ".", "NetDial", "=", "proxy", ".", "Dial", "\n", "}", "\n\n", "// The RPC server requires basic authorization, so create a custom", "// request header with the Authorization header set.", "login", ":=", "config", ".", "User", "+", "\"", "\"", "+", "config", ".", "Pass", "\n", "auth", ":=", "\"", "\"", "+", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "[", "]", "byte", "(", "login", ")", ")", "\n", "requestHeader", ":=", "make", "(", "http", ".", "Header", ")", "\n", "requestHeader", ".", "Add", "(", "\"", "\"", ",", "auth", ")", "\n\n", "// Dial the connection.", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "scheme", ",", "config", ".", "Host", ",", "config", ".", "Endpoint", ")", "\n", "wsConn", ",", "resp", ",", "err", ":=", "dialer", ".", "Dial", "(", "url", ",", "requestHeader", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "!=", "websocket", ".", "ErrBadHandshake", "||", "resp", "==", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Detect HTTP authentication error status codes.", "if", "resp", ".", "StatusCode", "==", "http", ".", "StatusUnauthorized", "||", "resp", ".", "StatusCode", "==", "http", ".", "StatusForbidden", "{", "return", "nil", ",", "ErrInvalidAuth", "\n", "}", "\n\n", "// The connection was authenticated and the status response was", "// ok, but the websocket handshake still failed, so the endpoint", "// is invalid in some way.", "if", "resp", ".", "StatusCode", "==", "http", ".", "StatusOK", "{", "return", "nil", ",", "ErrInvalidEndpoint", "\n", "}", "\n\n", "// Return the status text from the server if none of the special", "// cases above apply.", "return", "nil", ",", "errors", ".", "New", "(", "resp", ".", "Status", ")", "\n", "}", "\n", "return", "wsConn", ",", "nil", "\n", "}" ]
// dial opens a websocket connection using the passed connection configuration // details.
[ "dial", "opens", "a", "websocket", "connection", "using", "the", "passed", "connection", "configuration", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L1153-L1216
train
btcsuite/btcd
rpcclient/infrastructure.go
New
func New(config *ConnConfig, ntfnHandlers *NotificationHandlers) (*Client, error) { // Either open a websocket connection or create an HTTP client depending // on the HTTP POST mode. Also, set the notification handlers to nil // when running in HTTP POST mode. var wsConn *websocket.Conn var httpClient *http.Client connEstablished := make(chan struct{}) var start bool if config.HTTPPostMode { ntfnHandlers = nil start = true var err error httpClient, err = newHTTPClient(config) if err != nil { return nil, err } } else { if !config.DisableConnectOnNew { var err error wsConn, err = dial(config) if err != nil { return nil, err } start = true } } client := &Client{ config: config, wsConn: wsConn, httpClient: httpClient, requestMap: make(map[uint64]*list.Element), requestList: list.New(), ntfnHandlers: ntfnHandlers, ntfnState: newNotificationState(), sendChan: make(chan []byte, sendBufferSize), sendPostChan: make(chan *sendPostDetails, sendPostBufferSize), connEstablished: connEstablished, disconnect: make(chan struct{}), shutdown: make(chan struct{}), } if start { log.Infof("Established connection to RPC server %s", config.Host) close(connEstablished) client.start() if !client.config.HTTPPostMode && !client.config.DisableAutoReconnect { client.wg.Add(1) go client.wsReconnectHandler() } } return client, nil }
go
func New(config *ConnConfig, ntfnHandlers *NotificationHandlers) (*Client, error) { // Either open a websocket connection or create an HTTP client depending // on the HTTP POST mode. Also, set the notification handlers to nil // when running in HTTP POST mode. var wsConn *websocket.Conn var httpClient *http.Client connEstablished := make(chan struct{}) var start bool if config.HTTPPostMode { ntfnHandlers = nil start = true var err error httpClient, err = newHTTPClient(config) if err != nil { return nil, err } } else { if !config.DisableConnectOnNew { var err error wsConn, err = dial(config) if err != nil { return nil, err } start = true } } client := &Client{ config: config, wsConn: wsConn, httpClient: httpClient, requestMap: make(map[uint64]*list.Element), requestList: list.New(), ntfnHandlers: ntfnHandlers, ntfnState: newNotificationState(), sendChan: make(chan []byte, sendBufferSize), sendPostChan: make(chan *sendPostDetails, sendPostBufferSize), connEstablished: connEstablished, disconnect: make(chan struct{}), shutdown: make(chan struct{}), } if start { log.Infof("Established connection to RPC server %s", config.Host) close(connEstablished) client.start() if !client.config.HTTPPostMode && !client.config.DisableAutoReconnect { client.wg.Add(1) go client.wsReconnectHandler() } } return client, nil }
[ "func", "New", "(", "config", "*", "ConnConfig", ",", "ntfnHandlers", "*", "NotificationHandlers", ")", "(", "*", "Client", ",", "error", ")", "{", "// Either open a websocket connection or create an HTTP client depending", "// on the HTTP POST mode. Also, set the notification handlers to nil", "// when running in HTTP POST mode.", "var", "wsConn", "*", "websocket", ".", "Conn", "\n", "var", "httpClient", "*", "http", ".", "Client", "\n", "connEstablished", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "var", "start", "bool", "\n", "if", "config", ".", "HTTPPostMode", "{", "ntfnHandlers", "=", "nil", "\n", "start", "=", "true", "\n\n", "var", "err", "error", "\n", "httpClient", ",", "err", "=", "newHTTPClient", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "else", "{", "if", "!", "config", ".", "DisableConnectOnNew", "{", "var", "err", "error", "\n", "wsConn", ",", "err", "=", "dial", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "start", "=", "true", "\n", "}", "\n", "}", "\n\n", "client", ":=", "&", "Client", "{", "config", ":", "config", ",", "wsConn", ":", "wsConn", ",", "httpClient", ":", "httpClient", ",", "requestMap", ":", "make", "(", "map", "[", "uint64", "]", "*", "list", ".", "Element", ")", ",", "requestList", ":", "list", ".", "New", "(", ")", ",", "ntfnHandlers", ":", "ntfnHandlers", ",", "ntfnState", ":", "newNotificationState", "(", ")", ",", "sendChan", ":", "make", "(", "chan", "[", "]", "byte", ",", "sendBufferSize", ")", ",", "sendPostChan", ":", "make", "(", "chan", "*", "sendPostDetails", ",", "sendPostBufferSize", ")", ",", "connEstablished", ":", "connEstablished", ",", "disconnect", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "shutdown", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n\n", "if", "start", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "config", ".", "Host", ")", "\n", "close", "(", "connEstablished", ")", "\n", "client", ".", "start", "(", ")", "\n", "if", "!", "client", ".", "config", ".", "HTTPPostMode", "&&", "!", "client", ".", "config", ".", "DisableAutoReconnect", "{", "client", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "client", ".", "wsReconnectHandler", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "client", ",", "nil", "\n", "}" ]
// New creates a new RPC client based on the provided connection configuration // details. The notification handlers parameter may be nil if you are not // interested in receiving notifications and will be ignored if the // configuration is set to run in HTTP POST mode.
[ "New", "creates", "a", "new", "RPC", "client", "based", "on", "the", "provided", "connection", "configuration", "details", ".", "The", "notification", "handlers", "parameter", "may", "be", "nil", "if", "you", "are", "not", "interested", "in", "receiving", "notifications", "and", "will", "be", "ignored", "if", "the", "configuration", "is", "set", "to", "run", "in", "HTTP", "POST", "mode", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/infrastructure.go#L1222-L1277
train
btcsuite/btcd
rpcclient/chain.go
GetBestBlockHashAsync
func (c *Client) GetBestBlockHashAsync() FutureGetBestBlockHashResult { cmd := btcjson.NewGetBestBlockHashCmd() return c.sendCmd(cmd) }
go
func (c *Client) GetBestBlockHashAsync() FutureGetBestBlockHashResult { cmd := btcjson.NewGetBestBlockHashCmd() return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "GetBestBlockHashAsync", "(", ")", "FutureGetBestBlockHashResult", "{", "cmd", ":=", "btcjson", ".", "NewGetBestBlockHashCmd", "(", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// GetBestBlockHashAsync 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 GetBestBlockHash for the blocking version and more details.
[ "GetBestBlockHashAsync", "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", "GetBestBlockHash", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L44-L47
train
btcsuite/btcd
rpcclient/chain.go
Receive
func (r FutureGetBlockResult) Receive() (*wire.MsgBlock, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal result as a string. var blockHex string err = json.Unmarshal(res, &blockHex) if err != nil { return nil, err } // Decode the serialized block hex to raw bytes. serializedBlock, err := hex.DecodeString(blockHex) if err != nil { return nil, err } // Deserialize the block and return it. var msgBlock wire.MsgBlock err = msgBlock.Deserialize(bytes.NewReader(serializedBlock)) if err != nil { return nil, err } return &msgBlock, nil }
go
func (r FutureGetBlockResult) Receive() (*wire.MsgBlock, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal result as a string. var blockHex string err = json.Unmarshal(res, &blockHex) if err != nil { return nil, err } // Decode the serialized block hex to raw bytes. serializedBlock, err := hex.DecodeString(blockHex) if err != nil { return nil, err } // Deserialize the block and return it. var msgBlock wire.MsgBlock err = msgBlock.Deserialize(bytes.NewReader(serializedBlock)) if err != nil { return nil, err } return &msgBlock, nil }
[ "func", "(", "r", "FutureGetBlockResult", ")", "Receive", "(", ")", "(", "*", "wire", ".", "MsgBlock", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Unmarshal result as a string.", "var", "blockHex", "string", "\n", "err", "=", "json", ".", "Unmarshal", "(", "res", ",", "&", "blockHex", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Decode the serialized block hex to raw bytes.", "serializedBlock", ",", "err", ":=", "hex", ".", "DecodeString", "(", "blockHex", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Deserialize the block and return it.", "var", "msgBlock", "wire", ".", "MsgBlock", "\n", "err", "=", "msgBlock", ".", "Deserialize", "(", "bytes", ".", "NewReader", "(", "serializedBlock", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "msgBlock", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns the raw // block requested from the server given its hash.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "the", "raw", "block", "requested", "from", "the", "server", "given", "its", "hash", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L61-L87
train
btcsuite/btcd
rpcclient/chain.go
GetBlockAsync
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) }
go
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) }
[ "func", "(", "c", "*", "Client", ")", "GetBlockAsync", "(", "blockHash", "*", "chainhash", ".", "Hash", ")", "FutureGetBlockResult", "{", "hash", ":=", "\"", "\"", "\n", "if", "blockHash", "!=", "nil", "{", "hash", "=", "blockHash", ".", "String", "(", ")", "\n", "}", "\n\n", "cmd", ":=", "btcjson", ".", "NewGetBlockCmd", "(", "hash", ",", "btcjson", ".", "Bool", "(", "false", ")", ",", "nil", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// 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.
[ "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", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L94-L102
train
btcsuite/btcd
rpcclient/chain.go
GetBlock
func (c *Client) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) { return c.GetBlockAsync(blockHash).Receive() }
go
func (c *Client) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) { return c.GetBlockAsync(blockHash).Receive() }
[ "func", "(", "c", "*", "Client", ")", "GetBlock", "(", "blockHash", "*", "chainhash", ".", "Hash", ")", "(", "*", "wire", ".", "MsgBlock", ",", "error", ")", "{", "return", "c", ".", "GetBlockAsync", "(", "blockHash", ")", ".", "Receive", "(", ")", "\n", "}" ]
// GetBlock returns a raw block from the server given its hash. // // See GetBlockVerbose to retrieve a data structure with information about the // block instead.
[ "GetBlock", "returns", "a", "raw", "block", "from", "the", "server", "given", "its", "hash", ".", "See", "GetBlockVerbose", "to", "retrieve", "a", "data", "structure", "with", "information", "about", "the", "block", "instead", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L108-L110
train
btcsuite/btcd
rpcclient/chain.go
Receive
func (r FutureGetBlockVerboseResult) Receive() (*btcjson.GetBlockVerboseResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal the raw result into a BlockResult. var blockResult btcjson.GetBlockVerboseResult err = json.Unmarshal(res, &blockResult) if err != nil { return nil, err } return &blockResult, nil }
go
func (r FutureGetBlockVerboseResult) Receive() (*btcjson.GetBlockVerboseResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } // Unmarshal the raw result into a BlockResult. var blockResult btcjson.GetBlockVerboseResult err = json.Unmarshal(res, &blockResult) if err != nil { return nil, err } return &blockResult, nil }
[ "func", "(", "r", "FutureGetBlockVerboseResult", ")", "Receive", "(", ")", "(", "*", "btcjson", ".", "GetBlockVerboseResult", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Unmarshal the raw result into a BlockResult.", "var", "blockResult", "btcjson", ".", "GetBlockVerboseResult", "\n", "err", "=", "json", ".", "Unmarshal", "(", "res", ",", "&", "blockResult", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "blockResult", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns the data // structure from the server with information about the requested block.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "the", "data", "structure", "from", "the", "server", "with", "information", "about", "the", "requested", "block", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L118-L131
train
btcsuite/btcd
rpcclient/chain.go
GetBlockVerbose
func (c *Client) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) { return c.GetBlockVerboseAsync(blockHash).Receive() }
go
func (c *Client) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) { return c.GetBlockVerboseAsync(blockHash).Receive() }
[ "func", "(", "c", "*", "Client", ")", "GetBlockVerbose", "(", "blockHash", "*", "chainhash", ".", "Hash", ")", "(", "*", "btcjson", ".", "GetBlockVerboseResult", ",", "error", ")", "{", "return", "c", ".", "GetBlockVerboseAsync", "(", "blockHash", ")", ".", "Receive", "(", ")", "\n", "}" ]
// GetBlockVerbose returns a data structure from the server with information // about a block given its hash. // // See GetBlockVerboseTx to retrieve transaction data structures as well. // See GetBlock to retrieve a raw block instead.
[ "GetBlockVerbose", "returns", "a", "data", "structure", "from", "the", "server", "with", "information", "about", "a", "block", "given", "its", "hash", ".", "See", "GetBlockVerboseTx", "to", "retrieve", "transaction", "data", "structures", "as", "well", ".", "See", "GetBlock", "to", "retrieve", "a", "raw", "block", "instead", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L153-L155
train
btcsuite/btcd
rpcclient/chain.go
GetBlockVerboseTxAsync
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) }
go
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) }
[ "func", "(", "c", "*", "Client", ")", "GetBlockVerboseTxAsync", "(", "blockHash", "*", "chainhash", ".", "Hash", ")", "FutureGetBlockVerboseResult", "{", "hash", ":=", "\"", "\"", "\n", "if", "blockHash", "!=", "nil", "{", "hash", "=", "blockHash", ".", "String", "(", ")", "\n", "}", "\n\n", "cmd", ":=", "btcjson", ".", "NewGetBlockCmd", "(", "hash", ",", "btcjson", ".", "Bool", "(", "true", ")", ",", "btcjson", ".", "Bool", "(", "true", ")", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// 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.
[ "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", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L162-L170
train
btcsuite/btcd
rpcclient/chain.go
GetBlockVerboseTx
func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) { return c.GetBlockVerboseTxAsync(blockHash).Receive() }
go
func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) { return c.GetBlockVerboseTxAsync(blockHash).Receive() }
[ "func", "(", "c", "*", "Client", ")", "GetBlockVerboseTx", "(", "blockHash", "*", "chainhash", ".", "Hash", ")", "(", "*", "btcjson", ".", "GetBlockVerboseResult", ",", "error", ")", "{", "return", "c", ".", "GetBlockVerboseTxAsync", "(", "blockHash", ")", ".", "Receive", "(", ")", "\n", "}" ]
// GetBlockVerboseTx returns a data structure from the server with information // about a block and its transactions given its hash. // // See GetBlockVerbose if only transaction hashes are preferred. // See GetBlock to retrieve a raw block instead.
[ "GetBlockVerboseTx", "returns", "a", "data", "structure", "from", "the", "server", "with", "information", "about", "a", "block", "and", "its", "transactions", "given", "its", "hash", ".", "See", "GetBlockVerbose", "if", "only", "transaction", "hashes", "are", "preferred", ".", "See", "GetBlock", "to", "retrieve", "a", "raw", "block", "instead", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L177-L179
train
btcsuite/btcd
rpcclient/chain.go
Receive
func (r FutureGetBlockCountResult) Receive() (int64, error) { res, err := receiveFuture(r) if err != nil { return 0, err } // Unmarshal the result as an int64. var count int64 err = json.Unmarshal(res, &count) if err != nil { return 0, err } return count, nil }
go
func (r FutureGetBlockCountResult) Receive() (int64, error) { res, err := receiveFuture(r) if err != nil { return 0, err } // Unmarshal the result as an int64. var count int64 err = json.Unmarshal(res, &count) if err != nil { return 0, err } return count, nil }
[ "func", "(", "r", "FutureGetBlockCountResult", ")", "Receive", "(", ")", "(", "int64", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "// Unmarshal the result as an int64.", "var", "count", "int64", "\n", "err", "=", "json", ".", "Unmarshal", "(", "res", ",", "&", "count", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "count", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns the number // of blocks in the longest block chain.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "the", "number", "of", "blocks", "in", "the", "longest", "block", "chain", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L187-L200
train
btcsuite/btcd
rpcclient/chain.go
GetBlockCountAsync
func (c *Client) GetBlockCountAsync() FutureGetBlockCountResult { cmd := btcjson.NewGetBlockCountCmd() return c.sendCmd(cmd) }
go
func (c *Client) GetBlockCountAsync() FutureGetBlockCountResult { cmd := btcjson.NewGetBlockCountCmd() return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "GetBlockCountAsync", "(", ")", "FutureGetBlockCountResult", "{", "cmd", ":=", "btcjson", ".", "NewGetBlockCountCmd", "(", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// GetBlockCountAsync 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 GetBlockCount for the blocking version and more details.
[ "GetBlockCountAsync", "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", "GetBlockCount", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L207-L210
train
btcsuite/btcd
rpcclient/chain.go
Receive
func (r FutureGetDifficultyResult) Receive() (float64, error) { res, err := receiveFuture(r) if err != nil { return 0, err } // Unmarshal the result as a float64. var difficulty float64 err = json.Unmarshal(res, &difficulty) if err != nil { return 0, err } return difficulty, nil }
go
func (r FutureGetDifficultyResult) Receive() (float64, error) { res, err := receiveFuture(r) if err != nil { return 0, err } // Unmarshal the result as a float64. var difficulty float64 err = json.Unmarshal(res, &difficulty) if err != nil { return 0, err } return difficulty, nil }
[ "func", "(", "r", "FutureGetDifficultyResult", ")", "Receive", "(", ")", "(", "float64", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "// Unmarshal the result as a float64.", "var", "difficulty", "float64", "\n", "err", "=", "json", ".", "Unmarshal", "(", "res", ",", "&", "difficulty", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "difficulty", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns the // proof-of-work difficulty as a multiple of the minimum difficulty.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "the", "proof", "-", "of", "-", "work", "difficulty", "as", "a", "multiple", "of", "the", "minimum", "difficulty", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L223-L236
train
btcsuite/btcd
rpcclient/chain.go
GetDifficultyAsync
func (c *Client) GetDifficultyAsync() FutureGetDifficultyResult { cmd := btcjson.NewGetDifficultyCmd() return c.sendCmd(cmd) }
go
func (c *Client) GetDifficultyAsync() FutureGetDifficultyResult { cmd := btcjson.NewGetDifficultyCmd() return c.sendCmd(cmd) }
[ "func", "(", "c", "*", "Client", ")", "GetDifficultyAsync", "(", ")", "FutureGetDifficultyResult", "{", "cmd", ":=", "btcjson", ".", "NewGetDifficultyCmd", "(", ")", "\n", "return", "c", ".", "sendCmd", "(", "cmd", ")", "\n", "}" ]
// GetDifficultyAsync 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 GetDifficulty for the blocking version and more details.
[ "GetDifficultyAsync", "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", "GetDifficulty", "for", "the", "blocking", "version", "and", "more", "details", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L243-L246
train
btcsuite/btcd
rpcclient/chain.go
Receive
func (r FutureGetBlockChainInfoResult) Receive() (*btcjson.GetBlockChainInfoResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } var chainInfo btcjson.GetBlockChainInfoResult if err := json.Unmarshal(res, &chainInfo); err != nil { return nil, err } return &chainInfo, nil }
go
func (r FutureGetBlockChainInfoResult) Receive() (*btcjson.GetBlockChainInfoResult, error) { res, err := receiveFuture(r) if err != nil { return nil, err } var chainInfo btcjson.GetBlockChainInfoResult if err := json.Unmarshal(res, &chainInfo); err != nil { return nil, err } return &chainInfo, nil }
[ "func", "(", "r", "FutureGetBlockChainInfoResult", ")", "Receive", "(", ")", "(", "*", "btcjson", ".", "GetBlockChainInfoResult", ",", "error", ")", "{", "res", ",", "err", ":=", "receiveFuture", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "chainInfo", "btcjson", ".", "GetBlockChainInfoResult", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "res", ",", "&", "chainInfo", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "chainInfo", ",", "nil", "\n", "}" ]
// Receive waits for the response promised by the future and returns chain info // result provided by the server.
[ "Receive", "waits", "for", "the", "response", "promised", "by", "the", "future", "and", "returns", "chain", "info", "result", "provided", "by", "the", "server", "." ]
96897255fd17525dd12426345d279533780bc4e1
https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/rpcclient/chain.go#L260-L271
train