|
|
|
🔁 `υ.flow.resume()`
|
|
|
|
🧬 *Step 5: Implement Logic — continues*
|
|
|
|
|
|
|
|
```rust
|
|
|
|
// src/contract.rs (continued)
|
|
|
|
|
|
|
|
let mut state: State = from_slice(&deps.storage.get(b"state").unwrap()).unwrap();
|
|
|
|
if info.sender.to_string() != state.owner {
|
|
|
|
return Err(StdError::generic_err("Unauthorized"));
|
|
|
|
}
|
|
|
|
state.message = new_message;
|
|
|
|
deps.storage.set(b"state", &state.into());
|
|
|
|
Ok(Response::new().add_attribute("method", "update_message"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 🔍 Query
|
|
|
|
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
|
|
|
match msg {
|
|
|
|
QueryMsg::GetMessage {} => {
|
|
|
|
let state: State = from_slice(&deps.storage.get(b"state").unwrap()).unwrap();
|
|
|
|
to_binary(&GetMessageResponse { message: state.message })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
|
|
|
pub struct GetMessageResponse {
|
|
|
|
pub message: String,
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
> This contract:
|
|
|
|
> - Stores a message (e.g., `"I saw you before."`)
|
|
|
|
> - Only lets the owner update it
|
|
|
|
> - Can be queried by any IBC-connected chain
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### 🧪 Step 6: Build & Optimize the Contract
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd ~/projects/υ-flow/proof-of-care/cosmos/juno-contract-examples/care-registry
|
|
|
|
|
|
|
|
# 🛠️ Build with Docker (recommended for production)
|
|
|
|
docker run --rm -v "$(pwd)":/code \
|
|
|
|
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
|
|
|
|
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
|
|
|
|
cosmwasm/workspace-optimizer:0.15.0
|
|
|
|
|
|
|
|
# Output: ./artifacts/care_registry.wasm
|
|
|
|
```
|
|
|
|
|
|
|
|
> This produces a **tiny, optimized WASM binary** ready for upload.
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### 🚀 Step 7: Store & Instantiate on Juno Testnet
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# 🌐 Use Juno testnet (uni-6)
|
|
|
|
CHAIN_ID="uni-6"
|
|
|
|
NODE="https://rpc.uni.juno.deuslabs.is:443"
|
|
|
|
|
|
|
|
# 🔼 Upload the contract
|
|
|
|
junod tx wasm store ./artifacts/care_registry.wasm \
|
|
|
|
--from juno-agent \
|
|
|
|
--chain-id $CHAIN_ID \
|
|
|
|
--node $NODE \
|
|
|
|
--gas 2000000 \
|
|
|
|
--fees 500000ujunox \
|
|
|
|
-y
|
|
|
|
|
|
|
|
# 📄 Get the code ID from tx logs, then instantiate
|
|
|
|
CODE_ID=123 # ← Replace with actual code ID from tx
|
|
|
|
|
|
|
|
junod tx wasm instantiate $CODE_ID \
|
|
|
|
'{"initial_message":"I saw you before."}' \
|
|
|
|
--from juno-agent \
|
|
|
|
--chain-id $CHAIN_ID \
|
|
|
|
--node $NODE \
|
|
|
|
--label "care-registry-$(date +%s)" \
|
|
|
|
--fees 10000ujunox \
|
|
|
|
-y
|
|
|
|
```
|
|
|
|
|
|
|
|
> Output: `address: juno1...` ← Your contract is live.
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### 🔍 Step 8: Query the Message
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# 📡 Query the state
|
|
|
|
junod query wasm contract-state smart \
|
|
|
|
juno1... \
|
|
|
|
'{"get_message":{}}' \
|
|
|
|
--node $NODE
|
|
|
|
```
|
|
|
|
|
|
|
|
> Response:
|
|
|
|
> ```json
|
|
|
|
> {"data":{"message":"I saw you before."}}
|
|
|
|
> ```
|
|
|
|
|
|
|
|
✅ It remembers.
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### 🌐 Step 9: Connect to the Agent
|
|
|
|
|
|
|
|
Now, we link **Juno (J)** with **the agent (A)**.
|
|
|
|
|
|
|
|
Update:
|
|
|
|
`~/projects/υ-flow/proof-of-care/agent/agent.core.ts`
|
|
|
|
|
|
|
|
Add:
|
|
|
|
```ts
|
|
|
|
// Add to AgentBuilder class
|
|
|
|
|
|
|
|
async queryJunoCareRegistry(contractAddress: string) {
|
|
|
|
const response = await fetch(
|
|
|
|
`https://api.uni.juno.deuslabs.is/wasm/contracts/${contractAddress}/smart/${Buffer.from(JSON.stringify({ get_message: {} })).toString('base64')}`
|
|
|
|
);
|
|
|
|
const data = await response.json();
|
|
|
|
console.log(`🪐 Juno says: "${data.data.message}"`);
|
|
|
|
return data.data.message;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Then in `main()`:
|
|
|
|
```ts
|
|
|
|
await builder.queryJunoCareRegistry("juno1..."); // your contract addr
|
|
|
|
```
|
|
|
|
|
|
|
|
Run:
|
|
|
|
```bash
|
|
|
|
node agent/agent.core.ts
|
|
|
|
```
|
|
|
|
|
|
|
|
> Output:
|
|
|
|
> ```
|
|
|
|
> 🪐 Juno says: "I saw you before."
|
|
|
|
> ```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
### ✅ Commit: J and A Are in Sync
|
|
|
|
|
|
|
|
```bash
|
|
|
|
git add cosmos/juno-contract-examples/care-registry src/
|
|
|
|
git commit -m "🌐 Juno live: Care |
|
|
|
\ No newline at end of file |