Skip to content

Commit 10a2fb9

Browse files
committed
WIP: basin functions for worker manager
1 parent e291abd commit 10a2fb9

File tree

7 files changed

+411
-53
lines changed

7 files changed

+411
-53
lines changed

worker-manager/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ default = []
2525
backtraces = ["cosmwasm-std/backtraces"]
2626

2727
[dependencies]
28-
cosmwasm-std = { git = "https://github.com/scrtlabs/cosmwasm", tag = "v1.1.9-secret" }
29-
cosmwasm-storage = { git = "https://github.com/scrtlabs/cosmwasm", tag = "v1.1.9-secret" }
28+
cosmwasm-std = { package = "secret-cosmwasm-std", version = "1.1.11" }
29+
cosmwasm-storage = { package = "secret-cosmwasm-storage", version = "1.1.11" }
30+
secret-toolkit = { version = "0.10.0", default-features = false, features = [
31+
"storage"
32+
] }
3033
schemars = { version = "0.8.11" }
3134
serde = { version = "1.0" }
3235
thiserror = { version = "1.0" }

worker-manager/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ build-mainnet-reproducible:
3838

3939
.PHONY: compress-wasm
4040
compress-wasm:
41-
cp ./target/wasm32-unknown-unknown/release/*.wasm ./contract.wasm
41+
cp ./target/wasm32-unknown-unknown/release/claive_worker_manager.wasm ./contract.wasm
4242
@## The following line is not necessary, may work only on linux (extra size optimization)
4343
@# wasm-opt -Os ./contract.wasm -o ./contract.wasm
4444
cat ./contract.wasm | gzip -9 > ./contract.wasm.gz

worker-manager/Readme.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Worker Manager Smart Contract
2+
3+
This smart contract is designed to manage a list of workers. Each worker is registered with their IP address, payment wallet, and an attestation report. The contract allows administrators and workers to interact with and update worker information, as well as query the current state of registered workers.
4+
5+
## Features
6+
7+
- **Register a Worker**: Allows the registration of a worker with their IP address, payment wallet, and attestation report.
8+
- **Set Worker Wallet**: Allows a worker to update their payment wallet.
9+
- **Set Worker Address**: Allows a worker to update their IP address.
10+
- **Query Workers**: Allows querying of all registered workers.
11+
- **Liveliness Reporting**: A placeholder for liveliness reporting (yet to be implemented).
12+
- **Work Reporting**: A placeholder for work reporting (yet to be implemented).
13+
14+
## Contract Structure
15+
16+
### Messages
17+
18+
- **InstantiateMsg**: Used for instantiating the contract with an administrator.
19+
- **ExecuteMsg**: Used to execute contract actions like registering a worker, setting worker details, etc.
20+
- **QueryMsg**: Used to query the state of the contract, such as fetching workers or liveliness challenges.
21+
22+
### State
23+
24+
The contract stores the state using the following data structures:
25+
26+
- **State**: Holds the admin address.
27+
- **Worker**: Stores a worker's information, such as IP address, payment wallet, and attestation report.
28+
- **WORKERS_MAP**: A mapping that associates a worker's IP address with their information.
29+
30+
## Functions
31+
32+
### `try_register_worker`
33+
34+
Registers a worker by adding their IP address, payment wallet, and attestation report to the storage.
35+
36+
### `try_set_worker_wallet`
37+
38+
Allows a worker to update their payment wallet. It searches for a worker using the sender's address and updates their wallet.
39+
40+
### `try_set_worker_address`
41+
42+
Allows a worker to update their IP address. It searches for a worker using the sender's address and updates their IP address.
43+
44+
### `try_report_liveliness`
45+
46+
A placeholder function for reporting worker liveliness. This feature has yet to be implemented.
47+
48+
### `try_report_work`
49+
50+
A placeholder function for reporting a worker's work. This feature has yet to be implemented.
51+
52+
### `query_workers`
53+
54+
Queries all workers in storage and returns a list of their information.
55+
56+
### `query_liveliness_challenge`
57+
58+
Returns a liveliness challenge (placeholder response). This feature has yet to be implemented.
59+
60+
## How to Deploy
61+
62+
1. **Set up the CosmWasm environment**:
63+
- Install the required tools for working with CosmWasm contracts, such as Rust, Cargo, and CosmWasm CLI.
64+
65+
2. **Compile the Contract**:
66+
- Use `make build` to compile the contract to WebAssembly (Wasm).
67+
68+
3. **Deploy the Contract**:
69+
- Deploy the compiled contract to the Secret Network using the `secretcli` or other relevant tools.
70+
71+
4. **Interact with the Contract**:
72+
- Once deployed, you can interact with the contract using `secretcli` or by sending transactions via the Secret Network REST or gRPC endpoints.
73+
74+
## Example Queries and Transactions
75+
76+
### Register a Worker
77+
78+
To register a worker, execute the `RegisterWorker` action with the required parameters:
79+
80+
```bash
81+
secretcli tx compute exec <contract_address> '{"register_worker":{"ip_address":"192.168.1.1","payment_wallet":"secret1xyz","attestation_report":""}}' --from <your_wallet>
82+
```
83+
84+
### Query Workers
85+
86+
To query all workers, execute the `GetWorkers` query:
87+
88+
```bash
89+
secretcli q compute query <contract_address> '{"get_workers": {"address":"", "signature":"", "subscriber_public_key":""}}'
90+
```
91+
92+
### Set Worker Wallet
93+
94+
To update a worker's wallet:
95+
96+
```bash
97+
secretcli tx compute exec <contract_address> '{"set_worker_wallet":{"payment_wallet":"secret1newwallet"}}' --from <your_wallet>
98+
```
99+
### Set Worker Address
100+
101+
To update a worker's wallet:
102+
103+
```bash
104+
secretcli tx compute exec <contract_address> '{"set_worker_address": {"new_ip_address": "<new_ip>", "old_ip_address": "<old_ip>>"}}' --from <your_wallet>
105+
```
106+
107+
### Notes
108+
109+
- Currently, the contract does not verify signed messages in queries or check the attestation report for simplicity. These features will be added soon.
110+
- Liveliness reporting and work reporting are placeholder features and have not been implemented yet.

worker-manager/src/bin/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fs::create_dir_all;
44
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
55

66
use claive_worker_manager::msg::{
7-
ExecuteMsg, GetLivelinessChallengeResponse, GetNextWorkerResponse, InstantiateMsg, QueryMsg,
7+
ExecuteMsg, GetLivelinessChallengeResponse, GetWorkersResponse, InstantiateMsg, QueryMsg,
88
};
99
use claive_worker_manager::state::State;
1010

@@ -18,6 +18,6 @@ fn main() {
1818
export_schema(&schema_for!(ExecuteMsg), &out_dir);
1919
export_schema(&schema_for!(QueryMsg), &out_dir);
2020
export_schema(&schema_for!(State), &out_dir);
21-
export_schema(&schema_for!(GetNextWorkerResponse), &out_dir);
21+
export_schema(&schema_for!(GetWorkersResponse), &out_dir);
2222
export_schema(&schema_for!(GetLivelinessChallengeResponse), &out_dir);
2323
}

0 commit comments

Comments
 (0)