lnrpc: expose network name in GetInfo

Previously only a testnet boolean was available which
made it impossible to distinguish between regtest and
mainnet.
This commit is contained in:
Joost Jager 2019-01-02 16:10:12 +01:00
parent f63ab4beda
commit 649408003d
No known key found for this signature in database
GPG Key ID: AE6B0D042C8E38D9
5 changed files with 661 additions and 567 deletions

View File

@ -1669,6 +1669,11 @@ var getInfoCommand = cli.Command{
Action: actionDecorator(getInfo),
}
type chain struct {
Chain string `json:"chain"`
Network string `json:"network"`
}
func getInfo(ctx *cli.Context) error {
ctxb := context.Background()
client, cleanUp := getClient(ctx)
@ -1680,6 +1685,14 @@ func getInfo(ctx *cli.Context) error {
return err
}
chains := make([]chain, len(resp.Chains))
for i, c := range resp.Chains {
chains[i] = chain{
Chain: c.Chain,
Network: c.Network,
}
}
// We print a struct that mimics the proto definition of GetInfoResponse
// but has a better ordering for the same list of fields.
printJSON(struct {
@ -1695,7 +1708,7 @@ func getInfo(ctx *cli.Context) error {
BestHeaderTimestamp int64 `json:"best_header_timestamp"`
SyncedToChain bool `json:"synced_to_chain"`
Testnet bool `json:"testnet"`
Chains []string `json:"chains"`
Chains []chain `json:"chains"`
Uris []string `json:"uris"`
}{
Version: resp.Version,
@ -1710,7 +1723,7 @@ func getInfo(ctx *cli.Context) error {
BestHeaderTimestamp: resp.BestHeaderTimestamp,
SyncedToChain: resp.SyncedToChain,
Testnet: resp.Testnet,
Chains: resp.Chains,
Chains: chains,
Uris: resp.Uris,
})
return nil

File diff suppressed because it is too large Load Diff

View File

@ -1134,11 +1134,13 @@ message GetInfoResponse {
/// Whether the wallet's view is synced to the main chain
bool synced_to_chain = 9 [json_name = "synced_to_chain"];
/// Whether the current node is connected to testnet
bool testnet = 10 [json_name = "testnet"];
/**
Whether the current node is connected to testnet. This field is
deprecated and the network field should be used instead
**/
bool testnet = 10 [json_name = "testnet", deprecated = true];
/// A list of active chains the node is connected to
repeated string chains = 11 [json_name = "chains"];
reserved 11;
/// The URIs of the current node.
repeated string uris = 12 [json_name = "uris"];
@ -1151,6 +1153,17 @@ message GetInfoResponse {
/// Number of inactive channels
uint32 num_inactive_channels = 15 [json_name = "num_inactive_channels"];
/// A list of active chains the node is connected to
repeated Chain chains = 16 [json_name = "chains"];
}
message Chain {
/// The blockchain the node is on (eg bitcoin, litecoin)
string chain = 1 [json_name = "chain"];
/// The network the node is on (eg regtest, testnet, mainnet)
string network = 2 [json_name = "network"];
}
message ConfirmationUpdate {

View File

@ -1284,6 +1284,17 @@
"description": "- `p2wkh`: Pay to witness key hash (`WITNESS_PUBKEY_HASH` = 0)\n- `np2wkh`: Pay to nested witness key hash (`NESTED_PUBKEY_HASH` = 1)",
"title": "* \n`AddressType` has to be one of:"
},
"lnrpcChain": {
"type": "object",
"properties": {
"chain": {
"type": "string"
},
"network": {
"type": "string"
}
}
},
"lnrpcChangePasswordRequest": {
"type": "object",
"properties": {
@ -1859,14 +1870,7 @@
"testnet": {
"type": "boolean",
"format": "boolean",
"title": "/ Whether the current node is connected to testnet"
},
"chains": {
"type": "array",
"items": {
"type": "string"
},
"title": "/ A list of active chains the node is connected to"
"title": "* \nWhether the current node is connected to testnet. This field is \ndeprecated and the network field should be used instead"
},
"uris": {
"type": "array",
@ -1888,6 +1892,13 @@
"type": "integer",
"format": "int64",
"title": "/ Number of inactive channels"
},
"chains": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcChain"
},
"title": "/ A list of active chains the node is connected to"
}
}
},

View File

@ -1748,9 +1748,14 @@ func (r *rpcServer) GetInfo(ctx context.Context,
"with current best block in the main chain: %v", err)
}
activeChains := make([]string, registeredChains.NumActiveChains())
network := normalizeNetwork(activeNetParams.Name)
activeChains := make([]*lnrpc.Chain, registeredChains.NumActiveChains())
for i, chain := range registeredChains.ActiveChains() {
activeChains[i] = chain.String()
activeChains[i] = &lnrpc.Chain{
Chain: chain.String(),
Network: network,
}
}
// Check if external IP addresses were provided to lnd and use them