Skip to content

Commit

Permalink
Change package name to near-sdk-contract-tools (near#109)
Browse files Browse the repository at this point in the history
* chore: change name

* chore: change repository details
  • Loading branch information
encody authored Dec 16, 2022
1 parent d404a6b commit 462edd1
Show file tree
Hide file tree
Showing 35 changed files with 116 additions and 116 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ categories = ["wasm", "cryptography::cryptocurrencies"]
description = """
Helpful functions and macros for developing smart contracts on NEAR Protocol.
"""
documentation = "https://docs.rs/near-contract-tools"
documentation = "https://docs.rs/near-sdk-contract-tools"
edition = "2021"
license = "GPL-3.0"
name = "near-contract-tools"
repository = "https://github.com/NEARFoundation/near-contract-tools"
name = "near-sdk-contract-tools"
repository = "https://github.com/NEARFoundation/near-sdk-contract-tools"
version = "0.7.2"

[dependencies]
near-contract-tools-macros = {version = "=0.7.2", path = "./macros"}
near-sdk = {version = "4.1.0", default-features = false}
near-sdk-contract-tools-macros = {version = "=0.7.2", path = "./macros"}
serde = "1.0.144"
serde_json = "1.0.85"
thiserror = "1.0.35"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# This package will be renamed to [`near-sdk-contract-tools`](https://crates.io/crates/near-sdk-contract-tools)

# near-contract-tools
# near-sdk-contract-tools

> Helpful functions and macros for developing smart contracts on NEAR Protocol.
Expand All @@ -17,15 +15,17 @@ Not to be confused with [`near-contract-standards`](https://crates.io/crates/nea

**WARNING:** This is still early software, and there may be breaking changes between versions. I'll try my best to keep the docs & changelogs up-to-date. Don't hesitate to create an issue if find anything wrong.

(Formerly known as [`near-contract-tools`](https://crates.io/crates/near-contract-tools).)

## Benefits

- requires fewer lines of code
- Without near-contract-tools, implementing fungible token events (mint, transfer, and burn) takes ~100 lines of code. Using near-contract-tools, you can [implement them in ~40 lines](https://youtu.be/kJzes_UP5j0?t=1058).
- Without near-sdk-contract-tools, implementing fungible token events (mint, transfer, and burn) takes ~100 lines of code. Using near-sdk-contract-tools, you can [implement them in ~40 lines](https://youtu.be/kJzes_UP5j0?t=1058).
- is more readable
- follows a consistent pattern
- Every time you use the events macro, it will [implement events in the same way](https://youtu.be/kJzes_UP5j0?t=1150). Without it, you’d need to ensure that `emit`, `emit_many`, etc all work (and work the same).
- is more thorough
- near-contract-standards is also not implementing traits, so that’s another improvement that near-contract-tools offers.
- near-contract-standards is also not implementing traits, so that’s another improvement that near-sdk-contract-tools offers.

You can think of this collection of common tools and patterns (mostly in the form of [derive macros](https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros)) as sort of an OpenZeppelin for NEAR.

Expand All @@ -34,7 +34,7 @@ You can think of this collection of common tools and patterns (mostly in the for
```text
rustup target add wasm32-unknown-unknown
cargo init
cargo add near-contract-tools
cargo add near-sdk-contract-tools
cargo add near-sdk
# https://raen.dev/guide/intro/getting-set-up.html
cargo install raen
Expand Down Expand Up @@ -80,7 +80,7 @@ See also: [the full integration tests](tests/macros/mod.rs).

```rust
use near_sdk::{near_bindgen, AccountId};
use near_contract_tools::{owner::Owner, Owner};
use near_sdk_contract_tools::{owner::Owner, Owner};

#[derive(Owner)]
#[near_bindgen]
Expand Down Expand Up @@ -124,7 +124,7 @@ fn own_accept_owner(&mut self);
The `#[event]` macro can be applied to structs or enums.

```rust
use near_contract_tools::{event, standard::nep297::Event};
use near_sdk_contract_tools::{event, standard::nep297::Event};

#[event(standard = "nft", version = "1.0.0")]
pub struct MintEvent {
Expand All @@ -146,7 +146,7 @@ e.emit();
To create a contract that is compatible with the NEP-141 and NEP-148 standards, that emits standard-compliant (NEP-141, NEP-297) events.

```rust
use near_contract_tools::FungibleToken;
use near_sdk_contract_tools::FungibleToken;
use near_sdk::near_bindgen;

#[derive(FungibleToken)]
Expand All @@ -169,7 +169,7 @@ Standalone macros for each individual standard also exist.
One may wish to combine the features of multiple macros in one contract. All of the macros are written such that they will work in a standalone manner, so this should largely work without issue. However, sometimes it may be desirable for the macros to work in _combination_ with each other. For example, to make a fungible token pausable, use the fungible token hooks to require that a contract be unpaused before making a token transfer:

```rust
use near_contract_tools::{
use near_sdk_contract_tools::{
pause::Pause,
standard::nep141::{Nep141Hook, Nep141Transfer},
FungibleToken, Pause,
Expand All @@ -192,13 +192,13 @@ Note: Hooks can be disabled using `#[nep141(no_hooks)]` or `#[fungible_token(no_

### Custom Crates

If you are a library developer, have modified a crate that one of the `near-contract-tools` macros uses (like `serde` or `near-sdk`), or are otherwise using a crate under a different name, you can specify crate names in macros like so:
If you are a library developer, have modified a crate that one of the `near-sdk-contract-tools` macros uses (like `serde` or `near-sdk`), or are otherwise using a crate under a different name, you can specify crate names in macros like so:

```rust, ignore
#[event(
// ...
crate = "near_contract_tools",
macros = "near_contract_tools_macros",
crate = "near_sdk_contract_tools",
macros = "near_sdk_contract_tools_macros",
serde = "serde",
)]
// ...
Expand Down
4 changes: 2 additions & 2 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
authors = ["Jacob Lindahl <[email protected]>"]
categories = ["wasm"]
description = """
Macros for `near-contract-tools`
Macros for `near-sdk-contract-tools`
"""
edition = "2021"
license = "GPL-3.0"
name = "near-contract-tools-macros"
name = "near-sdk-contract-tools-macros"
version = "0.7.2"

[dependencies]
Expand Down
8 changes: 4 additions & 4 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Macros for near-contract-tools
//! Macros for near-sdk-contract-tools
use darling::{FromDeriveInput, FromMeta};
use proc_macro::TokenStream;
Expand All @@ -14,11 +14,11 @@ mod standard;
mod upgrade;

fn default_crate_name() -> syn::Path {
syn::parse_str("::near_contract_tools").unwrap()
syn::parse_str("::near_sdk_contract_tools").unwrap()
}

fn default_macros() -> syn::Path {
syn::parse_str("::near_contract_tools").unwrap()
syn::parse_str("::near_sdk_contract_tools").unwrap()
}

fn default_near_sdk() -> syn::Path {
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn derive_rbac(input: TokenStream) -> TokenStream {

/// Adds NEP-141 fungible token core functionality to a contract. Exposes
/// `ft_*` functions to the public blockchain, implements internal controller
/// and receiver functionality (see: `near_contract_tools::standard::nep141`).
/// and receiver functionality (see: `near_sdk_contract_tools::standard::nep141`).
///
/// The storage key prefix for the fields can be optionally specified (default:
/// `"~$141"`) using `#[nep141(storage_key = "<expression>")]`.
Expand Down
2 changes: 1 addition & 1 deletion src/approval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ where

#[cfg(test)]
mod tests {
use near_contract_tools_macros::Rbac;
use near_sdk::{
borsh::{self, BorshDeserialize, BorshSerialize},
near_bindgen,
test_utils::VMContextBuilder,
testing_env, AccountId, BorshStorageKey,
};
use near_sdk_contract_tools_macros::Rbac;
use serde::Serialize;

use crate::{rbac::Rbac, slot::Slot};
Expand Down
2 changes: 1 addition & 1 deletion src/approval/simple_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ where
}
}

/// Types used by near-contract-tools-macros
/// Types used by near-sdk-contract-tools-macros
pub mod macro_types {
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ pub mod slot;
pub mod upgrade;
pub mod utils;

pub use near_contract_tools_macros::*;
use near_sdk::IntoStorageKey;
pub use near_sdk_contract_tools_macros::*;
4 changes: 2 additions & 2 deletions src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
//! method takes this state and replaces it with the new schema.
//! [`MigrateExternal`] exposes this functionality publicly.
//!
//! The crate exports a [derive macro](near_contract_tools_macros::Migrate)
//! The crate exports a [derive macro](near_sdk_contract_tools_macros::Migrate)
//! that derives a default implementation for migration.
//!
//! Note: [`MigrateHook`] must be implemented by the user and is not derived
//! by default. It must convert data in the old schema to the new schema without
//! failing. For a complete example checkout [upgrade_new.rs](https://github.com/NEARFoundation/near-contract-tools/blob/develop/workspaces-tests/src/bin/upgrade_new.rs)
//! failing. For a complete example checkout [upgrade_new.rs](https://github.com/NEARFoundation/near-sdk-contract-tools/blob/develop/workspaces-tests/src/bin/upgrade_new.rs)
//! in workspace-tests.
//!
//! # Safety
Expand Down
10 changes: 5 additions & 5 deletions src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!
//! The pattern consists of methods in [`Owner`] and [`OwnerExternal`]. The
//! latter exposes methods externally and can be called by other contracts.
//! This [derive macro](near_contract_tools_macros::Owner)
//! This [derive macro](near_sdk_contract_tools_macros::Owner)
//! derives default implementation both these traits.
//!
//! # Safety
Expand All @@ -32,11 +32,11 @@
//! respective [`Owner`] methods and expect the same invariants.
#![allow(missing_docs)] // #[ext_contract(...)] does not play nicely with clippy

use near_contract_tools_macros::event;
use near_sdk::{
borsh::{self, BorshSerialize},
env, ext_contract, require, AccountId, BorshStorageKey,
};
use near_sdk_contract_tools_macros::event;

use crate::{slot::Slot, standard::nep297::Event, DefaultStorageKey};

Expand All @@ -51,7 +51,7 @@ const NO_PROPOSED_OWNER_FAIL_MESSAGE: &str = "No proposed owner";
standard = "x-own",
version = "1.0.0",
crate = "crate",
macros = "near_contract_tools_macros"
macros = "near_sdk_contract_tools_macros"
)]
#[derive(Debug, Clone)]
pub enum OwnerEvent {
Expand Down Expand Up @@ -160,7 +160,7 @@ pub trait Owner {
///
/// ```
/// use near_sdk::{AccountId, near_bindgen};
/// use near_contract_tools::{Owner, owner::Owner};
/// use near_sdk_contract_tools::{Owner, owner::Owner};
///
/// #[derive(Owner)]
/// #[near_bindgen]
Expand Down Expand Up @@ -199,7 +199,7 @@ pub trait Owner {
///
/// ```
/// use near_sdk::{AccountId, near_bindgen};
/// use near_contract_tools::{Owner, owner::Owner};
/// use near_sdk_contract_tools::{Owner, owner::Owner};
///
/// #[derive(Owner)]
/// #[near_bindgen]
Expand Down
8 changes: 4 additions & 4 deletions src/pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! is emitted. A contract starts off as "unpaused" by default. [`PauseExternal`]
//! exposes an external function to check the status of the contract.
//!
//! This [derive macro](near_contract_tools_macros::Pause)
//! This [derive macro](near_sdk_contract_tools_macros::Pause)
//! derives a default implementation for both these traits.
//!
//! # Safety
Expand All @@ -24,8 +24,8 @@
#![allow(missing_docs)] // #[ext_contract(...)] does not play nicely with clippy

use crate::{slot::Slot, standard::nep297::Event, DefaultStorageKey};
use near_contract_tools_macros::event;
use near_sdk::{ext_contract, require};
use near_sdk_contract_tools_macros::event;

const UNPAUSED_FAIL_MESSAGE: &str = "Disallowed while contract is unpaused";
const PAUSED_FAIL_MESSAGE: &str = "Disallowed while contract is paused";
Expand All @@ -35,7 +35,7 @@ const PAUSED_FAIL_MESSAGE: &str = "Disallowed while contract is paused";
standard = "x-paus",
version = "1.0.0",
crate = "crate",
macros = "near_contract_tools_macros"
macros = "near_sdk_contract_tools_macros"
)]
#[derive(Debug, Clone)]
pub enum PauseEvent {
Expand All @@ -51,7 +51,7 @@ pub enum PauseEvent {
///
/// ```
/// use near_sdk::near_bindgen;
/// use near_contract_tools::{pause::Pause, Pause};
/// use near_sdk_contract_tools::{pause::Pause, Pause};
///
/// #[derive(Pause)]
/// #[near_bindgen]
Expand Down
6 changes: 3 additions & 3 deletions src/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
//! or prohibit a particular role. Typically, these are used to guard access to
//! external functions exposed by the contract.
//!
//! This [derive macro](near_contract_tools_macros::Rbac) derives
//! This [derive macro](near_sdk_contract_tools_macros::Rbac) derives
//! a default implementation for RBAC. For a complete example check out
//! [`counter_multisig.rs`](https://github.com/NEARFoundation/near-contract-tools/blob/develop/workspaces-tests/src/bin/counter_multisig.rs)
//! [`counter_multisig.rs`](https://github.com/NEARFoundation/near-sdk-contract-tools/blob/develop/workspaces-tests/src/bin/counter_multisig.rs)
//! in workspace-tests directory.
//!
//! # Safety
Expand Down Expand Up @@ -183,13 +183,13 @@ impl ExactSizeIterator for Iter {}

#[cfg(test)]
mod tests {
use near_contract_tools_macros::Rbac;
use near_sdk::{
borsh::{self, BorshSerialize},
near_bindgen,
test_utils::VMContextBuilder,
testing_env, AccountId, BorshStorageKey,
};
use near_sdk_contract_tools_macros::Rbac;

use super::Rbac;

Expand Down
2 changes: 1 addition & 1 deletion src/standard/nep141.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//! <https://github.com/near/NEPs/blob/master/neps/nep-0141.md>
#![allow(missing_docs)] // ext_contract doesn't play nice with #![warn(missing_docs)]

use near_contract_tools_macros::event;
use near_sdk::{
borsh::{self, BorshDeserialize, BorshSerialize},
env, ext_contract,
json_types::U128,
require, AccountId, BorshStorageKey, Gas, Promise, PromiseOrValue, PromiseResult,
};
use near_sdk_contract_tools_macros::event;
use serde::{Deserialize, Serialize};

use crate::{slot::Slot, standard::nep297::*, DefaultStorageKey};
Expand Down
6 changes: 3 additions & 3 deletions src/standard/nep297.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Helpers for `#[derive(near_contract_tools::Nep297)]`
//! Helpers for `#[derive(near_sdk_contract_tools::Nep297)]`
use near_sdk::serde::Serialize;

Expand All @@ -9,7 +9,7 @@ use near_sdk::serde::Serialize;
/// ## Normal events
///
/// ```
/// use near_contract_tools::event;
/// use near_sdk_contract_tools::event;
///
/// #[event(standard = "nft", version = "1.0.0")]
/// pub struct MintEvent {
Expand All @@ -22,7 +22,7 @@ use near_sdk::serde::Serialize;
/// token_id: "token_1".to_string(),
/// };
///
/// use near_contract_tools::standard::nep297::Event;
/// use near_sdk_contract_tools::standard::nep297::Event;
///
/// e.emit();
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use near_sdk::{env, require, Promise};
/// # Examples
///
/// ```
/// use near_contract_tools::utils::prefix_key;
/// use near_sdk_contract_tools::utils::prefix_key;
///
/// assert_eq!(prefix_key(b"p", b"key"), b"pkey".to_vec());
/// ```
Expand All @@ -22,7 +22,7 @@ pub fn prefix_key(prefix: &dyn AsRef<[u8]>, key: &dyn AsRef<[u8]>) -> Vec<u8> {
/// # Examples
///
/// ```
/// use near_contract_tools::utils::apply_storage_fee_and_refund;
/// use near_sdk_contract_tools::utils::apply_storage_fee_and_refund;
///
/// let initial_storage_usage = near_sdk::env::storage_usage();
/// let additional_fees = 0;
Expand Down
8 changes: 4 additions & 4 deletions tests/macros/event.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use near_contract_tools::standard::nep297::{Event, ToEventLog};
use near_sdk_contract_tools::standard::nep297::{Event, ToEventLog};

use crate::macros::event::test_events::Nep171NftMintData;

mod test_events {
use near_contract_tools::Nep297;
use near_sdk_contract_tools::Nep297;
use serde::Serialize;

#[derive(Serialize)]
Expand Down Expand Up @@ -110,10 +110,10 @@ fn derive_event() {
}

mod event_attribute_macro {
use near_contract_tools::{event, standard::nep297::Event};
use near_sdk_contract_tools::{event, standard::nep297::Event};

mod my_event {
use near_contract_tools::event;
use near_sdk_contract_tools::event;

#[event(standard = "my_event_standard", version = "1")]
pub struct One;
Expand Down
Loading

0 comments on commit 462edd1

Please sign in to comment.