Skip to content

Commit

Permalink
chore: reverted own-type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn committed Nov 19, 2024
1 parent cd99c1a commit d33f288
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 520 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ url = { version = "2", features = ["serde"] }
tokio = { version = "1.0", default-features = false, features = ["time"] }
tracing = "0.1"
bs58 = "0.4"
serde_with = "3.11"
derive_more = "0.99"

thiserror = "1"

Expand Down
2 changes: 1 addition & 1 deletion examples/account_key_pooling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() {
);

let (key, tx) = Account(account.id().clone())
.add_key(near_api::types::views::AccessKeyPermission::FullAccess)
.add_key(near_primitives::account::AccessKeyPermission::FullAccess)
.new_keypair()
.generate_secret_key()
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion examples/sign_options.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use near_api::{prelude::*, types::views::AccessKeyPermission};
use near_api::prelude::*;
use near_crypto::SecretKey;
use near_primitives::account::AccessKeyPermission;

#[tokio::main]
async fn main() {
Expand Down
3 changes: 2 additions & 1 deletion src/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::convert::Infallible;

use near_crypto::PublicKey;
use near_gas::NearGas;
use near_primitives::types::AccountId;
use near_token::NearToken;
use reqwest::Response;
use serde_json::json;
Expand All @@ -12,7 +13,7 @@ use crate::{
errors::{AccountCreationError, FaucetError, ValidationError},
prelude::*,
transactions::{ConstructTransaction, TransactionWithSign},
types::{transactions::PrepopulateTransaction, AccountId},
types::transactions::PrepopulateTransaction,
};

#[derive(Clone, Debug)]
Expand Down
7 changes: 3 additions & 4 deletions src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::convert::Infallible;

use near_crypto::PublicKey;
use near_primitives::{
account::AccessKey,
account::{AccessKey, AccessKeyPermission},
action::{AddKeyAction, DeleteKeyAction},
types::BlockReference,
types::{AccountId, BlockReference},
};

use crate::common::{
Expand All @@ -15,7 +15,6 @@ use crate::common::{
secret::SecretBuilder,
};
use crate::transactions::ConstructTransaction;
use crate::types::{views::AccessKeyPermission, AccountId};

use self::create::CreateAccountBuilder;

Expand Down Expand Up @@ -70,7 +69,7 @@ impl Account {
near_primitives::transaction::Action::AddKey(Box::new(AddKeyAction {
access_key: AccessKey {
nonce: 0,
permission: permission.into(),
permission,
},
public_key,
})),
Expand Down
17 changes: 13 additions & 4 deletions src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use near_primitives::types::{BlockHeight, BlockReference};
use near_primitives::{
types::{BlockHeight, BlockReference},
views::BlockView,
};

use crate::{
common::query::{BlockQueryBuilder, PostprocessHandler, RpcBlockHandler, SimpleBlockRpc},
types::{views::Block, CryptoHash},
types::CryptoHash,
};

#[derive(Debug, Clone, Copy)]
Expand All @@ -13,15 +16,21 @@ impl Chain {
BlockQueryBuilder::new(
SimpleBlockRpc,
BlockReference::latest(),
PostprocessHandler::new(RpcBlockHandler, Box::new(|data: Block| data.header.height)),
PostprocessHandler::new(
RpcBlockHandler,
Box::new(|data: BlockView| data.header.height),
),
)
}

pub fn block_hash() -> BlockQueryBuilder<PostprocessHandler<CryptoHash, RpcBlockHandler>> {
BlockQueryBuilder::new(
SimpleBlockRpc,
BlockReference::latest(),
PostprocessHandler::new(RpcBlockHandler, Box::new(|data: Block| data.header.hash)),
PostprocessHandler::new(
RpcBlockHandler,
Box::new(|data: BlockView| data.header.hash.into()),
),
)
}

Expand Down
42 changes: 16 additions & 26 deletions src/common/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@ use near_jsonrpc_client::methods::{
validators::RpcValidatorRequest,
RpcMethod,
};
use near_primitives::views::QueryRequest;
use near_primitives::{
types::{BlockReference, EpochReference},
views::{BlockView, EpochValidatorInfo},
views::{
AccessKeyList, AccessKeyView, AccountView, BlockView, ContractCodeView, EpochValidatorInfo,
QueryRequest, ViewStateResult,
},
};
use serde::de::DeserializeOwned;
use tracing::{debug, error, info, instrument, trace, warn};

use crate::{
common::utils::retry,
config::NetworkConfig,
errors::QueryError,
types::{
views::{AccessKey, AccessKeyList, Account, Block, ContractCode, ViewStateResult},
Data,
},
};
use crate::{common::utils::retry, config::NetworkConfig, errors::QueryError, types::Data};

const QUERY_EXECUTOR_TARGET: &str = "near_api::query::executor";

Expand Down Expand Up @@ -489,7 +483,7 @@ pub struct AccountViewHandler;

impl ResponseHandler for AccountViewHandler {
type QueryResponse = RpcQueryResponse;
type Response = Data<Account>;
type Response = Data<AccountView>;
type Method = RpcQueryRequest;

fn process_response(
Expand All @@ -510,7 +504,7 @@ impl ResponseHandler for AccountViewHandler {
account.amount, account.locked
);
Ok(Data {
data: account.into(),
data: account,
block_height: response.block_height,
block_hash: response.block_hash.into(),
})
Expand All @@ -528,7 +522,7 @@ impl ResponseHandler for AccountViewHandler {
pub struct AccessKeyListHandler;

impl ResponseHandler for AccessKeyListHandler {
type Response = Data<AccessKeyList>;
type Response = AccessKeyList;
type QueryResponse = RpcQueryResponse;
type Method = RpcQueryRequest;

Expand All @@ -549,11 +543,7 @@ impl ResponseHandler for AccessKeyListHandler {
"Processed AccessKeyList response, keys count: {}",
access_key_list.keys.len()
);
Ok(Data {
data: access_key_list.into(),
block_height: response.block_height,
block_hash: response.block_hash.into(),
})
Ok(access_key_list)
} else {
warn!(target: QUERY_EXECUTOR_TARGET, "Unexpected response kind: {:?}", response.kind);
Err(QueryError::UnexpectedResponse {
Expand All @@ -568,7 +558,7 @@ impl ResponseHandler for AccessKeyListHandler {
pub struct AccessKeyHandler;

impl ResponseHandler for AccessKeyHandler {
type Response = Data<AccessKey>;
type Response = Data<AccessKeyView>;
type QueryResponse = RpcQueryResponse;
type Method = RpcQueryRequest;

Expand All @@ -590,7 +580,7 @@ impl ResponseHandler for AccessKeyHandler {
key.permission
);
Ok(Data {
data: key.into(),
data: key,
block_height: response.block_height,
block_hash: response.block_hash.into(),
})
Expand Down Expand Up @@ -630,7 +620,7 @@ impl ResponseHandler for ViewStateHandler {
data.proof.len()
);
Ok(Data {
data: data.into(),
data,
block_height: response.block_height,
block_hash: response.block_hash.into(),
})
Expand All @@ -648,7 +638,7 @@ impl ResponseHandler for ViewStateHandler {
pub struct ViewCodeHandler;

impl ResponseHandler for ViewCodeHandler {
type Response = Data<ContractCode>;
type Response = Data<ContractCodeView>;
type QueryResponse = RpcQueryResponse;
type Method = RpcQueryRequest;

Expand All @@ -670,7 +660,7 @@ impl ResponseHandler for ViewCodeHandler {
code.hash
);
Ok(Data {
data: code.into(),
data: code,
block_height: response.block_height,
block_hash: response.block_hash.into(),
})
Expand Down Expand Up @@ -715,7 +705,7 @@ impl ResponseHandler for RpcValidatorHandler {
pub struct RpcBlockHandler;

impl ResponseHandler for RpcBlockHandler {
type Response = Block;
type Response = BlockView;
type QueryResponse = BlockView;
type Method = RpcBlockRequest;

Expand All @@ -734,7 +724,7 @@ impl ResponseHandler for RpcBlockHandler {
response.header.height,
response.header.hash
);
Ok(response.into())
Ok(response)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/signed_delegate_action.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use borsh::{self, BorshDeserialize};
use near_primitives::{borsh, borsh::BorshDeserialize};

#[derive(Debug, Clone)]
pub struct SignedDelegateActionAsBase64 {
Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pub struct NetworkConfig {
pub rpc_url: url::Url,
pub rpc_api_key: Option<crate::types::ApiKey>,
// https://github.com/near/near-cli-rs/issues/116
pub linkdrop_account_id: Option<crate::types::AccountId>,
pub linkdrop_account_id: Option<near_primitives::types::AccountId>,
// https://docs.near.org/social/contract
pub near_social_db_contract_account_id: Option<crate::types::AccountId>,
pub near_social_db_contract_account_id: Option<near_primitives::types::AccountId>,
pub faucet_url: Option<url::Url>,
pub meta_transaction_relayer_url: Option<url::Url>,
pub fastnear_url: Option<url::Url>,
pub staking_pools_factory_account_id: Option<crate::types::AccountId>,
pub staking_pools_factory_account_id: Option<near_primitives::types::AccountId>,
}

impl NetworkConfig {
Expand Down
4 changes: 2 additions & 2 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use near_gas::NearGas;

use near_primitives::{
action::{Action, DeployContractAction, FunctionCallAction},
types::{BlockReference, StoreKey},
types::{AccountId, BlockReference, StoreKey},
};
use near_token::NearToken;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
Expand All @@ -20,7 +20,7 @@ use crate::{
errors::BuilderError,
signer::Signer,
transactions::{ConstructTransaction, Transaction},
types::{contract::ContractSourceMetadata, AccountId, Data},
types::{contract::ContractSourceMetadata, Data},
};

#[derive(Clone, Debug)]
Expand Down
5 changes: 3 additions & 2 deletions src/fastnear.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::collections::BTreeSet;

use near_primitives::types::AccountId;
use serde::de::DeserializeOwned;

use crate::errors::FastNearError;
use crate::types::AccountId;

#[derive(Debug, serde::Deserialize)]
pub struct StakingPool {
pool_id: AccountId,
pool_id: near_primitives::types::AccountId,
}

#[derive(Debug, serde::Deserialize)]
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ pub mod prelude {
types::{
reference::{EpochReference, Reference},
tokens::{FTBalance, USDT_BALANCE, W_NEAR_BALANCE},
AccountId, Data, NearGas, NearToken,
Data,
},
};

pub use near_account_id::AccountId;
pub use near_token::NearToken;
}
13 changes: 7 additions & 6 deletions src/signer/keystore.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use near_crypto::{PublicKey, SecretKey};
use near_primitives::{transaction::Transaction, types::Nonce};
use near_primitives::{
transaction::Transaction,
types::{AccountId, Nonce},
views::AccessKeyPermissionView,
};
use tracing::{debug, info, instrument, trace, warn};

use crate::{
config::NetworkConfig,
errors::{KeyStoreError, SignerError},
types::{
transactions::PrepopulateTransaction, views::AccessKeyPermission, AccountId, CryptoHash,
},
types::{transactions::PrepopulateTransaction, CryptoHash},
};

use super::{AccountKeyPair, SignerTrait};
Expand Down Expand Up @@ -86,11 +88,10 @@ impl KeystoreSigner {

debug!(target: KEYSTORE_SIGNER_TARGET, "Filtering and collecting potential public keys");
let potential_pubkeys: Vec<PublicKey> = account_keys
.data
.keys
.into_iter()
// TODO: support functional access keys
.filter(|key| key.access_key.permission == AccessKeyPermission::FullAccess)
.filter(|key| key.access_key.permission == AccessKeyPermissionView::FullAccess)
.flat_map(|key| {
Self::get_secret_key(&account_id, &key.public_key, &network.network_name)
.map(|keypair| keypair.public_key)
Expand Down
4 changes: 2 additions & 2 deletions src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeMap;

use near_gas::NearGas;
use near_jsonrpc_client::methods::query::RpcQueryRequest;
use near_primitives::types::{BlockReference, EpochReference};
use near_primitives::types::{AccountId, BlockReference, EpochReference};
use near_token::NearToken;

use crate::{
Expand All @@ -16,7 +16,7 @@ use crate::{
transactions::ConstructTransaction,
types::{
stake::{RewardFeeFraction, StakingPoolInfo, UserStakeBalance},
AccountId, Data,
Data,
},
};

Expand Down
3 changes: 2 additions & 1 deletion src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use near_primitives::types::AccountId;
use near_token::NearToken;
use serde_json::json;

Expand All @@ -6,7 +7,7 @@ use crate::{
contract::{Contract, ContractTransactBuilder},
errors::BuilderError,
transactions::ConstructTransaction,
types::{storage::StorageBalance, AccountId},
types::storage::StorageBalance,
};

#[derive(Clone, Debug)]
Expand Down
Loading

0 comments on commit d33f288

Please sign in to comment.