diff --git a/Cargo.lock b/Cargo.lock index c2f0df1..5976966 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1684,7 +1684,6 @@ dependencies = [ "bip39", "borsh", "bs58 0.4.0", - "derive_more", "ed25519-dalek", "futures", "keyring", @@ -1705,7 +1704,6 @@ dependencies = [ "reqwest", "serde", "serde_json", - "serde_with", "slipped10", "thiserror", "tokio", diff --git a/Cargo.toml b/Cargo.toml index fd3a046..cdf3ce0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/examples/account_key_pooling.rs b/examples/account_key_pooling.rs index 5bc7d86..be776cc 100644 --- a/examples/account_key_pooling.rs +++ b/examples/account_key_pooling.rs @@ -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(); diff --git a/examples/sign_options.rs b/examples/sign_options.rs index 04954f8..1d92879 100644 --- a/examples/sign_options.rs +++ b/examples/sign_options.rs @@ -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() { diff --git a/src/account/create.rs b/src/account/create.rs index 216c642..8a749d5 100644 --- a/src/account/create.rs +++ b/src/account/create.rs @@ -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; @@ -12,7 +13,7 @@ use crate::{ errors::{AccountCreationError, FaucetError, ValidationError}, prelude::*, transactions::{ConstructTransaction, TransactionWithSign}, - types::{transactions::PrepopulateTransaction, AccountId}, + types::transactions::PrepopulateTransaction, }; #[derive(Clone, Debug)] diff --git a/src/account/mod.rs b/src/account/mod.rs index 08054e8..42e151b 100644 --- a/src/account/mod.rs +++ b/src/account/mod.rs @@ -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::{ @@ -15,7 +15,6 @@ use crate::common::{ secret::SecretBuilder, }; use crate::transactions::ConstructTransaction; -use crate::types::{views::AccessKeyPermission, AccountId}; use self::create::CreateAccountBuilder; @@ -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, })), diff --git a/src/chain.rs b/src/chain.rs index 85a8aa2..7034b7e 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -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)] @@ -13,7 +16,10 @@ 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), + ), ) } @@ -21,7 +27,10 @@ impl Chain { 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()), + ), ) } diff --git a/src/common/query.rs b/src/common/query.rs index 6536b44..a49d4ed 100644 --- a/src/common/query.rs +++ b/src/common/query.rs @@ -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"; @@ -489,7 +483,7 @@ pub struct AccountViewHandler; impl ResponseHandler for AccountViewHandler { type QueryResponse = RpcQueryResponse; - type Response = Data; + type Response = Data; type Method = RpcQueryRequest; fn process_response( @@ -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(), }) @@ -528,7 +522,7 @@ impl ResponseHandler for AccountViewHandler { pub struct AccessKeyListHandler; impl ResponseHandler for AccessKeyListHandler { - type Response = Data; + type Response = AccessKeyList; type QueryResponse = RpcQueryResponse; type Method = RpcQueryRequest; @@ -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 { @@ -568,7 +558,7 @@ impl ResponseHandler for AccessKeyListHandler { pub struct AccessKeyHandler; impl ResponseHandler for AccessKeyHandler { - type Response = Data; + type Response = Data; type QueryResponse = RpcQueryResponse; type Method = RpcQueryRequest; @@ -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(), }) @@ -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(), }) @@ -648,7 +638,7 @@ impl ResponseHandler for ViewStateHandler { pub struct ViewCodeHandler; impl ResponseHandler for ViewCodeHandler { - type Response = Data; + type Response = Data; type QueryResponse = RpcQueryResponse; type Method = RpcQueryRequest; @@ -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(), }) @@ -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; @@ -734,7 +724,7 @@ impl ResponseHandler for RpcBlockHandler { response.header.height, response.header.hash ); - Ok(response.into()) + Ok(response) } } diff --git a/src/common/signed_delegate_action.rs b/src/common/signed_delegate_action.rs index 9854e41..3bc0711 100644 --- a/src/common/signed_delegate_action.rs +++ b/src/common/signed_delegate_action.rs @@ -1,4 +1,4 @@ -use borsh::{self, BorshDeserialize}; +use near_primitives::{borsh, borsh::BorshDeserialize}; #[derive(Debug, Clone)] pub struct SignedDelegateActionAsBase64 { diff --git a/src/config.rs b/src/config.rs index 72f872b..34c4352 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,13 +4,13 @@ pub struct NetworkConfig { pub rpc_url: url::Url, pub rpc_api_key: Option, // https://github.com/near/near-cli-rs/issues/116 - pub linkdrop_account_id: Option, + pub linkdrop_account_id: Option, // https://docs.near.org/social/contract - pub near_social_db_contract_account_id: Option, + pub near_social_db_contract_account_id: Option, pub faucet_url: Option, pub meta_transaction_relayer_url: Option, pub fastnear_url: Option, - pub staking_pools_factory_account_id: Option, + pub staking_pools_factory_account_id: Option, } impl NetworkConfig { diff --git a/src/contract.rs b/src/contract.rs index 82dc2b0..b8e7759 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -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}; @@ -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)] diff --git a/src/fastnear.rs b/src/fastnear.rs index 09b42e4..d0631f1 100644 --- a/src/fastnear.rs +++ b/src/fastnear.rs @@ -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)] diff --git a/src/lib.rs b/src/lib.rs index 3af90f5..e88ec6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; } diff --git a/src/signer/keystore.rs b/src/signer/keystore.rs index 38616b7..9a702d8 100644 --- a/src/signer/keystore.rs +++ b/src/signer/keystore.rs @@ -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}; @@ -86,11 +88,10 @@ impl KeystoreSigner { debug!(target: KEYSTORE_SIGNER_TARGET, "Filtering and collecting potential public keys"); let potential_pubkeys: Vec = 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) diff --git a/src/stake.rs b/src/stake.rs index ed26ced..decddbc 100644 --- a/src/stake.rs +++ b/src/stake.rs @@ -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::{ @@ -16,7 +16,7 @@ use crate::{ transactions::ConstructTransaction, types::{ stake::{RewardFeeFraction, StakingPoolInfo, UserStakeBalance}, - AccountId, Data, + Data, }, }; diff --git a/src/storage.rs b/src/storage.rs index 4180789..f6a3d88 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1,3 +1,4 @@ +use near_primitives::types::AccountId; use near_token::NearToken; use serde_json::json; @@ -6,7 +7,7 @@ use crate::{ contract::{Contract, ContractTransactBuilder}, errors::BuilderError, transactions::ConstructTransaction, - types::{storage::StorageBalance, AccountId}, + types::storage::StorageBalance, }; #[derive(Clone, Debug)] diff --git a/src/tokens.rs b/src/tokens.rs index 357a813..f02953f 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -6,7 +6,8 @@ use near_contract_standards::{ }; use near_primitives::{ action::{Action, TransferAction}, - types::BlockReference, + types::{AccountId, BlockReference}, + views::AccountView, }; use near_sdk::json_types::U128; use near_token::NearToken; @@ -27,8 +28,7 @@ use crate::{ types::{ tokens::{FTBalance, UserBalance}, transactions::PrepopulateTransaction, - views::Account, - AccountId, Data, + Data, }, }; @@ -56,7 +56,7 @@ impl Tokens { BlockReference::latest(), PostprocessHandler::new( AccountViewHandler, - Box::new(|account: Data| { + Box::new(|account: Data| { let account = account.data; let liquid = NearToken::from_yoctonear(account.amount); let locked = NearToken::from_yoctonear(account.locked); diff --git a/src/transactions.rs b/src/transactions.rs index 1051943..d0c2f1d 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -1,13 +1,13 @@ use std::sync::Arc; -use near_primitives::action::Action; +use near_primitives::{action::Action, types::AccountId}; use crate::{ common::send::{ExecuteSignedTransaction, Transactionable}, config::NetworkConfig, errors::{SignerError, ValidationError}, signer::Signer, - types::{transactions::PrepopulateTransaction, AccountId}, + types::transactions::PrepopulateTransaction, }; #[derive(Clone, Debug)] diff --git a/src/types/mod.rs b/src/types/mod.rs index 16e1f65..30d67b7 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -11,11 +11,6 @@ pub mod stake; pub mod storage; pub mod tokens; pub mod transactions; -pub mod views; - -pub use near_account_id::AccountId; -pub use near_gas::NearGas; -pub use near_token::NearToken; #[derive( Debug, diff --git a/src/types/views.rs b/src/types/views.rs deleted file mode 100644 index a94b557..0000000 --- a/src/types/views.rs +++ /dev/null @@ -1,441 +0,0 @@ -use std::sync::Arc; - -use near_contract_standards::fungible_token::Balance; -use near_primitives::account::FunctionCallPermission; -use near_primitives::serialize::dec_format; -use near_primitives::types::{BlockHeight, Gas, Nonce, ShardId, StorageUsage}; -use serde_with::base64::Base64; -use serde_with::serde_as; - -// TODO: THIS IS VERY VERY VERY BAD, BUT WE WILL ITERATE ON IT LATER :) -use near_crypto::PublicKey; - -use super::CryptoHash; -use crate::prelude::*; - -/// The block header info. This is a non-exhaustive list of items that -/// could be present in a block header. More can be added in the future. -/// -/// NOTE: For maintainability purposes, some items have been excluded. If required, -/// please submit an issue to [workspaces](https://github.com/near/near-api-rs/issues). -#[derive( - Clone, - Debug, - Eq, - PartialEq, - serde::Serialize, - serde::Deserialize, - borsh::BorshSerialize, - borsh::BorshDeserialize, -)] -#[non_exhaustive] -pub struct BlockHeader { - pub height: BlockHeight, - pub epoch_id: CryptoHash, - pub next_epoch_id: CryptoHash, - pub hash: CryptoHash, - pub prev_hash: CryptoHash, - pub timestamp_nanosec: u64, - pub random_value: CryptoHash, - pub gas_price: Balance, - pub block_ordinal: Option, - pub total_supply: Balance, - pub last_final_block: CryptoHash, - pub last_ds_final_block: CryptoHash, - pub next_bp_hash: CryptoHash, - pub latest_protocol_version: u32, - pub prev_state_root: CryptoHash, - pub chunk_receipts_root: CryptoHash, - pub chunk_headers_root: CryptoHash, - pub chunk_tx_root: CryptoHash, - pub outcome_root: CryptoHash, - pub challenges_root: CryptoHash, - pub block_merkle_root: CryptoHash, -} - -impl From for BlockHeader { - fn from(value: near_primitives::views::BlockHeaderView) -> Self { - Self { - height: value.height, - epoch_id: value.epoch_id.into(), - next_epoch_id: value.next_epoch_id.into(), - hash: value.hash.into(), - prev_hash: value.prev_hash.into(), - timestamp_nanosec: value.timestamp_nanosec, - random_value: value.random_value.into(), - gas_price: value.gas_price, - block_ordinal: value.block_ordinal, - total_supply: value.total_supply, - last_final_block: value.last_final_block.into(), - last_ds_final_block: value.last_ds_final_block.into(), - next_bp_hash: value.next_bp_hash.into(), - latest_protocol_version: value.latest_protocol_version, - prev_state_root: value.prev_state_root.into(), - chunk_receipts_root: value.chunk_receipts_root.into(), - chunk_headers_root: value.chunk_headers_root.into(), - chunk_tx_root: value.chunk_tx_root.into(), - outcome_root: value.outcome_root.into(), - challenges_root: value.challenges_root.into(), - block_merkle_root: value.block_merkle_root.into(), - } - } -} - -/// The header belonging to a `Chunk`. This is a non-exhaustive list of -/// members belonging to a Chunk, where newer fields can be added in the future. -/// -/// NOTE: For maintainability purposes, some items have been excluded. If required, -/// please submit an issue to [workspaces](https://github.com/near/workspaces-rs/issues). -#[derive( - Debug, - Clone, - Eq, - PartialEq, - serde::Serialize, - serde::Deserialize, - borsh::BorshSerialize, - borsh::BorshDeserialize, -)] -#[non_exhaustive] -pub struct ChunkHeader { - pub chunk_hash: CryptoHash, - pub prev_block_hash: CryptoHash, - pub height_created: BlockHeight, - pub height_included: BlockHeight, - pub shard_id: ShardId, - pub gas_used: Gas, - pub gas_limit: Gas, - pub balance_burnt: Balance, - - pub tx_root: CryptoHash, - pub outcome_root: CryptoHash, - pub prev_state_root: CryptoHash, - pub outgoing_receipts_root: CryptoHash, - pub encoded_merkle_root: CryptoHash, - pub encoded_length: u64, -} - -impl From for ChunkHeader { - fn from(value: near_primitives::views::ChunkHeaderView) -> Self { - Self { - chunk_hash: value.chunk_hash.into(), - prev_block_hash: value.prev_block_hash.into(), - height_created: value.height_created, - height_included: value.height_included, - shard_id: value.shard_id, - gas_used: value.gas_used, - gas_limit: value.gas_limit, - balance_burnt: value.balance_burnt, - tx_root: value.tx_root.into(), - outcome_root: value.outcome_root.into(), - prev_state_root: value.prev_state_root.into(), - outgoing_receipts_root: value.outgoing_receipts_root.into(), - encoded_merkle_root: value.encoded_merkle_root.into(), - encoded_length: value.encoded_length, - } - } -} - -#[derive( - serde::Serialize, - serde::Deserialize, - Debug, - Clone, - borsh::BorshSerialize, - borsh::BorshDeserialize, -)] -pub struct Block { - pub author: AccountId, - pub header: BlockHeader, - pub chunks: Vec, -} - -impl From for Block { - fn from(value: near_primitives::views::BlockView) -> Self { - Self { - author: value.author, - header: value.header.into(), - chunks: value.chunks.into_iter().map(Into::into).collect(), - } - } -} - -#[derive( - serde::Serialize, - serde::Deserialize, - Debug, - Eq, - PartialEq, - Clone, - borsh::BorshSerialize, - borsh::BorshDeserialize, -)] -pub struct Account { - #[serde(with = "dec_format")] - pub amount: Balance, - #[serde(with = "dec_format")] - pub locked: Balance, - pub code_hash: CryptoHash, - pub storage_usage: StorageUsage, - /// TODO(2271): deprecated. - #[serde(default)] - pub storage_paid_at: BlockHeight, -} - -impl From for Account { - fn from(value: near_primitives::views::AccountView) -> Self { - Self { - amount: value.amount, - locked: value.locked, - code_hash: value.code_hash.into(), - storage_usage: value.storage_usage, - storage_paid_at: value.storage_paid_at, - } - } -} - -/// A of the contract code. -#[serde_as] -#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Debug, Clone)] -pub struct ContractCode { - #[serde(rename = "code_base64")] - #[serde_as(as = "Base64")] - pub code: Vec, - pub hash: CryptoHash, -} - -impl From for ContractCode { - fn from(value: near_primitives::views::ContractCodeView) -> Self { - Self { - code: value.code, - hash: value.hash.into(), - } - } -} - -#[derive( - borsh::BorshSerialize, - borsh::BorshDeserialize, - Debug, - Eq, - PartialEq, - Clone, - serde::Serialize, - serde::Deserialize, -)] -pub enum AccessKeyPermission { - FunctionCall { - #[serde(with = "dec_format")] - allowance: Option, - receiver_id: String, - method_names: Vec, - }, - FullAccess, -} - -impl From for near_primitives::account::AccessKeyPermission { - fn from(value: AccessKeyPermission) -> Self { - match value { - AccessKeyPermission::FunctionCall { - allowance, - receiver_id, - method_names, - } => Self::FunctionCall(FunctionCallPermission { - allowance, - receiver_id, - method_names, - }), - AccessKeyPermission::FullAccess => Self::FullAccess, - } - } -} - -impl From for AccessKeyPermission { - fn from(value: near_primitives::views::AccessKeyPermissionView) -> Self { - match value { - near_primitives::views::AccessKeyPermissionView::FunctionCall { - allowance, - receiver_id, - method_names, - } => Self::FunctionCall { - allowance, - receiver_id, - method_names, - }, - near_primitives::views::AccessKeyPermissionView::FullAccess => Self::FullAccess, - } - } -} - -#[serde_as] -#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone)] -pub struct ViewStateResult { - pub values: Vec, - #[serde_as(as = "Vec")] - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub proof: Vec>, -} - -impl From for ViewStateResult { - fn from(value: near_primitives::views::ViewStateResult) -> Self { - Self { - values: value.values.into_iter().map(Into::into).collect(), - proof: value.proof, - } - } -} - -#[derive( - borsh::BorshSerialize, - borsh::BorshDeserialize, - Debug, - Eq, - PartialEq, - Clone, - serde::Serialize, - serde::Deserialize, -)] -pub struct AccessKey { - pub nonce: Nonce, - pub permission: AccessKeyPermission, -} - -impl From for AccessKey { - fn from(value: near_primitives::views::AccessKeyView) -> Self { - Self { - nonce: value.nonce, - permission: value.permission.into(), - } - } -} - -/// This type is used to mark keys (arrays of bytes) that are queried from store. -/// -/// NOTE: Currently, this type is only used in the _client and RPC to be able to transparently -/// pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`). -#[serde_as] -#[derive( - serde::Serialize, - serde::Deserialize, - Clone, - Debug, - PartialEq, - Eq, - borsh::BorshSerialize, - borsh::BorshDeserialize, - derive_more::Deref, - derive_more::From, - derive_more::Into, -)] -#[serde(transparent)] -pub struct StoreKey(#[serde_as(as = "Base64")] Vec); - -impl From for StoreKey { - fn from(value: near_primitives::types::StoreKey) -> Self { - Self(value.into()) - } -} - -/// This type is used to mark values returned from store (arrays of bytes). -/// -/// NOTE: Currently, this type is only used in the _client and RPC to be able to transparently -/// pretty-serialize the bytes arrays as base64-encoded strings (see `serialize.rs`). -#[serde_as] -#[derive( - serde::Serialize, - serde::Deserialize, - Clone, - Debug, - PartialEq, - Eq, - borsh::BorshSerialize, - borsh::BorshDeserialize, - derive_more::Deref, - derive_more::From, - derive_more::Into, -)] -#[serde(transparent)] -pub struct StoreValue(#[serde_as(as = "Base64")] Vec); - -impl From for StoreValue { - fn from(value: near_primitives::types::StoreValue) -> Self { - Self(value.into()) - } -} - -/// Item of the state, key and value are serialized in base64 and proof for inclusion of given state item. -#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone)] -pub struct StateItem { - pub key: StoreKey, - pub value: StoreValue, -} - -impl From for StateItem { - fn from(value: near_primitives::views::StateItem) -> Self { - Self { - key: value.key.into(), - value: value.value.into(), - } - } -} - -#[serde_as] -#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone)] -pub struct StateResult { - pub values: Vec, - #[serde_as(as = "Vec")] - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub proof: Vec>, -} - -impl From for StateResult { - fn from(value: near_primitives::views::ViewStateResult) -> Self { - Self { - values: value.values.into_iter().map(Into::into).collect(), - proof: value.proof, - } - } -} - -#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone, Default)] -pub struct CallResult { - pub result: Vec, - pub logs: Vec, -} - -impl From for CallResult { - fn from(value: near_primitives::views::CallResult) -> Self { - Self { - result: value.result, - logs: value.logs, - } - } -} - -#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone)] -pub struct AccessKeyInfo { - pub public_key: PublicKey, // TODO: replace it - pub access_key: AccessKey, -} - -impl From for AccessKeyInfo { - fn from(value: near_primitives::views::AccessKeyInfoView) -> Self { - Self { - public_key: value.public_key, - access_key: value.access_key.into(), - } - } -} - -#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Clone)] -pub struct AccessKeyList { - pub keys: Vec, -} - -impl From for AccessKeyList { - fn from(value: near_primitives::views::AccessKeyList) -> Self { - Self { - keys: value.keys.into_iter().map(Into::into).collect(), - } - } -} diff --git a/tests/account.rs b/tests/account.rs index 452175a..53933c1 100644 --- a/tests/account.rs +++ b/tests/account.rs @@ -1,6 +1,6 @@ use near_account_id::AccountId; use near_api::prelude::*; -use near_api::types::views::AccessKeyPermission; +use near_primitives::{account::AccessKeyPermission, views::AccessKeyPermissionView}; use near_token::NearToken; #[tokio::test] @@ -102,7 +102,7 @@ async fn access_key_management() { let alice_acc = Account(alice.id().clone()); let keys = alice_acc.list_keys().fetch_from(&network).await.unwrap(); - assert_eq!(keys.data.keys.len(), 1); + assert_eq!(keys.keys.len(), 1); let (secret, tx) = alice_acc .add_key(AccessKeyPermission::FullAccess) @@ -117,7 +117,7 @@ async fn access_key_management() { .assert_success(); let keys = alice_acc.list_keys().fetch_from(&network).await.unwrap(); - assert_eq!(keys.data.keys.len(), 2); + assert_eq!(keys.keys.len(), 2); let new_key_info = alice_acc .access_key(secret.public_key()) @@ -127,7 +127,7 @@ async fn access_key_management() { assert_eq!( new_key_info.data.permission, - AccessKeyPermission::FullAccess + AccessKeyPermissionView::FullAccess ); alice_acc @@ -140,7 +140,7 @@ async fn access_key_management() { let keys = alice_acc.list_keys().fetch_from(&network).await.unwrap(); - assert_eq!(keys.data.keys.len(), 1); + assert_eq!(keys.keys.len(), 1); alice_acc .access_key(secret.public_key()) @@ -164,10 +164,10 @@ async fn access_key_management() { let keys = alice_acc.list_keys().fetch_from(&network).await.unwrap(); - assert_eq!(keys.data.keys.len(), 11); + assert_eq!(keys.keys.len(), 11); alice_acc - .delete_keys(keys.data.keys.into_iter().map(|k| k.public_key).collect()) + .delete_keys(keys.keys.into_iter().map(|k| k.public_key).collect()) .with_signer(Signer::new(Signer::from_workspace(&alice)).unwrap()) .send_to(&network) .await @@ -175,5 +175,5 @@ async fn access_key_management() { .assert_success(); let keys = alice_acc.list_keys().fetch_from(&network).await.unwrap(); - assert_eq!(keys.data.keys.len(), 0); + assert_eq!(keys.keys.len(), 0); } diff --git a/tests/multiple_tx_at_same_time_from_same-_user.rs b/tests/multiple_tx_at_same_time_from_same-_user.rs index b1ac052..56ddaeb 100644 --- a/tests/multiple_tx_at_same_time_from_same-_user.rs +++ b/tests/multiple_tx_at_same_time_from_same-_user.rs @@ -1,9 +1,10 @@ use std::{collections::HashMap, sync::Arc}; use futures::future::join_all; -use near_api::{prelude::*, types::views::AccessKeyPermission}; +use near_api::prelude::*; use near_crypto::PublicKey; +use near_primitives::account::AccessKeyPermission; use near_token::NearToken; #[tokio::test]