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: removed prelude and filtered entries. #29

Merged
merged 3 commits into from
Dec 9, 2024
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
5 changes: 3 additions & 2 deletions examples/account_key_pooling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
///
/// This is an example of how to use account key pooling to send multiple transactions
/// using different keys.
use near_api::prelude::*;
use near_api::*;
use near_token::NearToken;
use signer::generate_secret_key;

use std::sync::Arc;

Expand Down Expand Up @@ -42,7 +43,7 @@ async fn main() {
.unwrap();

let txs = (0..2).map(|_| {
Tokens::of(account.id().clone())
Tokens::account(account.id().clone())
.send_to(second_account.id().clone())
.near(NearToken::from_near(1))
.with_signer(Arc::clone(&signer))
Expand Down
12 changes: 6 additions & 6 deletions examples/create_account_and_send_near.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use near_account_id::AccountId;
use near_api::prelude::*;
use near_api::*;

use near_token::NearToken;
use signer::generate_secret_key;

#[tokio::main]
async fn main() {
let network = near_workspaces::sandbox().await.unwrap();
let account = network.dev_create_account().await.unwrap();
let network = NetworkConfig::from(network);

let balance = Tokens::of(account.id().clone())
let balance = Tokens::account(account.id().clone())
.near_balance()
.fetch_from(&network)
.await
Expand All @@ -29,20 +29,20 @@ async fn main() {
.await
.unwrap();

Tokens::of(account.id().clone())
Tokens::account(account.id().clone())
.send_to(new_account.clone())
.near(NearToken::from_near(1))
.with_signer(signer)
.send_to(&network)
.await
.unwrap();

let new_acccount_balance = Tokens::of(account.id().clone())
let new_acccount_balance = Tokens::account(account.id().clone())
.near_balance()
.fetch_from(&network)
.await
.unwrap();
let bob_balance = Tokens::of(new_account)
let bob_balance = Tokens::account(new_account)
.near_balance()
.fetch_from(&network)
.await
Expand Down
2 changes: 1 addition & 1 deletion examples/deploy_and_call_method.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_api::{prelude::*, types::Data};
use near_api::*;

#[tokio::main]
async fn main() {
Expand Down
12 changes: 6 additions & 6 deletions examples/ft.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_api::prelude::*;
use near_api::*;

use serde_json::json;

Expand Down Expand Up @@ -29,7 +29,7 @@ async fn main() {
.unwrap();

// Verifying that user has 1000 tokens
let tokens = Tokens::of(token.id().clone())
let tokens = Tokens::account(token.id().clone())
.ft_balance(token.id().clone())
.unwrap()
.fetch_from(&network)
Expand All @@ -40,7 +40,7 @@ async fn main() {

// Transfer 100 tokens to the account
// We handle internally the storage deposit for the receiver account
Tokens::of(token.id().clone())
Tokens::account(token.id().clone())
.send_to(account.id().clone())
.ft(
token.id().clone(),
Expand All @@ -54,7 +54,7 @@ async fn main() {
.unwrap()
.assert_success();

let tokens = Tokens::of(account.id().clone())
let tokens = Tokens::account(account.id().clone())
.ft_balance(token.id().clone())
.unwrap()
.fetch_from(&network)
Expand All @@ -63,7 +63,7 @@ async fn main() {

println!("Account has {}", tokens);

let tokens = Tokens::of(token.id().clone())
let tokens = Tokens::account(token.id().clone())
.ft_balance(token.id().clone())
.unwrap()
.fetch_from(&network)
Expand All @@ -73,7 +73,7 @@ async fn main() {
println!("Owner has {}", tokens);

// We validate decimals at the network level so this should fail with a validation error
let token = Tokens::of(token.id().clone())
let token = Tokens::account(token.id().clone())
.send_to(account.id().clone())
.ft(
token.id().clone(),
Expand Down
11 changes: 5 additions & 6 deletions examples/nft.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use near_api::prelude::*;
use near_api::*;

use near_contract_standards::non_fungible_token::metadata::TokenMetadata;
use near_token::NearToken;
use serde_json::json;

#[tokio::main]
Expand Down Expand Up @@ -55,7 +54,7 @@ async fn main() {
.unwrap();

// Verifying that account has our nft token
let tokens = Tokens::of(account.id().clone())
let tokens = Tokens::account(account.id().clone())
.nft_assets(nft.id().clone())
.unwrap()
.fetch_from(&network)
Expand All @@ -65,7 +64,7 @@ async fn main() {
assert_eq!(tokens.data.len(), 1);
println!("Account has {}", tokens.data.first().unwrap().token_id);

Tokens::of(account.id().clone())
Tokens::account(account.id().clone())
.send_to(nft.id().clone())
.nft(nft.id().clone(), "1".to_string())
.unwrap()
Expand All @@ -75,7 +74,7 @@ async fn main() {
.unwrap();

// Verifying that account doesn't have nft anymore
let tokens = Tokens::of(account.id().clone())
let tokens = Tokens::account(account.id().clone())
.nft_assets(nft.id().clone())
.unwrap()
.fetch_from(&network)
Expand All @@ -84,7 +83,7 @@ async fn main() {

assert!(tokens.data.is_empty());

let tokens = Tokens::of(nft.id().clone())
let tokens = Tokens::account(nft.id().clone())
.nft_assets(nft.id().clone())
.unwrap()
.fetch_from(&network)
Expand Down
3 changes: 2 additions & 1 deletion examples/sign_options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use near_api::prelude::*;
use near_api::*;
use near_crypto::SecretKey;
use near_primitives::account::AccessKeyPermission;
use signer::generate_seed_phrase;

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/specify_backup_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_api::{prelude::*, types::reference::Reference};
use near_api::*;

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/specifying_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_api::{prelude::*, types::reference::Reference};
use near_api::*;

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use url::Url;
use crate::{
common::send::Transactionable,
errors::{AccountCreationError, FaucetError, ValidationError},
prelude::*,
transactions::{ConstructTransaction, TransactionWithSign},
types::transactions::PrepopulateTransaction,
Contract, NetworkConfig,
};

#[derive(Clone, Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use near_primitives::types::BlockHeight;
const META_TRANSACTION_VALID_FOR_DEFAULT: BlockHeight = 1000;

pub mod query;
pub mod secret;
pub mod send;
pub mod signed_delegate_action;
pub mod utils;
70 changes: 0 additions & 70 deletions src/common/secret.rs

This file was deleted.

46 changes: 22 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@ mod stake;
mod storage;
mod tokens;
mod transactions;
// TODO: to be honest, there is almost nothing in this file
// we should maybe intergrate with them more tightly
// for now, i comment it out
// mod fastnear;

mod common;
mod fastnear;

pub mod errors;
pub mod signer;
pub mod types;

pub mod prelude {
pub use crate::{
account::Account,
chain::Chain,
common::secret::*,
config::{retry, NetworkConfig, RPCEndpoint, RetryResponse},
contract::Contract,
fastnear::FastNear,
signer::{Signer, SignerTrait},
stake::Delegation,
stake::Staking,
storage::StorageDeposit,
tokens::Tokens,
transactions::Transaction,
types::{
reference::{EpochReference, Reference},
tokens::{FTBalance, USDT_BALANCE, W_NEAR_BALANCE},
Data,
},
};
pub use crate::{
account::Account,
chain::Chain,
config::{NetworkConfig, RPCEndpoint},
contract::Contract,
signer::{Signer, SignerTrait},
stake::Staking,
storage::StorageDeposit,
tokens::Tokens,
transactions::Transaction,
types::{
reference::{EpochReference, Reference},
tokens::{FTBalance, USDT_BALANCE, W_NEAR_BALANCE},
Data,
},
};

pub use near_account_id::AccountId;
pub use near_token::NearToken;
}
pub use near_account_id::AccountId;
pub use near_token::NearToken;
Loading
Loading