GetLedgerHeight returns the current ledger height for a peer on a channel
(n *Network, peer *Peer, channel string)
| 540 | // GetLedgerHeight returns the current ledger height for a peer on |
| 541 | // a channel |
| 542 | func GetLedgerHeight(n *Network, peer *Peer, channel string) int { |
| 543 | sess, err := n.PeerUserSession(peer, "User1", commands.ChannelInfo{ |
| 544 | ChannelID: channel, |
| 545 | ClientAuth: n.ClientAuthRequired, |
| 546 | }) |
| 547 | Expect(err).NotTo(HaveOccurred()) |
| 548 | Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit()) |
| 549 | |
| 550 | if sess.ExitCode() == 1 { |
| 551 | // if org is not yet member of channel, peer will return error |
| 552 | return -1 |
| 553 | } |
| 554 | |
| 555 | channelInfoStr := strings.TrimPrefix(string(sess.Buffer().Contents()[:]), "Blockchain info:") |
| 556 | channelInfo := common.BlockchainInfo{} |
| 557 | json.Unmarshal([]byte(channelInfoStr), &channelInfo) |
| 558 | return int(channelInfo.Height) |
| 559 | } |
| 560 | |
| 561 | // GetMaxLedgerHeight returns the maximum ledger height for the |
| 562 | // peers on a channel |