-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
138a833
commit 6205c07
Showing
8 changed files
with
277 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import { ViewService } from '@penumbra-zone/protobuf'; | ||
import { penumbra } from '../penumbra'; | ||
import { CallOptions } from '@connectrpc/connect'; | ||
import { PlainMessage, toPlainMessage } from '@bufbuild/protobuf'; | ||
import { | ||
StatusResponse, | ||
StatusStreamResponse, | ||
} from '@penumbra-zone/protobuf/penumbra/view/v1/view_pb'; | ||
|
||
const getInitialStatus = () => | ||
penumbra | ||
.service(ViewService) | ||
.status({}) | ||
.then(status => ({ | ||
fullSyncHeight: status.fullSyncHeight, | ||
latestKnownBlockHeight: status.catchingUp ? undefined : status.fullSyncHeight, | ||
})); | ||
|
||
export async function* getStatusStream(): AsyncGenerator<{ | ||
fullSyncHeight?: bigint; | ||
latestKnownBlockHeight?: bigint; | ||
}> { | ||
// `statusStream` sends new data to stream only when a new block is detected. | ||
// This can take up to 5 seconds (time of new block generated). | ||
// Therefore, we need to do a unary request to start us off. | ||
yield await getInitialStatus(); | ||
export const getInitialStatus = async (opt?: CallOptions): Promise<PlainMessage<StatusResponse>> => | ||
toPlainMessage(await penumbra.service(ViewService).status({}, opt)); | ||
|
||
for await (const result of penumbra.service(ViewService).statusStream({})) { | ||
yield { | ||
fullSyncHeight: result.fullSyncHeight, | ||
latestKnownBlockHeight: result.latestKnownBlockHeight, | ||
}; | ||
export async function* getStatusStream( | ||
opt?: CallOptions, | ||
): AsyncGenerator<PlainMessage<StatusStreamResponse>> { | ||
for await (const item of penumbra | ||
.service(ViewService) | ||
.statusStream({}, { timeoutMs: 15_000, ...opt })) { | ||
yield toPlainMessage(item); | ||
} | ||
} |
Oops, something went wrong.