Skip to content

Commit

Permalink
refactor: Slimmed down the dependencies by default
Browse files Browse the repository at this point in the history
  • Loading branch information
frol committed Feb 22, 2024
1 parent 5999e12 commit 0c03763
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 174 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
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"
2 changes: 1 addition & 1 deletion examples/lockable-fungible-token/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" }
near-sdk = { path = "../../near-sdk", features = ["legacy"] }

[dev-dependencies]
anyhow = "1.0"
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
6 changes: 3 additions & 3 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 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
9 changes: 3 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,13 @@
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::json_types::Base64VecU8;
use near_sdk::require;
use near_sdk::schemars;
use near_sdk::{require, NearSchema};
use near_sdk::serde::{Deserialize, Serialize};

/// 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 +22,8 @@ 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, NearToken, NearSchema};

#[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
Loading

0 comments on commit 0c03763

Please sign in to comment.