-
Notifications
You must be signed in to change notification settings - Fork 281
Generate runtime API from metadata #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f43df0e
01b7131
ff6b9fc
d7c1d22
b755c29
05fe051
5e91406
59aa4d7
e337d34
8540533
e917dac
2ef017d
f3005cb
e4f1374
b98b7aa
e20f123
2cf09c1
56cb2a6
c35d781
4726db3
f8f8b47
4b573f5
a6e7225
d2bd669
11248d0
b9ad905
f98d95a
a8ca64a
9eac486
a5281fc
bbb4530
2d7bed8
8ab7976
6ac3f42
c935dc1
13f69a3
af7c4ce
4e47acd
7e2ed94
a2bb550
0b233e0
09c5888
93c121d
a503911
b362dfd
8357031
e5333f1
5405fb7
1034b68
8556bc0
ed0d1bc
327a215
e70534e
d75d1f0
634f21f
cedf27e
690e079
b82d4e8
8342c31
4cb16a3
97308a9
f8f2da6
4d0e392
a264cf3
2eb657a
c89791f
537c633
73490a3
4ab94d5
9a6c98c
599863e
b99685a
f3ae886
a5c51af
92f8665
7da7f56
01558f5
0203365
184c096
e778231
ba71cc0
cadb26f
2766b40
1b04411
af1ec84
bbad328
c8ebd1c
0cf8ec7
d68e7dd
a6f8eb4
20aee21
3de2815
c5ef0fa
b2f0ddf
e8256e0
d0dda23
6198ac2
cbbf0e1
76d7b11
c86a9ce
d439722
997d6b7
44ec197
950845f
3cb4000
602f62b
4d1de1b
384f88e
b340bc2
f1b7b85
ec90ecc
e4907d4
bab2aef
696ee63
560ceb5
c5915b9
5e9b7d2
34e1da5
442fe24
35a3141
83af04e
b95ce3d
79355d3
5e7b7e7
368ec3b
f819cb6
903b153
d984dd5
a9d1e8f
ccb1491
ffc1a3c
f46c944
f834035
fc80bb0
72dc1f9
6563914
c66ac9f
7594bc5
d0b0bb1
2c2dd9f
7d9884d
cc0212d
ea4666f
851f612
69e6ed6
a30f9f8
d5bec8c
567ce0e
a672dc4
518c028
699ce18
021c186
99a83c7
27c5b92
4df1313
da5bb8d
c2e7ab7
8108f00
fd18fcd
643c8f8
77ae552
a0447ff
562b593
398c63c
192fa39
adf8ebd
e430d1b
90312bd
b2d04bb
d1566e8
927aa00
b26cd2f
091b255
cdb881e
da71f69
23be116
9d8c9a1
b500ac4
43f59e4
c19d2e6
1fd0d5f
0c45452
57f7a0b
4b45985
7caec49
d4a4ce0
cc1fdab
b570e39
9fd9540
4657b57
36d5e57
d250904
9818d0d
13915e2
69ee2da
e8a8376
4f3de30
1d1fffe
b301a85
c1f6d53
a97fb2e
d58834b
d0f5e69
9da0bcc
346504b
2f36a89
6306b9f
5dd6cf9
fc30e90
63bb5ea
84fe1a0
6886f4c
63641b4
ba2e3a8
06a6ddf
0d07b0c
f0bb889
2c93f3c
641ac27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,37 +75,6 @@ pub struct Metadata { | |
| } | ||
|
|
||
| impl Metadata { | ||
| /// Create a new indexed `Metadata` instance from the imported runtime metadata. | ||
| pub fn new(metadata: RuntimeMetadataLastVersion) -> Result<Self, InvalidMetadataError> { | ||
| let pallets = metadata.pallets.iter() | ||
| .map(|pallet| { | ||
| let calls = pallet.calls | ||
| .as_ref() | ||
| .map_or(Ok(HashMap::new()), |call| { | ||
| let ty = metadata.types.resolve(call.ty.id()) | ||
| .ok_or(InvalidMetadataError::MissingCallType)?; | ||
| if let scale_info::TypeDef::Variant(var) = ty.type_def() { | ||
| let calls = var.variants().iter().map(|v| (v.name().clone(), v.index())).collect(); | ||
| Ok(calls) | ||
| } else { | ||
| Err(InvalidMetadataError::CallTypeNotVariant) | ||
| } | ||
| })?; | ||
|
|
||
| let pallet_metadata = PalletMetadata { | ||
| index: pallet.index, | ||
| name: pallet.name.to_string(), | ||
| calls, | ||
| storage: Default::default(), | ||
| constants: Default::default() | ||
| }; | ||
|
|
||
| Ok((pallet.name.to_string(), pallet_metadata)) | ||
| }) | ||
| .collect::<Result<_, _>>()?; | ||
| Ok(Self { metadata, pallets }) | ||
| } | ||
|
|
||
| /// Returns `PalletMetadata`. | ||
| pub fn pallet(&self, name: &'static str) -> Result<&PalletMetadata, MetadataError> { | ||
| self.pallets.get(name) | ||
|
|
@@ -304,95 +273,39 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata { | |
| type Error = InvalidMetadataError; | ||
|
|
||
| fn try_from(metadata: RuntimeMetadataPrefixed) -> Result<Self, Self::Error> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This conversion between
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| todo!() | ||
| // if metadata.0 != META_RESERVED { | ||
| // return Err(ConversionError::InvalidPrefix.into()) | ||
| // } | ||
| // let meta = match metadata.1 { | ||
| // RuntimeMetadata::V14(meta) => meta, | ||
| // _ => return Err(ConversionError::InvalidVersion.into()), | ||
| // }; | ||
| // let mut modules = HashMap::new(); | ||
| // let mut modules_with_calls = HashMap::new(); | ||
| // let mut modules_with_events = HashMap::new(); | ||
| // let mut modules_with_errors = HashMap::new(); | ||
| // for module in convert(meta.modules)?.into_iter() { | ||
| // let module_name = convert(module.name.clone())?; | ||
| // | ||
| // let mut constant_map = HashMap::new(); | ||
| // for constant in convert(module.constants)?.into_iter() { | ||
| // let constant_meta = convert_constant(constant)?; | ||
| // constant_map.insert(constant_meta.name.clone(), constant_meta); | ||
| // } | ||
| // | ||
| // let mut storage_map = HashMap::new(); | ||
| // if let Some(storage) = module.storage { | ||
| // let storage = convert(storage)?; | ||
| // let module_prefix = convert(storage.prefix)?; | ||
| // for entry in convert(storage.entries)?.into_iter() { | ||
| // let storage_prefix = convert(entry.name.clone())?; | ||
| // let entry = convert_entry( | ||
| // module_prefix.clone(), | ||
| // storage_prefix.clone(), | ||
| // entry, | ||
| // )?; | ||
| // storage_map.insert(storage_prefix, entry); | ||
| // } | ||
| // } | ||
| // modules.insert( | ||
| // module_name.clone(), | ||
| // ModuleMetadata { | ||
| // index: module.index, | ||
| // name: module_name.clone(), | ||
| // storage: storage_map, | ||
| // constants: constant_map, | ||
| // }, | ||
| // ); | ||
| // | ||
| // if let Some(calls) = module.calls { | ||
| // let mut call_map = HashMap::new(); | ||
| // for (index, call) in convert(calls)?.into_iter().enumerate() { | ||
| // let name = convert(call.name)?; | ||
| // call_map.insert(name, index as u8); | ||
| // } | ||
| // modules_with_calls.insert( | ||
| // module_name.clone(), | ||
| // ModuleWithCalls { | ||
| // index: module.index, | ||
| // calls: call_map, | ||
| // }, | ||
| // ); | ||
| // } | ||
| // if let Some(events) = module.event { | ||
| // let mut event_map = HashMap::new(); | ||
| // for (index, event) in convert(events)?.into_iter().enumerate() { | ||
| // event_map.insert(index as u8, convert_event(event)?); | ||
| // } | ||
| // modules_with_events.insert( | ||
| // module_name.clone(), | ||
| // ModuleWithEvents { | ||
| // index: module.index, | ||
| // name: module_name.clone(), | ||
| // events: event_map, | ||
| // }, | ||
| // ); | ||
| // } | ||
| // let mut error_map = HashMap::new(); | ||
| // for (index, error) in convert(module.errors)?.into_iter().enumerate() { | ||
| // error_map.insert(index as u8, convert_error(error)?); | ||
| // } | ||
| // modules_with_errors.insert( | ||
| // module_name.clone(), | ||
| // ModuleWithErrors { | ||
| // index: module.index, | ||
| // name: module_name.clone(), | ||
| // errors: error_map, | ||
| // }, | ||
| // ); | ||
| // } | ||
| // Ok(Metadata { | ||
| // pallets, | ||
| // | ||
| // }) | ||
| if metadata.0 != META_RESERVED { | ||
| return Err(InvalidMetadataError::InvalidPrefix.into()) | ||
| } | ||
| let metadata = match metadata.1 { | ||
| RuntimeMetadata::V14(meta) => meta, | ||
| _ => return Err(InvalidMetadataError::InvalidVersion.into()), | ||
| }; | ||
| let pallets = metadata.pallets.iter() | ||
| .map(|pallet| { | ||
| let calls = pallet.calls | ||
| .as_ref() | ||
| .map_or(Ok(HashMap::new()), |call| { | ||
| let ty = metadata.types.resolve(call.ty.id()) | ||
| .ok_or(InvalidMetadataError::MissingCallType)?; | ||
| if let scale_info::TypeDef::Variant(var) = ty.type_def() { | ||
| let calls = var.variants().iter().map(|v| (v.name().clone(), v.index())).collect(); | ||
| Ok(calls) | ||
| } else { | ||
| Err(InvalidMetadataError::CallTypeNotVariant) | ||
| } | ||
| })?; | ||
|
|
||
| let pallet_metadata = PalletMetadata { | ||
| index: pallet.index, | ||
| name: pallet.name.to_string(), | ||
| calls, | ||
| storage: Default::default(), | ||
| constants: Default::default() | ||
| }; | ||
|
|
||
| Ok((pallet.name.to_string(), pallet_metadata)) | ||
| }) | ||
| .collect::<Result<_, _>>()?; | ||
| Ok(Self { metadata, pallets }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.