Skip to content

Commit

Permalink
refactor: Slimmed down the dependencies by default (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
frol authored Feb 23, 2024
1 parent 5999e12 commit c157688
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 199 deletions.
2 changes: 1 addition & 1 deletion examples/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../near-sdk", features = ["unstable"] }
near-sdk = { path = "../../near-sdk" }

[dev-dependencies]
near-workspaces = { version = "0.9.0", default-features = false, features = ["install"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dev-dependencies]
anyhow = "1.0"
near-sdk = { path = "../../near-sdk" }
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
tokio = { version = "1.14", features = ["full"] }
near-workspaces = { version = "0.9.0", default-features = false, features = ["install"] }

Expand Down
1 change: 0 additions & 1 deletion examples/fungible-token/ft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ crate-type = ["cdylib"]
[dependencies]
near-sdk = { path = "../../../near-sdk" }
near-contract-standards = { path = "../../../near-contract-standards" }
schemars = "0.8"
3 changes: 2 additions & 1 deletion examples/lockable-fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
near-sdk = { path = "../../near-sdk" }
near-sdk = { path = "../../near-sdk", features = ["legacy"] }

[dev-dependencies]
anyhow = "1.0"
tokio = { version = "1.14", features = ["full"] }
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }
near-workspaces = { version = "0.9.0", default-features = false, features = ["install"] }

[profile.release]
Expand Down
3 changes: 3 additions & 0 deletions examples/mission-control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ crate-type = ["cdylib"]
[dependencies]
near-sdk = { path = "../../near-sdk" }

[dev-dependencies]
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }

[profile.release]
codegen-units = 1
# Tell `rustc` to optimize for small code size.
Expand Down
18 changes: 9 additions & 9 deletions examples/mission-control/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::asset::*;
use crate::rate::*;
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::schemars::JsonSchema;
use near_sdk::serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::ops;

use near_sdk::NearSchema;
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::serde::{Deserialize, Serialize};

use crate::asset::*;
use crate::rate::*;

#[derive(
PartialEq,
Eq,
Expand All @@ -18,17 +20,15 @@ use std::ops;
Debug,
BorshDeserialize,
BorshSerialize,
JsonSchema,
NearSchema,
)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[schemars(crate = "near_sdk::schemars")]
pub struct Quantity(pub i32);

#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize, JsonSchema)]
#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize, NearSchema)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[schemars(crate = "near_sdk::schemars")]
pub struct Account(pub HashMap<Asset, Quantity>);

pub enum Tranx {
Expand Down
14 changes: 5 additions & 9 deletions examples/mission-control/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use near_sdk::NearSchema;
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::schemars::JsonSchema;
use near_sdk::serde::{Deserialize, Serialize};

#[derive(
Expand All @@ -14,11 +14,10 @@ use near_sdk::serde::{Deserialize, Serialize};
Deserialize,
BorshDeserialize,
BorshSerialize,
JsonSchema,
NearSchema,
)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[schemars(crate = "near_sdk::schemars")]
pub enum Resource {
Battery,
RgbSensor,
Expand All @@ -38,11 +37,10 @@ pub enum Resource {
Deserialize,
BorshDeserialize,
BorshSerialize,
JsonSchema,
NearSchema,
)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[schemars(crate = "near_sdk::schemars")]
pub enum Reward {
Score,
Token,
Expand All @@ -63,11 +61,10 @@ pub enum Reward {
Deserialize,
BorshDeserialize,
BorshSerialize,
JsonSchema,
NearSchema,
)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[schemars(crate = "near_sdk::schemars")]
pub enum Asset {
Resource(Resource),
Reward(Reward),
Expand All @@ -85,11 +82,10 @@ pub enum Asset {
Ord,
BorshDeserialize,
BorshSerialize,
JsonSchema,
NearSchema
)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[schemars(crate = "near_sdk::schemars")]
pub enum Exchange {
MissionTimeWithResource,
MissionTimeWithTrust,
Expand Down
3 changes: 3 additions & 0 deletions examples/status-message/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ crate-type = ["cdylib"]
[dependencies]
near-sdk = { path = "../../near-sdk" }

[dev-dependencies]
near-sdk = { path = "../../near-sdk", features = ["unit-testing"] }

[profile.release]
codegen-units = 1
# Tell `rustc` to optimize for small code size.
Expand Down
14 changes: 9 additions & 5 deletions examples/status-message/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::collections::LookupMap;
use near_sdk::store::LookupMap;
use near_sdk::{env, log, near_bindgen, AccountId, BorshStorageKey};

#[derive(BorshSerialize, BorshStorageKey)]
Expand All @@ -25,10 +25,10 @@ impl StatusMessage {
pub fn set_status(&mut self, message: String) {
let account_id = env::signer_account_id();
log!("{} set_status with message {}", account_id, message);
self.records.insert(&account_id, &message);
self.records.insert(account_id, message);
}

pub fn get_status(&self, account_id: AccountId) -> Option<String> {
pub fn get_status(&self, account_id: AccountId) -> Option<&String> {
log!("get_status for account_id {}", account_id);
self.records.get(&account_id)
}
Expand All @@ -54,11 +54,15 @@ mod tests {
testing_env!(context);
let mut contract = StatusMessage::default();
contract.set_status("hello".to_string());
// Flush the pending changes to avoid panic in the view method below due to the pending non-commited changes to the `store::LookupMap`:
// HostError(ProhibitedInView { method_name: "storage_write" })
contract.records.flush();
assert_eq!(get_logs(), vec!["bob_near set_status with message hello"]);

let context = get_context(true);
testing_env!(context);
assert_eq!("hello".to_string(), contract.get_status("bob_near".parse().unwrap()).unwrap());
assert_eq!(get_logs(), vec!["get_status for account_id bob_near"])
assert_eq!("hello", contract.get_status("bob_near".parse().unwrap()).unwrap());
assert_eq!(get_logs(), vec!["get_status for account_id bob_near"]);
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion near-contract-standards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ NEAR smart contracts standard library.
[dependencies]
near-sdk = { path = "../near-sdk", version = "~5.0.0-alpha.3", default-features = false, features = ["legacy"] }

[dev-dependencies]
near-sdk = { path = "../near-sdk", default-features = false, features = ["unit-testing"] }

[features]
default = ["abi"]
default = []
abi = ["near-sdk/abi"]
6 changes: 2 additions & 4 deletions near-contract-standards/src/fungible_token/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::json_types::Base64VecU8;
use near_sdk::schemars;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::{ext_contract, require};
use near_sdk::{ext_contract, require, NearSchema};

pub const FT_METADATA_SPEC: &str = "ft-1.0.0";

#[derive(BorshDeserialize, BorshSerialize, Clone, Deserialize, Serialize)]
#[derive(Clone, BorshDeserialize, BorshSerialize, Deserialize, Serialize, NearSchema)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))]
pub struct FungibleTokenMetadata {
pub spec: String,
pub name: String,
Expand Down
28 changes: 22 additions & 6 deletions near-contract-standards/src/non_fungible_token/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::json_types::Base64VecU8;
use near_sdk::require;
use near_sdk::schemars;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::{require, NearSchema};

/// This spec can be treated like a version of the standard.
pub const NFT_METADATA_SPEC: &str = "nft-1.0.0";

/// Metadata for the NFT contract itself.
#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
BorshDeserialize,
BorshSerialize,
Serialize,
Deserialize,
NearSchema,
)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
pub struct NFTContractMetadata {
Expand All @@ -24,9 +32,17 @@ pub struct NFTContractMetadata {

/// Metadata on the individual token level.
#[derive(
Debug, Clone, Serialize, Deserialize, PartialEq, Eq, BorshDeserialize, BorshSerialize, Default,
Debug,
Clone,
Default,
PartialEq,
Eq,
Serialize,
Deserialize,
BorshDeserialize,
BorshSerialize,
NearSchema,
)]
#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
pub struct TokenMetadata {
Expand Down
6 changes: 2 additions & 4 deletions near-contract-standards/src/non_fungible_token/token.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::non_fungible_token::metadata::TokenMetadata;
use near_sdk::schemars;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::AccountId;
use near_sdk::{AccountId, NearSchema};
use std::collections::HashMap;
/// Note that token IDs for NFTs are strings on NEAR. It's still fine to use autoincrementing numbers as unique IDs if desired, but they should be stringified. This is to make IDs more future-proof as chain-agnostic conventions and standards arise, and allows for more flexibility with considerations like bridging NFTs across chains, etc.
pub type TokenId = String;

/// In this implementation, the Token struct takes two extensions standards (metadata and approval) as optional fields, as they are frequently used in modern NFTs.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, NearSchema)]
#[serde(crate = "near_sdk::serde")]
pub struct Token {
pub token_id: TokenId,
Expand Down
10 changes: 4 additions & 6 deletions near-contract-standards/src/storage_management/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::schemars;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::{AccountId, NearToken};
#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize)]
use near_sdk::{AccountId, NearSchema, NearToken};

#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, NearSchema)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))]
pub struct StorageBalance {
pub total: NearToken,
pub available: NearToken,
}

#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize)]
#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, NearSchema)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))]
pub struct StorageBalanceBounds {
pub min: NearToken,
pub max: Option<NearToken>,
Expand Down
14 changes: 7 additions & 7 deletions near-sdk-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Main macro of the library for writing NEAR smart contracts.
proc-macro = true

[dependencies]
proc-macro2 = "1"
syn = { version = "2", features = ["full", "fold", "extra-traits", "visit"] }
strum = "0.24"
strum_macros = "0.24"
quote = "1.0"
proc-macro2 = { version = "1", default-features = false }
syn = { version = "2", default-features = false }
strum = { version = "0.26", default-features = false }
strum_macros = "0.26"
quote = { version = "1.0", default-features = false }
Inflector = { version = "0.11.4", default-features = false, features = [] }
darling = { version = "0.20.3" }
serde = { version = "1", features = ["derive"] }
darling = { version = "0.20.3", default-features = false }
serde = { version = "1", default-features = false, features = ["serde_derive"] }
serde_json = "1"

[dev-dependencies]
Expand Down
Loading

0 comments on commit c157688

Please sign in to comment.