File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,9 +136,30 @@ func (c *Connection) BroadcastTransaction(
136136 panic ("not implemented" )
137137}
138138
139+ // GetLatestBlockHeight gets the height of the latest block (tip). If the
140+ // latest block was not determined, this function returns an error.
139141func (c * Connection ) GetLatestBlockHeight () (uint , error ) {
140- // TODO: Implementation.
141- panic ("not implemented" )
142+ var tip * electrum.SubscribeHeadersResult
143+ err := wrappers .DoWithDefaultRetry (c .requestRetryTimeout , func (ctx context.Context ) error {
144+ headersChan , err := c .client .SubscribeHeaders (c .ctx )
145+ if err != nil {
146+ return fmt .Errorf ("failed to get the blocks tip height: [%w]" , err )
147+ }
148+
149+ tip = <- headersChan
150+ return nil
151+ })
152+ if err != nil {
153+ return 0 , fmt .Errorf ("failed to subscribe for headers: [%w]" , err )
154+ }
155+
156+ blockHeight := tip .Height
157+
158+ if blockHeight > 0 {
159+ return uint (blockHeight ), nil
160+ }
161+
162+ return 0 , nil
142163}
143164
144165// GetBlockHeader gets the block header for the given block height. If the
You can’t perform that action at this time.
0 commit comments