Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jun 6, 2024
2 parents b3bd35c + 289d75f commit 148133c
Show file tree
Hide file tree
Showing 35 changed files with 174 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,4 @@ The minimum supported Rust version is currently `1.72`. There are no guarantees

## Contributing

If you are interested in contributing, please look at the [contributing guidelines](CONTRIBUTING.md).
If you are interested in contributing, please look at the [contributing guidelines](https://github.com/near/near-sdk-rs/blob/master/CONTRIBUTING.md).
2 changes: 1 addition & 1 deletion examples/fungible-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Fungible Token (FT)

Example implementation of a [Fungible Token] contract which uses [near-contract-standards].

[Fungible Token]: https://nomicon.io/Standards/Tokens/FungibleTokenCore.html
[Fungible Token]: https://nomicon.io/Standards/Tokens/FungibleToken
[near-contract-standards]: https://github.com/near/near-sdk-rs/tree/master/near-contract-standards

NOTES:
Expand Down
4 changes: 2 additions & 2 deletions examples/non-fungible-token/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Non-fungible Token (NFT)
===================

Example implementation of a [non-fungible token] contract which uses [near-contract-standards].
Example implementation of a [Non-Fungible Token] contract which uses [near-contract-standards].

[non-fungible token]: https://nomicon.io/Standards/NonFungibleToken/README.html
[Non-Fungible Token]: https://nomicon.io/Standards/NonFungibleToken
[near-contract-standards]: https://github.com/near/near-sdk-rs/tree/master/near-contract-standards

NOTES:
Expand Down
12 changes: 6 additions & 6 deletions near-sdk-macros/src/core_impl/abi/abi_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ mod tests {
#[handle_result]
pub fn f3(&mut self, arg0: FancyStruct, arg1: u64) -> Result<IsOk, Error> { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = method_info.abi_struct();

local_insta_assert_snapshot!(pretty_print_fn_body_syn_str(actual));
Expand All @@ -339,7 +339,7 @@ mod tests {
#[handle_result]
pub fn f3(&mut self, #[serializer(borsh)] arg0: FancyStruct) -> Result<IsOk, Error> { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = method_info.abi_struct();

local_insta_assert_snapshot!(pretty_print_fn_body_syn_str(actual));
Expand All @@ -355,7 +355,7 @@ mod tests {
#[callback_vec] x: Vec<String>,
) -> bool { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = method_info.abi_struct();

local_insta_assert_snapshot!(pretty_print_fn_body_syn_str(actual));
Expand All @@ -367,7 +367,7 @@ mod tests {
let mut method = parse_quote! {
pub fn method(&self, #[callback_unwrap] #[serializer(borsh)] x: &mut u64, #[serializer(borsh)] y: String, #[callback_unwrap] #[serializer(json)] z: Vec<u8>) { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = method_info.abi_struct();

local_insta_assert_snapshot!(pretty_print_fn_body_syn_str(actual));
Expand All @@ -380,7 +380,7 @@ mod tests {
#[init(ignore_state)]
pub fn new() -> u64 { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = method_info.abi_struct();

local_insta_assert_snapshot!(pretty_print_fn_body_syn_str(actual));
Expand All @@ -392,7 +392,7 @@ mod tests {
let mut method = parse_quote! {
pub fn method() { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = method_info.abi_struct();

local_insta_assert_snapshot!(pretty_print_fn_body_syn_str(actual));
Expand Down
6 changes: 3 additions & 3 deletions near-sdk-macros/src/core_impl/code_generator/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod tests {
#[warn(unused)]
pub fn method(&self) { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = generate_ext_function(&method_info.attr_signature_info);

local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap());
Expand All @@ -189,7 +189,7 @@ mod tests {
let mut method: ImplItemFn = parse_quote! {
pub fn method(&self, k: &String) { }
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = generate_ext_function(&method_info.attr_signature_info);

local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap());
Expand All @@ -201,7 +201,7 @@ mod tests {
let mut method: syn::ImplItemFn = parse_quote! {
pub fn borsh_test(&mut self, #[serializer(borsh)] a: String) {}
};
let method_info = ImplItemMethodInfo::new(&mut method, false, impl_type).unwrap().unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, None, impl_type).unwrap().unwrap();
let actual = generate_ext_function(&method_info.attr_signature_info);

local_insta_assert_snapshot!(pretty_print_syn_str(&actual).unwrap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,24 +277,41 @@ impl ImplItemMethodInfo {

let ident = &self.attr_signature_info.ident;
let arg_list = self.attr_signature_info.arg_list();
let struct_type = &self.struct_type;

let method_invocation = || {
let method_fqdn = if let Some(impl_trait) = &self.impl_trait {
quote! {
contract.#ident(#arg_list)
<#struct_type as #impl_trait>::#ident
}
} else {
quote! {
#struct_type::#ident
}
};

let method_invocation = |receiver: &Receiver| {
if receiver.reference.is_some() {
let mutability = receiver.mutability;
quote! {
#method_fqdn(&#mutability contract, #arg_list)
}
} else {
quote! {
#method_fqdn(contract, #arg_list)
}
}
};

let static_invocation = || {
let struct_type = &self.struct_type;
quote! {
#struct_type::#ident(#arg_list)
#method_fqdn(#arg_list)
}
};

match &self.attr_signature_info.method_kind {
Call(call_method) => {
if call_method.receiver.is_some() {
method_invocation()
if let Some(receiver) = call_method.receiver.as_ref() {
method_invocation(receiver)
} else {
static_invocation()
}
Expand All @@ -304,8 +321,8 @@ impl ImplItemMethodInfo {
Init(_) => quote! {},

View(view_method) => {
if view_method.receiver.is_some() {
method_invocation()
if let Some(receiver) = view_method.receiver.as_ref() {
method_invocation(receiver)
} else {
static_invocation()
}
Expand Down
Loading

0 comments on commit 148133c

Please sign in to comment.