Conversation
b557493 to
3fd0ab0
Compare
- add storage map from myc->twin - add setter method to update the storage which emit TwinMyceliumPkSet event - update rs/ts/go clients with setter/getter methods
3fd0ab0 to
e325c9f
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a mapping between a mycelium public key and a twin identity by adding new storage, extrinsics, events, and updating client libraries.
- Adds a new storage map (MyceliumTwin) and setter extrinsic (set_mycelium_twin) that emits the MyceliumTwinUpdated event.
- Updates weights, benchmarking, and clients in Rust, JavaScript, and Go to support the new mapping functionality.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| substrate-node/pallets/pallet-tfgrid/src/weights.rs | Added weight calculation for the new extrinsic. |
| substrate-node/pallets/pallet-tfgrid/src/twin.rs | Introduced the internal setter _set_mycelium_twin with event emission. |
| substrate-node/pallets/pallet-tfgrid/src/lib.rs | Added storage definition and new extrinsic for mapping. |
| substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs | Added benchmarks for the new extrinsic. |
| scripts/activate/man.go | Updated activation script (no direct mapping changes). |
| scripts/activate/go.mod | Added dependency changes for the activation module. |
| clients/tfchain-client-rs/* | Updated runtime client functions for setting/getting the mapping. |
| clients/tfchain-client-js/* | Updated twin module and client to support the new extrinsic. |
| clients/tfchain-client-go/* | Added new functions to map the mycelium public key to a twin. |
| clients/tfchain-client-go/events.go | Introduced the event struct MyceliumTwinUpdated. |
Comments suppressed due to low confidence (1)
substrate-node/pallets/pallet-tfgrid/src/twin.rs:412
- [nitpick] Consider renaming '_set_mycelium_twin' to a name without a leading underscore (e.g. 'set_mycelium_twin_inner') since it is a public function. This helps clarify its intended internal usage and avoids confusion with private functions.
pub fn _set_mycelium_twin(
| Weight::from_parts(12_053_000, 3852) | ||
| .saturating_add(RocksDbWeight::get().reads(1_u64)) | ||
| .saturating_add(RocksDbWeight::get().writes(1_u64)) | ||
| } |
There was a problem hiding this comment.
This file shouldn't be manually updated
|
|
||
| // Step 3: Create Alice's identity for sending tokens | ||
| fmt.Println("Setting up Alice's identity for token transfer...") | ||
| aliceIdentity, err := substrate.NewIdentityFromSr25519Phrase("//Alice") |
There was a problem hiding this comment.
What is this script intended for?
Unless this is for a local setup, it won't work. Alice is poor(has nothing) on our dev networks
| pub type MyceliumTwin<T: Config> = StorageMap< | ||
| _, | ||
| Blake2_128Concat, | ||
| MyceliumPkInput, // key is mycelium pk |
There was a problem hiding this comment.
MyceliumPkInput > MyceliumPk
|
|
||
| #[pallet::storage] | ||
| #[pallet::getter(fn get_mycelium_twin)] | ||
| pub type MyceliumTwin<T: Config> = StorageMap< |
There was a problem hiding this comment.
MyceliumTwin > TwinIdByMyceliumPk
| >; | ||
|
|
||
| #[pallet::storage] | ||
| #[pallet::getter(fn get_mycelium_twin)] |
There was a problem hiding this comment.
get_mycelium_twin > twin_id_by_mycelium_pubkey
|
|
||
| #[pallet::call_index(40)] | ||
| #[pallet::weight(<T as Config>::WeightInfo::set_mycelium_twin())] | ||
| pub fn set_mycelium_twin( |
There was a problem hiding this comment.
set_mycelium_twin > set_twin_mycelium_pk
| pub fn set_mycelium_twin( | ||
| origin: OriginFor<T>, | ||
| mycelium_pk: MyceliumPkInput, | ||
| twin_id: u32, |
There was a problem hiding this comment.
Do we need to pass this twin ID? At the end, we use the sender account's twin to update the pk?
| ensure!(twin.account_id == account_id, Error::<T>::UnauthorizedToUpdateTwin); | ||
|
|
||
| // Store the mapping | ||
| MyceliumTwin::<T>::insert(&mycelium_pk, twin_id); |
There was a problem hiding this comment.
Could we implement some form of validation?
|
|
||
| #[pallet::call_index(40)] | ||
| #[pallet::weight(<T as Config>::WeightInfo::set_mycelium_twin())] | ||
| pub fn set_mycelium_twin( |
There was a problem hiding this comment.
Please add tests for the new call
| TwinEntityRemoved(u32, u32), | ||
| TwinDeleted(u32), | ||
| TwinAccountBounded(u32, T::AccountId), | ||
| MyceliumTwinUpdated(MyceliumPkInput, u32), |
There was a problem hiding this comment.
Since MyceliumPk belongs to a twin
MyceliumTwinUpdated > TwinMyceliumPkUpdated
| // | ||
| // Returns: | ||
| // - error: nil on success, error on failure | ||
| func (s *Substrate) SetMyceliumTwin(identity Identity, myceliumPK string, twinID uint32) error { |
There was a problem hiding this comment.
Could you add tests to the client
| .await?) | ||
| } | ||
|
|
||
| pub async fn set_mycelium_twin( |
There was a problem hiding this comment.
Since you are updating the rs client, you need to re-generate the client scale file
|
I don't believe we should proceed with this |
|
I converted this PR to a draft till we have a final consensus. |
Uh oh!
There was an error while loading. Please reload this page.