Skip to content
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

fix: interface module bindings #1219

Merged
merged 10 commits into from
Sep 13, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ use {{crate}}::{{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeywor
{{/propertyDeps.length}}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {}
pub struct {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
{{#isInterface}}uri: &'static str{{/isInterface}}
}

{{^isInterface}}
impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
pub const URI: &'static str = "{{uri}}";

Expand All @@ -51,3 +54,29 @@ impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
{{/last}}
{{/methods}}
}
{{/isInterface}}
{{#isInterface}}
impl {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
pub const INTERFACE_URI: &'static str = "{{uri}}";

pub fn new(uri: &'static str) -> {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} {
{{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}} { uri: uri }
}

{{#methods}}
pub fn {{#toLower}}{{name}}{{/toLower}}(&self, args: &Args{{#toUpper}}{{name}}{{/toUpper}}) -> Result<{{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}}, String> {
let uri = self.uri;
let args = serialize_{{#toLower}}{{name}}{{/toLower}}_args(args).map_err(|e| e.to_string())?;
let result = subinvoke::wrap_subinvoke(
uri,
"{{name}}",
args,
)?;
deserialize_{{#toLower}}{{name}}{{/toLower}}_result(result.as_slice()).map_err(|e| e.to_string())
}
{{^last}}

{{/last}}
{{/methods}}
}
{{/isInterface}}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ use crate::TestImportObject;
use crate::TestImportEnum;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct TestImportModule {}
pub struct TestImportModule {
uri: &'static str
}

impl TestImportModule {
pub const URI: &'static str = "testimport.uri.eth";
pub const INTERFACE_URI: &'static str = "testimport.uri.eth";

pub fn new() -> TestImportModule {
TestImportModule {}
pub fn new(uri: &'static str) -> TestImportModule {
TestImportModule { uri: uri }
}

pub fn imported_method(args: &ArgsImportedMethod) -> Result<Option<TestImportObject>, String> {
let uri = TestImportModule::URI;
pub fn imported_method(&self, args: &ArgsImportedMethod) -> Result<Option<TestImportObject>, String> {
let uri = self.uri;
let args = serialize_imported_method_args(args).map_err(|e| e.to_string())?;
let result = subinvoke::wrap_subinvoke(
uri,
Expand All @@ -42,8 +44,8 @@ impl TestImportModule {
deserialize_imported_method_result(result.as_slice()).map_err(|e| e.to_string())
}

pub fn another_method(args: &ArgsAnotherMethod) -> Result<i32, String> {
let uri = TestImportModule::URI;
pub fn another_method(&self, args: &ArgsAnotherMethod) -> Result<i32, String> {
let uri = self.uri;
let args = serialize_another_method_args(args).map_err(|e| e.to_string())?;
let result = subinvoke::wrap_subinvoke(
uri,
Expand Down