-
Notifications
You must be signed in to change notification settings - Fork 11
map mycelium to twin identity #1037
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: development
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MyceliumPkInput > MyceliumPk
@@ -263,6 +265,16 @@ pub mod pallet { | |||
ValueQuery, | |||
>; | |||
|
|||
#[pallet::storage] | |||
#[pallet::getter(fn get_mycelium_twin)] | |||
pub type MyceliumTwin<T: Config> = StorageMap< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MyceliumTwin > TwinIdByMyceliumPk
@@ -263,6 +265,16 @@ pub mod pallet { | |||
ValueQuery, | |||
>; | |||
|
|||
#[pallet::storage] | |||
#[pallet::getter(fn get_mycelium_twin)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for the new call
@@ -411,6 +423,7 @@ pub mod pallet { | |||
TwinEntityRemoved(u32, u32), | |||
TwinDeleted(u32), | |||
TwinAccountBounded(u32, T::AccountId), | |||
MyceliumTwinUpdated(MyceliumPkInput, u32), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add tests to the client
@@ -201,3 +201,43 @@ pub async fn get_balance( | |||
.fetch(¤t::storage().system().account(account)) | |||
.await?) | |||
} | |||
|
|||
pub async fn set_mycelium_twin( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Uh oh!
There was an error while loading. Please reload this page.