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: deprecate block_index and replace with block_height #474

Merged
merged 6 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* This type will have `ValidAccountId`'s JSON (de)serialization and the borsh serialization will be equivalent to what it was previously
* Initializes default for `BLOCKCHAIN_INTERFACE` to avoid requiring to initialize testing environment for tests that don't require custom blockchain interface configuration
* This default only affects outside of `wasm32` environments and is optional/backwards compatible
* Deprecates `env::block_index` and replaces it with `env::block_height` for more consistent naming
* Makes `BLOCKCHAIN_INTERFACE` a concrete type and no longer exports it.
* If for testing you need this mocked blockchain, `near_sdk::mock::with_mocked_blockchain` can be used
* `near_sdk::env::take_blockchain_interface` is removed, as this interface is no longer optional
Expand Down
8 changes: 7 additions & 1 deletion near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ pub fn input() -> Option<Vec<u8>> {
}

/// Current block index.
#[deprecated(since = "4.0.0", note = "Use block_height instead")]
Copy link
Contributor

Choose a reason for hiding this comment

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

perfect

pub fn block_index() -> BlockHeight {
unsafe { sys::block_index() }
block_height()
}

/// Returns the height of the block the transaction is being executed in.
pub fn block_height() -> BlockHeight {
unsafe { sys::block_height() }
}

/// Current block timestamp, i.e, number of non-leap-nanoseconds since January 1, 1970 0:00:00 UTC.
Expand Down
5 changes: 5 additions & 0 deletions near-sdk/src/environment/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,8 @@ extern "C" {
pub fn validator_stake(account_id_len: u64, account_id_ptr: u64, stake_ptr: u64);
pub fn validator_total_stake(stake_ptr: u64);
}

#[inline]
pub unsafe fn block_height() -> u64 {
block_index()
}