-
Notifications
You must be signed in to change notification settings - Fork 12
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
Showing
13 changed files
with
210 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### @marlowe.io/runtime-rest-client | ||
|
||
- Added a new endpoint `GetRuntimeStatus` that retrieves informations about the Runtime (version deployed, Network Id of the Node and tips) |
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,2 +1,2 @@ | ||
export * as MarloweJSON from "./codec.js"; | ||
export * as Codec from "./codec.js"; | ||
export * as Time from "./time.js"; |
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 @@ | ||
export * from "./status.js"; |
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,103 @@ | ||
import { AxiosInstance } from "axios"; | ||
import * as HTTP from "@marlowe.io/adapter/http"; | ||
import { unsafeEither, unsafeTaskEither } from "@marlowe.io/adapter/fp-ts"; | ||
import { ISO8601 } from "@marlowe.io/adapter/time"; | ||
import { | ||
BlockHeader, | ||
BlockHeaderGuard, | ||
NetworkId, | ||
bigintGuard, | ||
} from "@marlowe.io/runtime-core"; | ||
import { formatValidationErrors } from "jsonbigint-io-ts-reporters"; | ||
import * as E from "fp-ts/lib/Either.js"; | ||
import * as t from "io-ts/lib/index.js"; | ||
import { MarloweJSON, MarloweJSONCodec } from "@marlowe.io/adapter/codec"; | ||
export type BlockHash = string; | ||
|
||
export type RuntimeVersion = string; | ||
|
||
export type CompatibleRuntimeVersion = "0.0.6" | "0.0.5"; | ||
|
||
export const CompatibleRuntimeVersionGuard: t.Type< | ||
CompatibleRuntimeVersion, | ||
string | ||
> = t.union([t.literal("0.0.6"), t.literal("0.0.5")]); | ||
|
||
/** | ||
* A **Tip** represents the last block read in a "projection" process. | ||
* In the context of Cardano and Blockchain in general, a Projection is about deriving a state from a ledger by streaming the block events. | ||
* These States (e.g : contract details) are eventually consistent, and the Tip gives you an approximate notion on how freshly updated they are. | ||
*/ | ||
export type Tip = { | ||
/** | ||
* Last Block Header Read | ||
*/ | ||
blockHeader: BlockHeader; | ||
/** | ||
* Last Slot Read in UTC time | ||
*/ | ||
slotTimeUTC: ISO8601; | ||
}; | ||
/** | ||
* @hidden | ||
*/ | ||
export const TipGuard = t.type({ | ||
slotTimeUTC: ISO8601, | ||
blockHeader: BlockHeaderGuard, | ||
}); | ||
|
||
/** | ||
* Set of information about the runtime hosted | ||
*/ | ||
export type RuntimeStatus = { | ||
/** | ||
* Network ID of the node connected to the runtime | ||
*/ | ||
networkId: NetworkId; | ||
/** | ||
* Runtime Version Deployed | ||
*/ | ||
version: RuntimeVersion; | ||
/** | ||
* Set of Tips providing information on how healthy is the flow of Projections : Node > Runtime Chain > Runtime | ||
* The Runtime Tip indicates if the information Queried is up to date. The Node and the Runtime Chain Tips are | ||
* here to help the diagnostic of a Runtime Tip that would be too long in the past or not being updated anymore. | ||
*/ | ||
tips: { | ||
node: Tip; | ||
runtimeChain: Tip; | ||
runtime: Tip; | ||
}; | ||
}; | ||
|
||
export const getRuntimeStatus = async ( | ||
axiosInstance: AxiosInstance | ||
): Promise<RuntimeStatus> => { | ||
const headers = await unsafeTaskEither( | ||
HTTP.GetWithHeaders(axiosInstance)("/healthcheck") | ||
); | ||
|
||
return { | ||
networkId: headers["x-network-id"], | ||
version: headers["x-runtime-version"], | ||
tips: { | ||
node: unsafeEither( | ||
E.mapLeft(formatValidationErrors)( | ||
TipGuard.decode(MarloweJSONCodec.decode(headers["x-node-tip"])) | ||
) | ||
), | ||
runtimeChain: unsafeEither( | ||
E.mapLeft(formatValidationErrors)( | ||
TipGuard.decode( | ||
MarloweJSONCodec.decode(headers["x-runtime-chain-tip"]) | ||
) | ||
) | ||
), | ||
runtime: unsafeEither( | ||
E.mapLeft(formatValidationErrors)( | ||
TipGuard.decode(MarloweJSONCodec.decode(headers["x-runtime-tip"])) | ||
) | ||
), | ||
}, | ||
}; | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/runtime/client/rest/test/endpoints/runtime.spec.e2e.ts
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,18 @@ | ||
import { mkRestClient } from "@marlowe.io/runtime-rest-client"; | ||
|
||
import { getMarloweRuntimeUrl } from "../context.js"; | ||
|
||
import console from "console"; | ||
import * as G from "@marlowe.io/runtime-rest-client/guards"; | ||
import { MarloweJSON } from "@marlowe.io/adapter/codec"; | ||
|
||
global.console = console; | ||
|
||
describe("Runtime", () => { | ||
const restClient = mkRestClient(getMarloweRuntimeUrl()); | ||
it("is deployed with a version compatible with @marlowe.io/runtime-rest-client.", async () => { | ||
const status = await restClient.getRuntimeStatus(); | ||
console.log("status", MarloweJSON.stringify(status)); | ||
expect(G.CompatibleRuntimeVersion.is(status.version)).toBe(true); | ||
}, 100_000); | ||
}); |
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,24 @@ | ||
import * as t from "io-ts/lib/index.js"; | ||
|
||
export type NetworkId = bigint; | ||
export type Network = "preview" | "preprod" | "mainnet" | "private"; | ||
|
||
export const NetworkGuard: t.Type<Network, string> = t.union([ | ||
t.literal("preview"), | ||
t.literal("preprod"), | ||
t.literal("mainnet"), | ||
t.literal("private"), | ||
]); | ||
|
||
export const getNetwork = (networkId: NetworkId): Network => { | ||
switch (networkId) { | ||
case 0n: | ||
return "mainnet"; | ||
case 1n: | ||
return "preprod"; | ||
case 2n: | ||
return "preview"; | ||
default: | ||
return "private"; | ||
} | ||
}; |
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