@@ -6,56 +6,49 @@ use frame::prelude::*;
66use pvq_extension:: metadata:: Metadata ;
77pub use pvq_primitives:: PvqResult ;
88
9- use pvq_extension:: { impl_extensions , ExtensionsExecutor , InvokeSource } ;
9+ use pvq_extension:: { extensions_impl , ExtensionsExecutor , InvokeSource } ;
1010decl_runtime_apis ! {
1111 pub trait PvqApi {
1212 fn execute_query( query: Vec <u8 >, input: Vec <u8 >) -> PvqResult ;
1313 fn metadata( ) -> Vec <u8 >;
1414 }
1515}
1616
17- // extension_core impls
18- pub struct ExtensionImpl ;
19-
20- impl pvq_extension_core:: Config for ExtensionImpl {
21- type ExtensionId = u64 ;
22- }
23-
24- // extension_fungibles impls
25- impl pvq_extension_fungibles:: Config for ExtensionImpl {
26- type AccountId = [ u8 ; 32 ] ;
27- type Balance = crate :: interface:: Balance ;
28- type AssetId = crate :: interface:: AssetId ;
29- }
30- impl_extensions ! {
31- impl pvq_extension_core:: ExtensionCore for ExtensionImpl {
32- type Config = ExtensionImpl ;
33- fn has_extension( id: <Self :: Config as pvq_extension_core:: Config >:: ExtensionId ) -> bool {
34- matches!( id, pvq_extension_core:: EXTENSION_ID | pvq_extension_fungibles:: EXTENSION_ID )
17+ #[ extensions_impl]
18+ pub mod extensions {
19+ #[ extensions_impl:: impl_struct]
20+ pub struct ExtensionImpl ;
21+
22+ #[ extensions_impl:: extension]
23+ impl pvq_extension_core:: extension:: ExtensionCore for ExtensionImpl {
24+ type ExtensionId = u64 ;
25+ fn has_extension ( id : Self :: ExtensionId ) -> bool {
26+ id == pvq_extension_core:: extension:: extension_id ( )
27+ || id == pvq_extension_fungibles:: extension:: extension_id ( )
3528 }
3629 }
3730
38- impl pvq_extension_fungibles :: ExtensionFungibles for ExtensionImpl {
39- type Config = ExtensionImpl ;
40- fn balance (
41- asset : < Self :: Config as pvq_extension_fungibles :: Config > :: AssetId ,
42- who : < Self :: Config as pvq_extension_fungibles :: Config > :: AccountId ,
43- ) -> < Self :: Config as pvq_extension_fungibles :: Config > :: Balance {
31+ # [ extensions_impl :: extension ]
32+ impl pvq_extension_fungibles :: extension :: ExtensionFungibles for ExtensionImpl {
33+ type AccountId = [ u8 ; 32 ] ;
34+ type Balance = crate :: interface :: Balance ;
35+ type AssetId = crate :: interface :: AssetId ;
36+ fn balance ( asset : Self :: AssetId , who : Self :: AccountId ) -> Self :: Balance {
4437 crate :: Assets :: balance ( asset, crate :: interface:: AccountId :: from ( who) )
4538 }
46- fn total_supply( asset: < Self :: Config as pvq_extension_fungibles :: Config > :: AssetId ) -> < Self :: Config as pvq_extension_fungibles :: Config > :: Balance {
39+ fn total_supply ( asset : Self :: AssetId ) -> Self :: Balance {
4740 crate :: Assets :: total_supply ( asset)
4841 }
4942 }
5043}
5144
5245pub fn execute_query ( query : & [ u8 ] , input : & [ u8 ] ) -> PvqResult {
53- let mut executor = ExtensionsExecutor :: < Extensions , ( ) > :: new ( InvokeSource :: RuntimeAPI ) ;
54- executor. execute_method ( query, input)
46+ let mut executor = ExtensionsExecutor :: < extensions :: Extensions , ( ) > :: new ( InvokeSource :: RuntimeAPI ) ;
47+ executor. execute_method ( query, input, 0 )
5548}
5649
5750pub fn metadata ( ) -> Metadata {
58- ExtensionImpl :: metadata ( )
51+ extensions :: metadata ( )
5952}
6053
6154#[ cfg( test) ]
0 commit comments