Skip to content

Commit

Permalink
fix(env): Update method name parameters in env to string equivalents (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
austinabell committed Aug 5, 2021
1 parent 1160a64 commit 0c953e1
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 22 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>` 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).
Expand Down
4 changes: 2 additions & 2 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Binary file not shown.
Binary file modified examples/fungible-token/res/defi.wasm
Binary file not shown.
Binary file modified examples/fungible-token/res/fungible_token.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion examples/lockable-fungible-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
Binary file modified examples/non-fungible-token/res/approval_receiver.wasm
Binary file not shown.
Binary file modified examples/non-fungible-token/res/non_fungible_token.wasm
Binary file not shown.
Binary file modified examples/non-fungible-token/res/token_receiver.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion examples/status-message-collections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -79,7 +79,7 @@ mod tests {
pub fn merge<T: ToString>(__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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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 {
/// Attributes and signature information.
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 {
Expand All @@ -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 })
}
Expand Down
4 changes: 2 additions & 2 deletions near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions near-sdk/src/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum PromiseAction {
code: Vec<u8>,
},
FunctionCall {
method_name: Vec<u8>,
method_name: String,
arguments: Vec<u8>,
amount: Balance,
gas: Gas,
Expand All @@ -32,7 +32,7 @@ pub enum PromiseAction {
public_key: PublicKey,
allowance: Balance,
receiver_id: AccountId,
method_names: Vec<u8>,
method_names: String,
nonce: u64,
},
DeleteKey {
Expand Down Expand Up @@ -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<u8>,
method_name: String,
arguments: Vec<u8>,
amount: Balance,
gas: Gas,
Expand Down Expand Up @@ -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<u8>,
method_names: String,
) -> Self {
self.add_access_key_with_nonce(public_key, allowance, receiver_id, method_names, 0)
}
Expand All @@ -289,7 +289,7 @@ impl Promise {
public_key: PublicKey,
allowance: Balance,
receiver_id: AccountId,
method_names: Vec<u8>,
method_names: String,
nonce: u64,
) -> Self {
self.add_action(PromiseAction::AddAccessKey {
Expand Down

0 comments on commit 0c953e1

Please sign in to comment.