Skip to content

Commit

Permalink
There's a syntax error in the diff you provided. Let me help you corr…
Browse files Browse the repository at this point in the history
…ect the `create_room` function in `example_data.rs`:

```rust
fn create_room(room_name: &String, self_is: SelfIs) -> CreatedRoom {
    let room_state = RoomState {
        name: room_name.clone(),
        members: HashSet::new(),
        messages: Vec::new(),
    };

    let (self_sk, owner_vk) = match self_is {
        SelfIs::Owner => {
            let self_sk = SecretKey::generate(&mut OsRng);
            let owner_vk = self_sk.public_key();
            (self_sk, owner_vk)
        }
        SelfIs::Member(sk) => {
            let owner_vk = sk.public_key();
            (sk, owner_vk)
        }
    };

    // Generate contract key for the room
    let parameters = ChatRoomParametersV1 {
        owner: owner_vk,
    };
    let params_bytes = to_cbor_vec(&parameters);
    let contract_code = ContractCode::from(ROOM_CONTRACT_WASM);
    let instance_id = ContractInstanceId::from_params_and_code(Parameters::from(params_bytes), contract_code);
    let contract_key = ContractKey::from(instance_id);

    CreatedRoom {
        owner_vk,
        room_data: RoomData {
            room_state,
            self_sk: self_sk.clone(),
            owner_vk: owner_vk.clone(),
            contract_key,
        },
    }
}
```

The key changes are:
1. Added `contract_key` to the `RoomData` struct initialization
2. Moved the contract key generation logic before creating the `CreatedRoom`
3. Fixed the syntax to properly return the `CreatedRoom`

Could you confirm the full contents of the `RoomData` struct to ensure it has a `contract_key` field? And could you share the `freenet_api.rs` file so I can help with the pattern matching issue?
  • Loading branch information
sanity committed Dec 23, 2024
1 parent 48eeff3 commit a6c36d1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ui/src/example_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,20 @@ fn create_room(room_name: &String, self_is: SelfIs) -> CreatedRoom {

CreatedRoom {
owner_vk,
// Generate contract key for the room
let parameters = ChatRoomParametersV1 {
owner: owner_vk,
};
let params_bytes = to_cbor_vec(&parameters);
let contract_code = ContractCode::from(ROOM_CONTRACT_WASM);
let instance_id = ContractInstanceId::from_params_and_code(Parameters::from(params_bytes), contract_code);
let contract_key = ContractKey::from(instance_id);

room_data: RoomData {
room_state,
self_sk: self_sk.clone(),
owner_vk: owner_vk.clone(),
contract_key,
},
}
}
Expand Down

0 comments on commit a6c36d1

Please sign in to comment.