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

refactor: Re-exported packages cleanup #1114

Merged
merged 8 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 1 deletion examples/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ crate-type = ["cdylib"]

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

[dev-dependencies]
near-workspaces = { version = "0.9.0", default-features = false, features = ["install"] }
Expand Down
4 changes: 0 additions & 4 deletions near-contract-standards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ NEAR smart contracts standard library.

[dependencies]
near-sdk = { path = "../near-sdk", version = "~5.0.0-alpha.1", default-features = false, features = ["legacy"] }
serde = "1"
serde_json = "1"
schemars = "0.8"
near-account-id = {version="1.0.0-alpha.3", features = ["abi", "serde", "borsh", "schemars"]}

[features]
default = ["abi"]
Expand Down
4 changes: 3 additions & 1 deletion near-contract-standards/src/contract_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use serde::{Deserialize, Serialize};
use near_sdk::serde::{Deserialize, Serialize};

/// The contract source metadata is a standard interface that allows auditing and viewing source code for a deployed smart contract.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct ContractSourceMetadata {
pub version: Option<String>,
pub link: Option<String>,
pub standards: Vec<Standard>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct Standard {
pub standard: String,
pub version: String,
Expand Down
4 changes: 3 additions & 1 deletion near-contract-standards/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use near_sdk::env;
use serde::Serialize;
use near_sdk::serde::Serialize;
use near_sdk::serde_json;

#[derive(Serialize, Debug)]
#[serde(crate = "near_sdk::serde")]
#[serde(tag = "standard")]
#[must_use = "don't forget to `.emit()` this event"]
#[serde(rename_all = "snake_case")]
Expand Down
7 changes: 6 additions & 1 deletion near-contract-standards/src/fungible_token/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

use crate::event::NearEvent;
use near_sdk::json_types::U128;
use near_sdk::serde::Serialize;
use near_sdk::AccountIdRef;
use serde::Serialize;

/// Data to log for an FT mint event. To log this event, call [`.emit()`](FtMint::emit).
#[must_use]
#[derive(Serialize, Debug, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct FtMint<'a> {
pub owner_id: &'a AccountIdRef,
pub amount: U128,
Expand All @@ -46,6 +47,7 @@ impl FtMint<'_> {
/// call [`.emit()`](FtTransfer::emit).
#[must_use]
#[derive(Serialize, Debug, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct FtTransfer<'a> {
pub old_owner_id: &'a AccountIdRef,
pub new_owner_id: &'a AccountIdRef,
Expand All @@ -71,6 +73,7 @@ impl FtTransfer<'_> {
/// Data to log for an FT burn event. To log this event, call [`.emit()`](FtBurn::emit).
#[must_use]
#[derive(Serialize, Debug, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct FtBurn<'a> {
pub owner_id: &'a AccountIdRef,
pub amount: U128,
Expand All @@ -93,13 +96,15 @@ impl FtBurn<'_> {
}

#[derive(Serialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub(crate) struct Nep141Event<'a> {
version: &'static str,
#[serde(flatten)]
event_kind: Nep141EventKind<'a>,
}

#[derive(Serialize, Debug)]
#[serde(crate = "near_sdk::serde")]
#[serde(tag = "event", content = "data")]
#[serde(rename_all = "snake_case")]
#[allow(clippy::enum_variant_names)]
Expand Down
1 change: 1 addition & 0 deletions near-contract-standards/src/fungible_token/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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};

Expand Down
7 changes: 6 additions & 1 deletion near-contract-standards/src/non_fungible_token/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
//! or [`NftBurn::emit_many`] respectively.

use crate::event::NearEvent;
use near_sdk::serde::Serialize;
use near_sdk::AccountIdRef;
use serde::Serialize;

/// Data to log for an NFT mint event. To log this event, call [`.emit()`](NftMint::emit).
#[must_use]
#[derive(Serialize, Debug, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct NftMint<'a> {
pub owner_id: &'a AccountIdRef,
pub token_ids: &'a [&'a str],
Expand All @@ -45,6 +46,7 @@ impl NftMint<'_> {
/// call [`.emit()`](NftTransfer::emit).
#[must_use]
#[derive(Serialize, Debug, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct NftTransfer<'a> {
pub old_owner_id: &'a AccountIdRef,
pub new_owner_id: &'a AccountIdRef,
Expand Down Expand Up @@ -72,6 +74,7 @@ impl NftTransfer<'_> {
/// Data to log for an NFT burn event. To log this event, call [`.emit()`](NftBurn::emit).
#[must_use]
#[derive(Serialize, Debug, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct NftBurn<'a> {
pub owner_id: &'a AccountIdRef,
pub token_ids: &'a [&'a str],
Expand All @@ -96,13 +99,15 @@ impl NftBurn<'_> {
}

#[derive(Serialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub(crate) struct Nep171Event<'a> {
version: &'static str,
#[serde(flatten)]
event_kind: Nep171EventKind<'a>,
}

#[derive(Serialize, Debug)]
#[serde(crate = "near_sdk::serde")]
#[serde(tag = "event", content = "data")]
#[serde(rename_all = "snake_case")]
#[allow(clippy::enum_variant_names)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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};

/// This spec can be treated like a version of the standard.
Expand Down
2 changes: 1 addition & 1 deletion near-contract-standards/src/non_fungible_token/token.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::non_fungible_token::metadata::TokenMetadata;
use near_sdk::schemars;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::AccountId;
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;

Expand Down
2 changes: 1 addition & 1 deletion near-contract-standards/src/storage_management/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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)]
#[serde(crate = "near_sdk::serde")]
#[borsh(crate = "near_sdk::borsh")]
Expand Down
40 changes: 20 additions & 20 deletions near-sdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,23 +368,25 @@ pub fn derive_near_schema(input: TokenStream) -> TokenStream {
}
}

// <unspecified> or #[abi(json)]
let json_schema = json_schema || !borsh_schema;

let derive = match (json_schema, borsh_schema) {
// <unspecified> or #[abi(json)]
(_, false) => quote! {
#[derive(schemars::JsonSchema)]
},
// #[abi(borsh)]
(false, true) => quote! {
#[derive(::near_sdk::borsh::BorshSchema)]
#[borsh(crate = "::near_sdk::borsh")]
},
// #[abi(json, borsh)]
(true, true) => quote! {
#[derive(schemars::JsonSchema, ::near_sdk::borsh::BorshSchema)]
#[borsh(crate = "::near_sdk::borsh")]
},
let derive = {
let mut derive = quote! {};
if borsh_schema {
derive = quote! {
#[derive(::near_sdk::borsh::BorshSchema)]
#[borsh(crate = "::near_sdk::borsh")]
};
}
if json_schema {
derive = quote! {
#derive
#[derive(::near_sdk::schemars::JsonSchema)]
#[schemars(crate = "::near_sdk::schemars")]
};
}
derive
};

let input_ident = &input.ident;
Expand All @@ -394,13 +396,13 @@ pub fn derive_near_schema(input: TokenStream) -> TokenStream {
let json_impl = if json_schema {
quote! {
#[automatically_derived]
impl schemars::JsonSchema for #input_ident_proxy {
impl ::near_sdk::schemars::JsonSchema for #input_ident_proxy {
fn schema_name() -> ::std::string::String {
stringify!(#input_ident).to_string()
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
<#input_ident as schemars::JsonSchema>::json_schema(gen)
fn json_schema(gen: &mut ::near_sdk::schemars::gen::SchemaGenerator) -> ::near_sdk::schemars::schema::Schema {
<#input_ident as ::near_sdk::schemars::JsonSchema>::json_schema(gen)
}
}
}
Expand Down Expand Up @@ -436,8 +438,6 @@ pub fn derive_near_schema(input: TokenStream) -> TokenStream {
#[allow(non_camel_case_types)]
type #input_ident_proxy = #input_ident;
{
use ::near_sdk::__private::schemars;

#derive
#input

Expand Down
8 changes: 4 additions & 4 deletions near-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ wee_alloc = { version = "0.4.5", default-features = false, optional = true }
once_cell = { version = "1.17", default-features = false }

near-abi = { version = "0.4.0", features = ["__chunked-entries"], optional = true }
near-gas = { version = "0.2.3", features = ["serde", "borsh", "schemars"] }
near-token = { version = "0.2.0", features = ["serde", "borsh", "schemars"] }
near-account-id = {version="1.0.0-alpha.3", features = ["abi", "serde", "borsh", "schemars"]}
near-account-id = { version="1.0.0-alpha.4", features = ["serde", "borsh"] }
near-gas = { version = "0.2.3", features = ["serde", "borsh"] }
near-token = { version = "0.2.0", features = ["serde", "borsh"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
near-vm-logic = { version = "0.17", optional = true }
Expand All @@ -62,7 +62,7 @@ default = ["wee_alloc", "unit-testing", "legacy", "abi"]
expensive-debug = []
unstable = []
legacy = []
abi = ["borsh/unstable__schema", "near-abi", "schemars", "near-sdk-macros/abi"]
abi = ["borsh/unstable__schema", "near-abi", "schemars", "near-sdk-macros/abi", "near-account-id/abi", "near-gas/abi", "near-token/abi"]
unit-testing = ["near-vm-logic", "near-primitives-core", "near-primitives", "near-crypto"]

__abi-embed = ["near-sdk-macros/__abi-embed"]
Expand Down
Loading
Loading