|
| 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. |
0 commit comments