diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e098b796..b2bfd4a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,11 @@ ## [unreleased] - fix: Public keys can no longer be borsh deserialized from invalid bytes. [PR 502](https://github.com/near/near-sdk-rs/pull/502) - Adds `Hash` derive to `PublicKey` -* Update `panic` and `panic_utf8` syscall signatures to indicate they do not return. +- Update `panic` and `panic_utf8` syscall signatures to indicate they do not return. - Removes `PublicKey` generic on `env` promise batch calls. Functions now just take a reference to the `PublicKey`. +- Changes method name parameters from bytes (`Vec` and `&[u8]`) to string equivalents for batch function call promises [PR 515](https://github.com/near/near-sdk-rs/pull/515) + - `promise_batch_action_function_call`, `Promise::function_call`, `promise_batch_action_add_key_with_function_call`, `Promise::add_access_key`, and `Promise::add_access_key_with_nonce` are afffected. + - Instead of `b"method_name"` just use `"method_name"`, the bytes are enforced to be utf8 in the runtime. ## `4.0.0-pre.1` [07-23-2021] * Implements new `LazyOption` type under `unstable` feature. Similar to `Lazy` but is optional to set a value. [PR 444](https://github.com/near/near-sdk-rs/pull/444). diff --git a/HELP.md b/HELP.md index d6e370599..90e0a6495 100644 --- a/HELP.md +++ b/HELP.md @@ -457,8 +457,8 @@ mod ext_calculator { pub fn mult(a: U64, b: U64, receiver_id: &AccountId, deposit: Balance, gas: Gas) -> Promise { Promise::new(receiver_id.clone()) .function_call( - b"mult", - json!({ "a": a, "b": b }).to_string().as_bytes(), + "mult".to_string(), + json!({ "a": a, "b": b }).to_string().into_bytes(), deposit, gas, ) diff --git a/examples/cross-contract-high-level/res/cross_contract_high_level.wasm b/examples/cross-contract-high-level/res/cross_contract_high_level.wasm index 564ca464c..9ec4ab7a1 100755 Binary files a/examples/cross-contract-high-level/res/cross_contract_high_level.wasm and b/examples/cross-contract-high-level/res/cross_contract_high_level.wasm differ diff --git a/examples/fungible-token/res/defi.wasm b/examples/fungible-token/res/defi.wasm index f7e26fa88..796a0c92b 100755 Binary files a/examples/fungible-token/res/defi.wasm and b/examples/fungible-token/res/defi.wasm differ diff --git a/examples/fungible-token/res/fungible_token.wasm b/examples/fungible-token/res/fungible_token.wasm index 3591d1c07..0019ae9d1 100755 Binary files a/examples/fungible-token/res/fungible_token.wasm and b/examples/fungible-token/res/fungible_token.wasm differ diff --git a/examples/lockable-fungible-token/src/lib.rs b/examples/lockable-fungible-token/src/lib.rs index 37cbe71fc..fdced9931 100644 --- a/examples/lockable-fungible-token/src/lib.rs +++ b/examples/lockable-fungible-token/src/lib.rs @@ -256,7 +256,6 @@ impl FunToken { #[cfg(test)] mod tests { use near_sdk::test_utils::test_env::{alice, bob, carol}; - use near_sdk::MockedBlockchain; use near_sdk::{testing_env, VMContext}; use super::*; diff --git a/examples/non-fungible-token/res/approval_receiver.wasm b/examples/non-fungible-token/res/approval_receiver.wasm index cb9c2aa1e..51b2e47f7 100755 Binary files a/examples/non-fungible-token/res/approval_receiver.wasm and b/examples/non-fungible-token/res/approval_receiver.wasm differ diff --git a/examples/non-fungible-token/res/non_fungible_token.wasm b/examples/non-fungible-token/res/non_fungible_token.wasm index 7cbdbc01e..870a98cff 100755 Binary files a/examples/non-fungible-token/res/non_fungible_token.wasm and b/examples/non-fungible-token/res/non_fungible_token.wasm differ diff --git a/examples/non-fungible-token/res/token_receiver.wasm b/examples/non-fungible-token/res/token_receiver.wasm index b9637040a..be78f7ebe 100755 Binary files a/examples/non-fungible-token/res/token_receiver.wasm and b/examples/non-fungible-token/res/token_receiver.wasm differ diff --git a/examples/status-message-collections/src/lib.rs b/examples/status-message-collections/src/lib.rs index 436d94f35..8d4dd017d 100644 --- a/examples/status-message-collections/src/lib.rs +++ b/examples/status-message-collections/src/lib.rs @@ -43,7 +43,6 @@ impl StatusMessage { mod tests { use super::*; use near_sdk::test_utils::VMContextBuilder; - use near_sdk::MockedBlockchain; use near_sdk::{testing_env, VMContext}; use std::convert::TryInto; diff --git a/near-sdk-macros/src/core_impl/code_generator/item_trait_info.rs b/near-sdk-macros/src/core_impl/code_generator/item_trait_info.rs index a55976c82..731d11376 100644 --- a/near-sdk-macros/src/core_impl/code_generator/item_trait_info.rs +++ b/near-sdk-macros/src/core_impl/code_generator/item_trait_info.rs @@ -70,7 +70,7 @@ mod tests { let args = near_sdk::serde_json::to_vec(&args) .expect("Failed to serialize the cross contract args using JSON."); near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string())).function_call( - b"merge_sort".to_vec(), + "merge_sort".to_string(), args, __balance, __gas, @@ -79,7 +79,7 @@ mod tests { pub fn merge(__account_id: &T, __balance: near_sdk::Balance, __gas: near_sdk::Gas) -> near_sdk::Promise { let args = vec![]; near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string())).function_call( - b"merge".to_vec(), + "merge".to_string(), args, __balance, __gas, @@ -122,7 +122,7 @@ mod tests { let args = near_sdk::borsh::BorshSerialize::try_to_vec(&args) .expect("Failed to serialize the cross contract args using Borsh."); near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string())).function_call( - b"test".to_vec(), + "test".to_string(), args, __balance, __gas, diff --git a/near-sdk-macros/src/core_impl/code_generator/trait_item_method_info.rs b/near-sdk-macros/src/core_impl/code_generator/trait_item_method_info.rs index 1cc0c533d..8e9e0339b 100644 --- a/near-sdk-macros/src/core_impl/code_generator/trait_item_method_info.rs +++ b/near-sdk-macros/src/core_impl/code_generator/trait_item_method_info.rs @@ -20,7 +20,7 @@ impl TraitItemMethodInfo { #serialize near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string())) .function_call( - #ident_byte_str.to_vec(), + #ident_byte_str.to_string(), args, __balance, __gas, diff --git a/near-sdk-macros/src/core_impl/info_extractor/trait_item_method_info.rs b/near-sdk-macros/src/core_impl/info_extractor/trait_item_method_info.rs index 92c9d7a76..b1c95fdd2 100644 --- a/near-sdk-macros/src/core_impl/info_extractor/trait_item_method_info.rs +++ b/near-sdk-macros/src/core_impl/info_extractor/trait_item_method_info.rs @@ -1,7 +1,7 @@ use super::AttrSigInfo; use syn::export::Span; use syn::spanned::Spanned; -use syn::{Error, LitByteStr, TraitItemMethod}; +use syn::{Error, LitStr, TraitItemMethod}; /// Information extracted from trait method. pub struct TraitItemMethodInfo { @@ -9,8 +9,8 @@ pub struct TraitItemMethodInfo { pub attr_sig_info: AttrSigInfo, /// The original AST of the trait item method. pub original: TraitItemMethod, - /// Byte representation of method name, e.g. `b"my_method"`. - pub ident_byte_str: LitByteStr, + /// String representation of method name, e.g. `"my_method"`. + pub ident_byte_str: LitStr, } impl TraitItemMethodInfo { @@ -28,8 +28,7 @@ impl TraitItemMethodInfo { let attr_sig_info = AttrSigInfo::new(attrs, sig)?; - let ident_byte_str = - LitByteStr::new(attr_sig_info.ident.to_string().as_bytes(), Span::call_site()); + let ident_byte_str = LitStr::new(&attr_sig_info.ident.to_string(), Span::call_site()); Ok(Self { attr_sig_info, original: original.clone(), ident_byte_str }) } diff --git a/near-sdk/src/environment/env.rs b/near-sdk/src/environment/env.rs index 55c926cbf..79f4379ed 100644 --- a/near-sdk/src/environment/env.rs +++ b/near-sdk/src/environment/env.rs @@ -318,7 +318,7 @@ pub fn promise_batch_action_deploy_contract(promise_index: u64, code: &[u8]) { pub fn promise_batch_action_function_call( promise_index: PromiseIndex, - method_name: &[u8], + method_name: &str, arguments: &[u8], amount: Balance, gas: Gas, @@ -374,7 +374,7 @@ pub fn promise_batch_action_add_key_with_function_call( nonce: u64, allowance: Balance, receiver_id: &AccountId, - method_names: &[u8], + method_names: &str, ) { let receiver_id: &str = receiver_id.as_ref(); unsafe { diff --git a/near-sdk/src/promise.rs b/near-sdk/src/promise.rs index 804e44222..3197ce02e 100644 --- a/near-sdk/src/promise.rs +++ b/near-sdk/src/promise.rs @@ -12,7 +12,7 @@ pub enum PromiseAction { code: Vec, }, FunctionCall { - method_name: Vec, + method_name: String, arguments: Vec, amount: Balance, gas: Gas, @@ -32,7 +32,7 @@ pub enum PromiseAction { public_key: PublicKey, allowance: Balance, receiver_id: AccountId, - method_names: Vec, + method_names: String, nonce: u64, }, DeleteKey { @@ -242,7 +242,7 @@ impl Promise { /// A low-level interface for making a function call to the account that this promise acts on. pub fn function_call( self, - method_name: Vec, + method_name: String, arguments: Vec, amount: Balance, gas: Gas, @@ -272,13 +272,13 @@ impl Promise { /// Add an access key that is restricted to only calling a smart contract on some account using /// only a restricted set of methods. Here `method_names` is a comma separated list of methods, - /// e.g. `b"method_a,method_b"`. + /// e.g. `"method_a,method_b".to_string()`. pub fn add_access_key( self, public_key: PublicKey, allowance: Balance, receiver_id: AccountId, - method_names: Vec, + method_names: String, ) -> Self { self.add_access_key_with_nonce(public_key, allowance, receiver_id, method_names, 0) } @@ -289,7 +289,7 @@ impl Promise { public_key: PublicKey, allowance: Balance, receiver_id: AccountId, - method_names: Vec, + method_names: String, nonce: u64, ) -> Self { self.add_action(PromiseAction::AddAccessKey {