-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* a basic telemetry rpc * fix test * add rpcs * fix * fix * fix * fix
- Loading branch information
Showing
13 changed files
with
113 additions
and
47 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Blockchain | ||
import RPC | ||
import Utils | ||
|
||
public final class NodeDataSource: DataSource { | ||
public let blockchain: Blockchain | ||
public let chainDataProvider: BlockchainDataProvider | ||
public let networkManager: NetworkManager | ||
|
||
public init(blockchain: Blockchain, chainDataProvider: BlockchainDataProvider, networkManager: NetworkManager) { | ||
self.blockchain = blockchain | ||
self.chainDataProvider = chainDataProvider | ||
self.networkManager = networkManager | ||
} | ||
|
||
public func importBlock(_ block: BlockRef) async throws { | ||
try await blockchain.importBlock(block) | ||
} | ||
|
||
public func getBestBlock() async throws -> BlockRef { | ||
try await chainDataProvider.getBlock(hash: chainDataProvider.bestHead.hash) | ||
} | ||
|
||
public func getBlock(hash: Data32) async throws -> BlockRef? { | ||
try await chainDataProvider.getBlock(hash: hash) | ||
} | ||
|
||
public func getState(hash: Data32) async throws -> StateRef? { | ||
try await chainDataProvider.getState(hash: hash) | ||
} | ||
|
||
public func getPeersCount() async throws -> Int { | ||
networkManager.getPeersCount() | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Blockchain | ||
import Foundation | ||
import Utils | ||
|
||
struct TelemetryHandler { | ||
let source: DataSource | ||
|
||
static func getHandlers(source: DataSource) -> [String: JSONRPCHandler] { | ||
let handler = TelemetryHandler(source: source) | ||
|
||
return [ | ||
"telemetry_getUpdate": handler.getUpdate, | ||
] | ||
} | ||
|
||
func getUpdate(request _: JSONRequest) async throws -> any Encodable { | ||
let block = try await source.getBestBlock() | ||
let peerCount = try await source.getPeersCount() | ||
return [ | ||
"name": "Boka", | ||
"chainHead": block.header.timeslot.description, | ||
"blockHash": block.hash.description, | ||
"peerCount": peerCount.description, | ||
] | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.