Skip to content

Commit

Permalink
#49: cargo fmt all & add CI check (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon authored and SkidanovAlex committed Oct 28, 2019
1 parent 6a00875 commit 9c3faad
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Expand Up @@ -17,6 +17,7 @@ test_cargo:
- *setup_cache
script:
- rustc --version && cargo --version
- cargo fmt --all -- --check
- cargo check --all --tests --benches --all-features
- cargo test --all --verbose

Expand Down
2 changes: 1 addition & 1 deletion chain/client/src/view_client.rs
Expand Up @@ -106,7 +106,7 @@ impl Handler<GetChunk> for ViewClientActor {
.get_chunk(&block.chunks[shard_id as usize].chunk_hash())
.map(Clone::clone)
})
},
}
GetChunk::BlockHeight(block_height, shard_id) => {
self.chain.get_block_by_height(block_height).map(Clone::clone).and_then(|block| {
self.chain
Expand Down
3 changes: 2 additions & 1 deletion chain/jsonrpc/client/src/lib.rs
Expand Up @@ -8,7 +8,8 @@ use serde::Serialize;
use near_primitives::hash::CryptoHash;
use near_primitives::types::{BlockIndex, ShardId};
use near_primitives::views::{
BlockView, ChunkView, ExecutionOutcomeView, FinalExecutionOutcomeView, QueryResponse, StatusResponse,
BlockView, ChunkView, ExecutionOutcomeView, FinalExecutionOutcomeView, QueryResponse,
StatusResponse,
};

use crate::message::{from_slice, Message};
Expand Down
55 changes: 31 additions & 24 deletions chain/jsonrpc/src/lib.rs
Expand Up @@ -18,7 +18,8 @@ use async_utils::{delay, timeout};
use message::Message;
use message::{Request, RpcError};
use near_client::{
ClientActor, GetBlock, GetChunk, GetNetworkInfo, Query, Status, TxDetails, TxStatus, ViewClientActor,
ClientActor, GetBlock, GetChunk, GetNetworkInfo, Query, Status, TxDetails, TxStatus,
ViewClientActor,
};
pub use near_jsonrpc_client as client;
use near_jsonrpc_client::{message, BlockId, ChunkId};
Expand Down Expand Up @@ -115,19 +116,16 @@ fn parse_hash(params: Option<Value>) -> Result<CryptoHash, RpcError> {
})
}

fn jsonify_client_response(client_response: Result<NetworkClientResponses, MailboxError>) -> Result<Value, RpcError> {
fn jsonify_client_response(
client_response: Result<NetworkClientResponses, MailboxError>,
) -> Result<Value, RpcError> {
match client_response {
Ok(NetworkClientResponses::TxStatus(tx_result)) => {
serde_json::to_value(tx_result).map_err(|err| {
RpcError::server_error(Some(err.to_string()))
})
}
Ok(_) => {
Err(RpcError::server_error(Some("Wrong response for transaction status query".to_string())))
}
Err(e) => {
Err(RpcError::server_error(Some(e.to_string())))
}
Ok(NetworkClientResponses::TxStatus(tx_result)) => serde_json::to_value(tx_result)
.map_err(|err| RpcError::server_error(Some(err.to_string()))),
Ok(_) => Err(RpcError::server_error(Some(
"Wrong response for transaction status query".to_string(),
))),
Err(e) => Err(RpcError::server_error(Some(e.to_string()))),
}
}

Expand Down Expand Up @@ -194,14 +192,18 @@ impl JsonRpcHandler {
if needs_routing {
let final_tx = self
.client_addr
.send(NetworkClientMessages::TxStatus { tx_hash, signer_account_id: signer_account_id.clone() })
.send(NetworkClientMessages::TxStatus {
tx_hash,
signer_account_id: signer_account_id.clone(),
})
.compat()
.await;
if let Ok(NetworkClientResponses::TxStatus(ref tx_result)) = final_tx {
match tx_result.status {
FinalExecutionStatus::Started
| FinalExecutionStatus::NotStarted => {}
FinalExecutionStatus::Failure(_) | FinalExecutionStatus::SuccessValue(_) => {
FinalExecutionStatus::Failure(_)
| FinalExecutionStatus::SuccessValue(_) => {
break jsonify_client_response(final_tx);
}
}
Expand All @@ -213,7 +215,8 @@ impl JsonRpcHandler {
match tx.status {
FinalExecutionStatus::Started
| FinalExecutionStatus::NotStarted => {}
FinalExecutionStatus::Failure(_) | FinalExecutionStatus::SuccessValue(_) => {
FinalExecutionStatus::Failure(_)
| FinalExecutionStatus::SuccessValue(_) => {
break jsonify(final_tx);
}
}
Expand All @@ -235,7 +238,7 @@ impl JsonRpcHandler {
}
NetworkClientResponses::NoResponse => {
Err(RpcError::server_error(Some("Failed to include transaction.".to_string())))
},
}
_ => unreachable!(),
}
}
Expand All @@ -259,11 +262,11 @@ impl JsonRpcHandler {
let tx_hash = from_base_or_parse_err(hash).and_then(|bytes| {
CryptoHash::try_from(bytes).map_err(|err| RpcError::parse_error(err.to_string()))
})?;
jsonify_client_response(self
.client_addr
.send(NetworkClientMessages::TxStatus { tx_hash, signer_account_id: account_id })
.compat()
.await
jsonify_client_response(
self.client_addr
.send(NetworkClientMessages::TxStatus { tx_hash, signer_account_id: account_id })
.compat()
.await,
)
}

Expand Down Expand Up @@ -291,8 +294,12 @@ impl JsonRpcHandler {
self.view_client_addr
.send(match chunk_id {
ChunkId::BlockShardId(block_id, shard_id) => match block_id {
BlockId::Height(block_height) => GetChunk::BlockHeight(block_height, shard_id),
BlockId::Hash(block_hash) => GetChunk::BlockHash(block_hash.into(), shard_id),
BlockId::Height(block_height) => {
GetChunk::BlockHeight(block_height, shard_id)
}
BlockId::Hash(block_hash) => {
GetChunk::BlockHash(block_hash.into(), shard_id)
}
},
ChunkId::Hash(chunk_hash) => GetChunk::ChunkHash(chunk_hash.into()),
})
Expand Down
7 changes: 3 additions & 4 deletions core/primitives/src/views.rs
Expand Up @@ -881,10 +881,9 @@ impl From<Receipt> for ReceiptView {
.collect(),
actions: action_receipt.actions.into_iter().map(Into::into).collect(),
},
ReceiptEnum::Data(data_receipt) => ReceiptEnumView::Data {
data_id: data_receipt.data_id,
data: data_receipt.data,
},
ReceiptEnum::Data(data_receipt) => {
ReceiptEnumView::Data { data_id: data_receipt.data_id, data: data_receipt.data }
}
},
}
}
Expand Down
6 changes: 2 additions & 4 deletions genesis-tools/genesis-populate/src/lib.rs
Expand Up @@ -267,10 +267,8 @@ impl GenesisBuilder {
{
let code = ContractCode::new(wasm_binary.to_vec());
set_code(&mut state_update, &account_id, &code);
let contract_record = StateRecord::Contract {
account_id,
code: wasm_binary_base64.clone(),
};
let contract_record =
StateRecord::Contract { account_id, code: wasm_binary_base64.clone() };
records.push(contract_record);
}

Expand Down
4 changes: 1 addition & 3 deletions near/src/runtime.rs
Expand Up @@ -313,9 +313,7 @@ impl RuntimeAdapter for NightshadeRuntime {
last_known_block_hash: &CryptoHash,
) -> Result<Vec<(AccountId, bool)>, Error> {
let mut epoch_manager = self.epoch_manager.write().expect(POISONED_LOCK_ERR);
epoch_manager
.get_all_block_producers(epoch_id, last_known_block_hash)
.map_err(Error::from)
epoch_manager.get_all_block_producers(epoch_id, last_known_block_hash).map_err(Error::from)
}

fn get_block_producer(
Expand Down

0 comments on commit 9c3faad

Please sign in to comment.