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

Switch log signature to str from bytes #366

Merged
merged 21 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a1b9148
Switch log signature to str from bytes
austinabell Apr 20, 2021
bb568c7
fix(log): switch macro type to expr to make api less restrictive
austinabell Apr 20, 2021
d00ef07
Switch function signature to &str to remove potential code duplication
austinabell Apr 20, 2021
54252df
Merge branch 'master' into env/logsignature
austinabell Apr 23, 2021
4994c92
Merge branch 'master' of github.com:near/near-sdk-rs into env/logsign…
austinabell May 17, 2021
6af641c
Merge branch 'master' of github.com:near/near-sdk-rs into env/logsign…
austinabell Jun 4, 2021
ec98504
remove breaking change on function signature by adding log_str and up…
austinabell Jun 4, 2021
84f714b
fix equivalent doc example
austinabell Jun 4, 2021
f514ec0
fmt
austinabell Jun 4, 2021
844c3a6
Merge branch 'master' into env/logsignature
austinabell Jun 4, 2021
3bd7cb1
add print added to log_str also
austinabell Jun 4, 2021
2a37b9f
change log debug prints to std error instead of std out
austinabell Jun 10, 2021
a5c95b6
Merge branch 'master' into env/logsignature
mikedotexe Jun 21, 2021
d8d8109
Merge branch 'master' into env/logsignature
austinabell Jun 23, 2021
b695537
Merge branch 'master' into env/logsignature
austinabell Jun 29, 2021
2ca4858
Merge branch 'master' into env/logsignature
mikedotexe Jul 4, 2021
481d850
Merge branch 'master' of github.com:near/near-sdk-rs into env/logsign…
austinabell Jul 7, 2021
59216bc
Merge branch 'env/logsignature' of github.com:austinabell/near-sdk-rs…
austinabell Jul 7, 2021
2f0dd43
Merge branch 'master' into env/logsignature
austinabell Jul 13, 2021
80c8f08
Merge branch 'master' into env/logsignature
austinabell Jul 14, 2021
8473783
Merge branch 'master' into env/logsignature
austinabell Jul 15, 2021
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
14 changes: 7 additions & 7 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ There is an macro decorator `#[private]` that checks that the current account ID
impl Contract {
#[private]
pub fn resolve_transfer(&mut self) {
env::log(b"This is a callback");
env::log("This is a callback");
}
}
```
Expand All @@ -196,7 +196,7 @@ impl Contract {
if env::current_account_id() != env::predecessor_account_id() {
near_sdk::env::panic(b"Method resolve_transfer is private");
}
env::log(b"This is a callback");
env::log("This is a callback");
}
}
```
Expand Down Expand Up @@ -348,11 +348,11 @@ to receive attached deposits. Otherwise, if a deposit is attached to a non-payab
impl Contract {
#[payable]
pub fn take_my_money(&mut self) {
env::log(b"Thanks!");
env::log("Thanks!");
}

pub fn do_not_take_my_money(&mut self) {
env::log(b"Thanks!");
env::log("Thanks!");
}
}
```
Expand All @@ -363,14 +363,14 @@ This is equivalent to:
#[near_bindgen]
impl Contract {
pub fn take_my_money(&mut self) {
env::log(b"Thanks!");
env::log("Thanks!");
}

pub fn do_not_take_my_money(&mut self) {
if near_sdk::env::attached_deposit() != 0 {
near_sdk::env::panic(b"Method do_not_take_my_money doesn't accept deposit");
}
env::log(b"Thanks!");
env::log("Thanks!");
}
}
```
Expand Down Expand Up @@ -412,7 +412,7 @@ log!("Transferred {} tokens from {} to {}", amount, sender_id, receiver_id);
It's equivalent to the following message:

```rust
env::log(format!("Transferred {} tokens from {} to {}", amount, sender_id, receiver_id).as_bytes());
env::log(format!("Transferred {} tokens from {} to {}", amount, sender_id, receiver_id));
```

## Return `Promise`
Expand Down
2 changes: 1 addition & 1 deletion examples/cross-contract-low-level/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl CrossContract {
pub fn check_promise(&mut self) {
match env::promise_result(0) {
PromiseResult::Successful(_) => {
env::log(b"Check_promise successful");
env::log("Check_promise successful");
self.checked_promise = true;
}
_ => panic!("Promise with index 0 failed"),
Expand Down
16 changes: 7 additions & 9 deletions near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,15 +691,13 @@ pub fn panic(message: &[u8]) -> ! {
unreachable!()
}
/// Log the UTF-8 encodable message.
pub fn log(message: &[u8]) {
unsafe {
BLOCKCHAIN_INTERFACE.with(|b| {
b.borrow()
.as_ref()
.expect(BLOCKCHAIN_INTERFACE_NOT_SET_ERR)
.log_utf8(message.len() as _, message.as_ptr() as _)
})
}
pub fn log(message: &str) {
BLOCKCHAIN_INTERFACE.with(|b| unsafe {
b.borrow()
.as_ref()
.expect(BLOCKCHAIN_INTERFACE_NOT_SET_ERR)
.log_utf8(message.len() as _, message.as_ptr() as _)
})
}

// ###############
Expand Down
6 changes: 3 additions & 3 deletions near-sdk/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::{env, AccountId, PromiseResult};

#[macro_export]
macro_rules! log {
($arg:tt) => {
$crate::env::log($arg.as_bytes())
($arg:expr) => {
$crate::env::log($arg.as_ref())
};
($($arg:tt)*) => {
$crate::env::log(format!($($arg)*).as_bytes())
$crate::env::log(format!($($arg)*).as_str())
};
}

Expand Down