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

chore: use near-abi 0.3.0 #954

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions examples/adder/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workspaces = "0.5.0"
serde_json = "1.0"
tokio = { version = "1.14", features = ["full"] }
anyhow = "1.0"
near-abi = "0.1.0-pre.0"
near-abi = { version = "0.3.0", features = ["__chunked-entries"] }
itegulov marked this conversation as resolved.
Show resolved Hide resolved
zstd = "0.11"

[profile.release]
Expand Down
12 changes: 6 additions & 6 deletions examples/fungible-token/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 23 additions & 11 deletions near-sdk-macros/src/core_impl/abi/abi_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,27 @@ impl ImplItemMethodInfo {
Some(doc) => quote! { Some(#doc.to_string()) },
None => quote! { None },
};
let is_view = matches!(&self.attr_signature_info.method_type, &MethodType::View);
let is_init = matches!(
&self.attr_signature_info.method_type,
&MethodType::Init | &MethodType::InitIgnoreState
);
let AttrSigInfo { is_payable, is_private, is_handles_result, .. } =
self.attr_signature_info;
let mut modifiers = vec![];
let kind = match &self.attr_signature_info.method_type {
&MethodType::View => quote! { near_sdk::__private::AbiFunctionKind::View },
&MethodType::Regular => {
quote! { near_sdk::__private::AbiFunctionKind::Call }
Comment on lines +93 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth noting for clarity that until #890 is merged, the ABI will represent self-less functions as call functions. Meaning clients will think they have to send signed transactions and not simply making view calls. Then again, I don't have any stats on how often these are used or if at all, so it might be a trivial nit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that is also the current behavior, so doesn't have to do anything with this particular change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

}
&MethodType::Init | &MethodType::InitIgnoreState => {
modifiers.push(quote! { near_sdk::__private::AbiFunctionModifier::Init });
quote! { near_sdk::__private::AbiFunctionKind::Call }
}
};
if self.attr_signature_info.is_payable {
modifiers.push(quote! { near_sdk::__private::AbiFunctionModifier::Payable });
}
if self.attr_signature_info.is_private {
modifiers.push(quote! { near_sdk::__private::AbiFunctionModifier::Private });
}
let modifiers = quote! {
vec![#(#modifiers),*]
};
let AttrSigInfo { is_handles_result, .. } = self.attr_signature_info;

let mut params = Vec::<TokenStream2>::new();
let mut callbacks = Vec::<TokenStream2>::new();
Expand Down Expand Up @@ -220,10 +234,8 @@ impl ImplItemMethodInfo {
near_sdk::__private::AbiFunction {
name: #function_name_str.to_string(),
doc: #function_doc,
is_view: #is_view,
is_init: #is_init,
is_payable: #is_payable,
is_private: #is_private,
kind: #kind,
modifiers: #modifiers,
params: #params,
callbacks: vec![#(#callbacks),*],
callbacks_vec: #callback_vec,
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wee_alloc = { version = "0.4.5", default-features = false, optional = true }
# Used for caching, might be worth porting only functionality needed.
once_cell = { version = "1.8", default-features = false }

near-abi = { version = "0.2.0", features = ["__chunked-entries"], optional = true }
near-abi = { version = "0.3.0", features = ["__chunked-entries"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# alt_bn128 feature will need to be removed on the next version update (now stabilized)
Expand Down
5 changes: 4 additions & 1 deletion near-sdk/src/private/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#[cfg(feature = "abi")]
pub use near_abi::__private::ChunkedAbiEntry;
#[cfg(feature = "abi")]
pub use near_abi::{AbiBorshParameter, AbiFunction, AbiJsonParameter, AbiParameters, AbiType};
pub use near_abi::{
AbiBorshParameter, AbiFunction, AbiFunctionKind, AbiFunctionModifier, AbiJsonParameter,
AbiParameters, AbiType,
};

#[cfg(feature = "abi")]
pub use schemars;
Expand Down