Skip to content

Commit b0ce73e

Browse files
Tjemmmicdrewstone
andauthored
chore: update blueprint-sdk docs (#100)
* chore: update cli docs * chore: update code links wip * chore: fmt * chore: update code links * chore: prettier --------- Co-authored-by: Drew Stone <drewstone329@gmail.com>
1 parent a0a5379 commit b0ce73e

24 files changed

+152
-83
lines changed

pages/developers/blueprint-contexts/eigenlayer-context.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ The `EigenlayerContext` trait provides access to core Eigenlayer services and fu
3535
<GithubFileReaderDisplay
3636
url="https://github.com/tangle-network/gadget/blob/main/crates/contexts/src/eigenlayer.rs"
3737
title="EigenlayerContext Trait Definition"
38+
fromLine={5}
39+
toLine={9}
3840
/>
3941

4042
## Using the Context
@@ -45,8 +47,8 @@ First, define your context struct that implements the `EigenlayerContext` trait:
4547

4648
<GithubFileReaderDisplay
4749
url="https://github.com/tangle-network/gadget/blob/main/blueprints/incredible-squaring-eigenlayer/src/contexts/aggregator.rs"
48-
fromLine={43}
49-
toLine={56}
50+
fromLine={39}
51+
toLine={52}
5052
title="Aggregator Context Definition"
5153
/>
5254

@@ -68,6 +70,6 @@ Finally, instantiate your context in your main runner:
6870
<GithubFileReaderDisplay
6971
url="https://github.com/tangle-network/gadget/blob/main/blueprints/incredible-squaring-eigenlayer/src/main.rs"
7072
fromLine={27}
71-
toLine={45}
73+
toLine={53}
7274
title="Instantiating the Context"
7375
/>

pages/developers/blueprint-contexts/keystore-context.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The `KeystoreContext` trait provides access to a `Keystore` that implements the
2121
<GithubFileReaderDisplay
2222
url="https://github.com/tangle-network/gadget/blob/main/crates/contexts/src/keystore.rs"
2323
fromLine={4}
24-
toLine={9}
24+
toLine={8}
2525
title="KeystoreContext Trait Definition"
2626
/>
2727

pages/developers/blueprint-event-listeners/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"introduction": "Introduction to Event Listeners",
33
"tangle-job-calls": "Tangle Job Call Listener",
44
"evm-contracts": "EVM Contract Listeners",
5-
"periodic-listeners": "Periodic Listeners",
5+
"cron-job-listeners": "Cron Job Listeners",
66
"custom-listeners": "Custom Listeners"
77
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: Cron Job Listeners
3+
---
4+
5+
import GithubFileReaderDisplay from "/components/GithubFileReaderDisplay";
6+
7+
# Cron Job Listeners
8+
9+
Cron Job listeners are event listeners that trigger at specific time intervals. They are useful for tasks that need to be executed regularly, such as quality of service metrics/uptime checkers, data updates, and subscription style services.
10+
11+
## Overview
12+
13+
Cron Job Listeners enable your blueprint to:
14+
15+
1. Schedule tasks to run at specific intervals
16+
2. Execute background jobs periodically
17+
3. Perform regular checks or updates without manual intervention
18+
19+
Cron Job Listeners are particularly useful for tasks such as:
20+
21+
- Regular data synchronization
22+
- Scheduled maintenance operations
23+
- Periodic health checks
24+
- Automated reporting at set intervals
25+
26+
# CronJob
27+
28+
Some programs may only be interested in checking for events at regular intervals. In this case, the `CronJob` can be used to simplify the process.
29+
30+
A `CronJob` executes a job periodically, using a context that provides interval information in cron notation (e.g., "1/2 \* \* \* \* \*"):
31+
32+
<GithubFileReaderDisplay
33+
url="https://github.com/tangle-network/gadget/blob/main/crates/event-listeners/cronjob/src/lib.rs"
34+
fromLine={13}
35+
toLine={27}
36+
title="CronJob Event Listener Definition"
37+
/>
38+
39+
--TODO: Update the section below once the Example Blueprints are updated in Gadget
40+
41+
We can make a `PeriodicEventListener` that ticks every 6000ms to check the status of a web server using [reqwest](https://crates.io/crates/reqwest).
42+
43+
Start by defining our inner event listener (`T` = `WebPoller`, in this case), and implement the `EventListener` trait.
44+
45+
<GithubFileReaderDisplay
46+
url="https://github.com/tangle-network/gadget/blob/main/blueprints/examples/src/periodic_web_poller.rs"
47+
fromLine={79}
48+
toLine={116}
49+
title="Example WebPoller `EventListener` Implementation"
50+
/>
51+
52+
## Using it in a Blueprint
53+
54+
Implement the pre-processor and post-processors, as needed for the event listener:
55+
56+
<GithubFileReaderDisplay
57+
url="https://github.com/tangle-network/gadget/blob/main/blueprints/examples/src/periodic_web_poller.rs"
58+
fromLine={68}
59+
toLine={77}
60+
title="Example WebPoller Post-Processor"
61+
/>
62+
63+
Integrate the event listener inside the `job`:
64+
65+
<GithubFileReaderDisplay
66+
url="https://github.com/tangle-network/gadget/blob/main/blueprints/examples/src/periodic_web_poller.rs"
67+
fromLine={36}
68+
toLine={65}
69+
title="Example Job with Periodic Web Poller Listener"
70+
/>

pages/developers/blueprint-event-listeners/custom-listeners.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Custom Event Listeners
55
To create an event listener, begin by defining a struct or enum which will listen to events:
66

77
```rust
8-
use gadget_sdk::event_listener::EventListener;
8+
use blueprint_sdk::event_listeners::core::EventListener;
99
use async_trait::async_trait;
1010

1111
/// Define a simple event listener that ticks every MS milliseconds.
@@ -65,7 +65,6 @@ Finally, register the event listener inside the `job` macro using `event_listene
6565
#[job(
6666
id = 0,
6767
params(x),
68-
result(_),
6968
event_listener(listener = Ticker::<6000>), // <-- Register the event listener here
7069
)]
7170
pub fn hello_event_listener(

pages/developers/blueprint-event-listeners/introduction.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ In general, when defining your job, you must register an event listeners and pro
1212

1313
<GithubFileReaderDisplay
1414
url="https://github.com/tangle-network/blueprint-template/blob/main/src/lib.rs"
15-
fromLine={11}
16-
toLine={32}
15+
fromLine={12}
16+
toLine={36}
1717
title="Example Blueprint Job with Tangle JobCalled Event Listener"
1818
/>
1919

@@ -25,7 +25,7 @@ Event listeners in the SDK are designed to be flexible and allow developers to c
2525

2626
<GithubFileReaderDisplay
2727
url="https://github.com/tangle-network/gadget/blob/main/crates/event-listeners/core/src/lib.rs"
28-
fromLine={15}
28+
fromLine={14}
2929
toLine={25}
3030
title="Event Listener Trait Definition"
3131
/>
@@ -36,8 +36,8 @@ When a blueprint instance runs, the event listeners are constructed and executed
3636

3737
<GithubFileReaderDisplay
3838
url="https://github.com/tangle-network/gadget/blob/main/blueprints/incredible-squaring/src/main.rs"
39-
fromLine={8}
40-
toLine={26}
39+
fromLine={7}
40+
toLine={30}
4141
title="Example Blueprint Runner execution"
4242
/>
4343

pages/developers/blueprint-event-listeners/tangle-job-calls.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ will automatically work with the Tangle network.
3434

3535
<GithubFileReaderDisplay
3636
url="https://github.com/tangle-network/blueprint-template/blob/main/src/lib.rs"
37-
fromLine={11}
38-
toLine={32}
37+
fromLine={20}
38+
toLine={36}
3939
title="Example Blueprint Job with Tangle JobCalled Event Listener"
4040
/>
4141

@@ -53,7 +53,7 @@ The pre-processor for Tangle job calls handles the following tasks:
5353

5454
<GithubFileReaderDisplay
5555
url="https://github.com/tangle-network/gadget/blob/main/crates/event-listeners/tangle/src/services.rs"
56-
fromLine={7}
56+
fromLine={8}
5757
toLine={56}
5858
title="Tangle Job Call Pre-processor Implementation"
5959
/>

pages/developers/blueprint-macros/context.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ These extensions can be easily added to your Context using derive macros, as sho
118118
Here's an example of how to use the built-in `KeystoreContext` extension:
119119

120120
```rust
121-
use std::convert::Infallible;
122-
use gadget_sdk::ctx::KeystoreContext;
123-
use gadget_sdk::config::StdGadgetConfiguration;
121+
use blueprint_sdk::std::convert::Infallible;
122+
use blueprint_sdk::contexts::keystore::KeystoreContext;
123+
use blueprint_sdk::config::StdGadgetConfiguration;
124124

125125
#[derive(Debug, Clone, KeystoreContext)] // Derive the KeystoreContext extension
126126
struct Context {
@@ -129,7 +129,7 @@ struct Context {
129129
sdk_config: StdGadgetConfiguration,
130130
}
131131

132-
#[job(id = 2, params(x), result(_))]
132+
#[job(id = 2, params(x))]
133133
pub fn x_squared(ctx: &Context, x: u64) -> Result<u64, Infallible> {
134134
let keystore = ctx.keystore(); // Access the keystore using the extension method
135135
// Use the keystore here ...
@@ -177,7 +177,7 @@ impl HttpClientContext for Context {
177177
}
178178

179179
// Example job using the custom extension
180-
#[job(id = 3, params(url), result(_))]
180+
#[job(id = 3, params(url))]
181181
pub async fn fetch_url(ctx: &Context, url: String) -> Result<String, reqwest::Error> {
182182
let client = ctx.http_client();
183183
let response = client.get(&url).send().await?;

pages/developers/blueprint-macros/event-listeners.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import TableOfContentCards from "../../../components/TableOfContentCards";
4242
},
4343
{
4444
title: "Periodic Listeners",
45-
href: "/developers/blueprint-event-listeners/periodic-listeners",
45+
href: "/developers/blueprint-event-listeners/cron-job-listeners",
4646
subItems: [
4747
{
4848
title: "Time-based Operations",

pages/developers/blueprint-macros/jobs.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ The `#[job]` macro is used to define individual tasks or jobs within a blueprint
2020

2121
<GithubFileReaderDisplay
2222
url="https://github.com/tangle-network/blueprint-template/blob/main/src/lib.rs"
23-
fromLine={16}
24-
toLine={32}
23+
fromLine={20}
24+
toLine={36}
2525
title="Example Job Macro Usage"
2626
/>
2727

@@ -69,8 +69,8 @@ The basic Incredible Squaring blueprint includes a `simple_squaring` job that sq
6969

7070
<GithubFileReaderDisplay
7171
url="https://github.com/tangle-network/gadget/blob/main/blueprints/incredible-squaring/src/lib.rs"
72-
fromLine={9}
73-
toLine={21}
72+
fromLine={19}
73+
toLine={31}
7474
title="Example Simple Squaring Job"
7575
/>
7676

@@ -82,8 +82,8 @@ The Eigenlayer Incredible Squaring blueprint includes a `compute_x_square` job t
8282

8383
<GithubFileReaderDisplay
8484
url="https://github.com/tangle-network/gadget/blob/main/blueprints/incredible-squaring-eigenlayer/src/jobs/compute_x_square.rs"
85-
fromLine={18}
86-
toLine={77}
85+
fromLine={22}
86+
toLine={86}
8787
title="Example Eigenlayer Squaring Job"
8888
/>
8989

@@ -105,7 +105,7 @@ This example demonstrates how to use the FROST keygen job to generate a new keyp
105105
<GithubFileReaderDisplay
106106
url="https://github.com/tangle-network/frost-blueprint/blob/main/src/keygen.rs"
107107
fromLine={59}
108-
toLine={127}
108+
toLine={128}
109109
title="Example FROST Keygen Job"
110110
/>
111111

@@ -115,7 +115,7 @@ This example demonstrates how to use the FROST signing job to sign a message usi
115115

116116
<GithubFileReaderDisplay
117117
url="https://github.com/tangle-network/frost-blueprint/blob/main/src/sign.rs"
118-
fromLine={70}
119-
toLine={158}
118+
fromLine={69}
119+
toLine={164}
120120
title="Example FROST Signing Job"
121121
/>

pages/developers/blueprint-macros/reports.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ use my_special_web_polling_context::Context;
7878
#[report(
7979
id = 1,
8080
params(value),
81-
result(_),
8281
event_listener(
8382
listener = PeriodicEventListener<2000, WebPoller, serde_json::Value, reqwest::Client>
8483
),

pages/developers/blueprints/introduction.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { Callout } from 'nextra/components'
21
import CardGrid from "../../../components/CardGrid.tsx"
3-
import ExpandableImage from "../../../components/ExpandableImage.tsx"
42

53
# Blueprints
64

@@ -26,13 +24,13 @@ import ExpandableImage from "../../../components/ExpandableImage.tsx"
2624
]}
2725
/>
2826

29-
**Blueprints** are specifications for Actively Validated Services (AVS) or **Instances** on the Tangle Network. Developers build blueprints using our [Gadget SDK](https://github.com/tangle-network/gadget) and deploy them to the Tangle Network. Once deployed, users can create Instances of the Blueprint, which are run by Tangle Operators. The Tangle Network incentivizes operators to run these instances by rewarding them with TNT tokens and fees from instancing and instance exeuction. Developers incentivize operators to run instances by specifying additional rewards for operators in the Blueprint.
27+
**Blueprints** are specifications for Actively Validated Services (AVS) or **Instances** on the Tangle Network. Developers build blueprints using our [Gadget SDK](https://github.com/tangle-network/gadget) and deploy them to the Tangle Network. Once deployed, users can create Instances of the Blueprint, which are run by Tangle Operators. The Tangle Network incentivizes operators to run these instances by rewarding them with TNT tokens and fees from instancing and instance execution. Developers incentivize operators to run instances by specifying additional rewards for operators in the Blueprint.
3028

31-
An Actively Validated Service or Blueprint Instance is a computational service that runs a specified period of time, potentially user-specified or on-demand or forever. Instances allow Blueprints to be reused multiple times, so that useful services can be leveraged by many customers. A key benefit of instancing Blueprints is that each instance can have different operators and diffierent restaked assets securing them.
29+
An Actively Validated Service or Blueprint Instance is a computational service that runs a specified period of time, potentially user-specified or on-demand or forever. Instances allow Blueprints to be reused multiple times, so that useful services can be leveraged by many customers. A key benefit of instancing Blueprints is that each instance can have different operators and different restaked assets securing them.
3230

3331
A Tangle Blueprint is defined by:
3432

35-
- An program binary.
33+
- A program binary.
3634
- A set of smart contracts that provide programmability over the service's output verification and handling of malicious failures
3735

3836
Tangle Blueprints specify their target environment for program execution. The Blueprint's binary can run natively on the operator's machine, in a virtual machine, or in a containerized environment. We are constantly working to provide the right environments for developers to build Blueprints so that operators are satisfied executing Blueprint Instances. Our Gadget SDK supports building AVS and Blueprint Instances directly on Eigenlayer without the same instancing as exists on Tangle, allowing developers nonetheless to leverage the features of our SDK to build and test their services on Eigenlayer. Future integrations with other restaking infrastructures are planned.
@@ -46,10 +44,10 @@ Developers interact with Tangle Blueprints by deploying them to the blockchain.
4644
The Blueprint includes one main smart contract responsible with all aspects of customizing a Blueprint's behavior and features. Developers have the flexibility to extend this contract, create child contracts, and anything that adheres to the function signatures expected by the runtime when executing logic. The Blueprint smart contract handles:
4745

4846
1. **Registration**: Specifies how Operators register for the Blueprint, allowing the developer to add additional fees, access control, KYC, and any other EVM-deployable functionality to the registration process.
49-
2. **Request**: Defines how customer of Blueprints initiate Service Instances, providing the same customizability as the EVM for the initialization process of Service Instances.
47+
2. **Request**: Defines how customer of Blueprints initiates Service Instances, providing the same customizability as the EVM for the initialization process of Service Instances.
5048
3. **On Job Hooks**: Allows developers to specify custom logic to be executed when a job is created.
5149
4. **On Job Result Hooks**: Allows developers to specify custom logic to be executed when a job is completed, such as verifying a job's output.
52-
5. **Custom slashing conditions**: Allows developers to specify custom slashing conditions for Operators, such as failing to provide a service or providing a malicious service. These would be callable by anyone or priveledged callers but is entirely up to the developer to design.
50+
5. **Custom slashing conditions**: Allows developers to specify custom slashing conditions for Operators, such as failing to provide a service or providing a malicious service. These would be callable by anyone or privileged callers but is entirely up to the developer to design.
5351

5452
Blueprint upgrades are handled differently than runtime upgrades and should eventually be supported through an additional Blueprint smart contract for governance. Upgrades should not overwrite previous versions to protect against malicious updates to active and future services. Instead, upgrades allow for a form of Operator lock-in, enabling developers to quickly benefit from the success of existing services and pass liquidity, as users can request "new versions" of the Blueprint while accessing the already restaked capital from the success of previous versions.
5553

pages/developers/blueprints/use-cases.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import ExpandableImage from "../../../components/ExpandableImage";
2-
import TableOfContentCards from "../../../components/TableOfContentCards";
31
import NonuniformTableOfContentCards from "../../../components/NonuniformTableOfContentCards";
42
import GithubRepoCard, { GithubRepoList } from "../../../components/GithubRepoCard";
53

@@ -114,7 +112,7 @@ Signatures are pervasive in the design of blockchain bridges, oracles, and custo
114112
displayStyle="row"
115113
/>
116114

117-
The FROST Blueprint demonstrates how to implement threshold signatures using the FROST protocol on Tangle Network. [FROST](https://eprint.iacr.org/2020/852.pdf) is a protocol for generating threshold Shnorr signatures. This example showcases:
115+
The FROST Blueprint demonstrates how to implement threshold signatures using the FROST protocol on Tangle Network. [FROST](https://eprint.iacr.org/2020/852.pdf) is a protocol for generating threshold Schnorr signatures. This example showcases:
118116

119117
- Distributed key generation between operators
120118
- Threshold signature creation

pages/developers/cli/installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ There are multiple sources to install the CLI from:
1111
> The script supports Linux, MacOS, and Windows (WSL2)
1212
1313
```shell
14-
$ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/tangle-network/gadget/releases/download/cargo-tangle/v0.1.1-beta.7/cargo-tangle-installer.sh | sh
14+
$ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/tangle-network/gadget/releases/download/cargo-tangle-v0.3.3/cargo-tangle-installer.sh | sh
1515
```
1616

1717
2. From [crates.io](https://crates.io) (stable)

pages/developers/cli/quickstart.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ title: Quickstart
1111

1212
## Creating a New Project
1313

14-
1. Open your terminal and run:
14+
1. For an in-depth guide to commands, see the [CLI Reference](./reference.mdx). To get started
15+
right away with creating a Tangle Blueprint, open your terminal and run:
1516

1617
```shell
1718
$ cargo tangle blueprint create --name <blueprint-name>
1819
```
1920

20-
2. Follow the prompts to set up your project.
21+
2. Follow the prompts to set up your project. The following image shows the prompt flow with example input and defaults selected.
2122

22-
{/* TODO: Add a GIF */}
23+
![CLI Blueprint Creation](/images/cli-blueprint-create.png)
2324

2425
### Project Structure
2526

pages/developers/cli/reference.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Creates a new blueprint
3030
- `--name` (**required**): The name of the blueprint
3131
- `--repo`: The repo to pull the template from, by default this uses the hello world [blueprint template](https://github.com/tangle-network/blueprint-template)
3232
- `--path`: The path to copy a template from, no default value
33+
- `--eigenlayer`: Uses an Eigenlayer template for creating an AVS, defaulting to the BLS version as seen below
3334

3435
Usage:
3536

@@ -45,6 +46,17 @@ Create a blueprint using another template from git
4546
$ cargo tangle blueprint create --name <name> --repo <git-repo-url>
4647
```
4748

49+
Create an EigenLayer AVS:
50+
51+
```shell
52+
$ cargo tangle blueprint create --name <project-name> --eigenlayer <type>
53+
```
54+
55+
where the following are the possible types (defaulting to bls if the type is omitted):
56+
57+
- `bls`: Generates from our [BLS template](https://github.com/tangle-network/eigenlayer-bls-template), with contracts for BLS interaction
58+
- `ecdsa`: Generates from our [ECDSA template](https://github.com/tangle-network/eigenlayer-ecdsa-template), with ECDSA-oriented contracts
59+
4860
#### Deploy
4961

5062
Deploy a blueprint to Tangle

0 commit comments

Comments
 (0)