mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Metadata V16: Implement support for Pallet View Functions (#1981)
* Support Pallet View Functions in Subxt * fmt * clippy * Move a little view function logic to subxt_core * clippy * Add back check that prob isnt needed * avoid vec macro in core * Add view funciton test and apply various fixes to get it working * Add test for dynamic view fn call and fix issues * clippy * fix test-runtime * fmt * remove export * avoid vec for nostd core * use const instead of fn for view fn call name * Update to support latest unstable metadata * Update metadata stripping tests for new v16 version
This commit is contained in:
@@ -7,6 +7,7 @@ mod client;
|
||||
mod codegen;
|
||||
mod frame;
|
||||
mod metadata_validation;
|
||||
mod pallet_view_functions;
|
||||
mod runtime_api;
|
||||
mod storage;
|
||||
mod transactions;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
use crate::{subxt_test, test_context};
|
||||
use test_runtime::node_runtime_unstable;
|
||||
|
||||
#[subxt_test]
|
||||
async fn call_view_function() -> Result<(), subxt::Error> {
|
||||
let ctx = test_context().await;
|
||||
let api = ctx.client();
|
||||
|
||||
use node_runtime_unstable::proxy::view_functions::check_permissions::{Call, ProxyType};
|
||||
|
||||
// This is one of only two view functions that currently exists at the time of writing.
|
||||
let call = Call::System(node_runtime_unstable::system::Call::remark {
|
||||
remark: b"hi".to_vec(),
|
||||
});
|
||||
let proxy_type = ProxyType::Any;
|
||||
let view_function_call = node_runtime_unstable::view_functions()
|
||||
.proxy()
|
||||
.check_permissions(call, proxy_type);
|
||||
|
||||
// Submit the call and get back a result.
|
||||
let _is_call_allowed = api
|
||||
.view_functions()
|
||||
.at_latest()
|
||||
.await?
|
||||
.call(view_function_call)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[subxt_test]
|
||||
async fn call_view_function_dynamically() -> Result<(), subxt::Error> {
|
||||
let ctx = test_context().await;
|
||||
let api = ctx.client();
|
||||
let metadata = api.metadata();
|
||||
|
||||
let query_id = metadata
|
||||
.pallet_by_name("Proxy")
|
||||
.unwrap()
|
||||
.view_function_by_name("check_permissions")
|
||||
.unwrap()
|
||||
.query_id();
|
||||
|
||||
use scale_value::value;
|
||||
|
||||
let view_function_call = subxt::dynamic::view_function_call(
|
||||
*query_id,
|
||||
vec![value!(System(remark(b"hi".to_vec()))), value!(Any())],
|
||||
);
|
||||
|
||||
// Submit the call and get back a result.
|
||||
let _is_call_allowed = api
|
||||
.view_functions()
|
||||
.at_latest()
|
||||
.await?
|
||||
.call(view_function_call)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user