Skip to content

Commit

Permalink
Merge #4494
Browse files Browse the repository at this point in the history
4494: Implement `get_addresses_bytecode` in JsonRPC r=aoudiamoncef a=aoudiamoncef

* [x] document all added functions
* [ ] try in sandbox /simulation/labnet
  * [ ] if part of node-launch, checked using the `resync_check` flag
* [x] unit tests on the added/changed features
  * [x] make tests compile
  * [x] make tests pass 
* [x] add logs allowing easy debugging in case the changes caused problems
* [x] if the API has changed, update the API specification

closes #4474

Co-authored-by: Moncef AOUDIA <[email protected]>
  • Loading branch information
bors[bot] and aoudiamoncef authored Oct 24, 2023
2 parents 24e1480 + a739e57 commit c6f6a5e
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 48 deletions.
67 changes: 45 additions & 22 deletions Cargo.lock

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

22 changes: 22 additions & 0 deletions massa-api-exports/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,25 @@ impl std::fmt::Display for CompactAddressInfo {
Ok(())
}
}

/// filter used when retrieving address informations
#[derive(Debug, Deserialize, Clone, Serialize)]
pub struct AddressFilter {
/// Address
pub address: Address,

/// true means final
/// false means candidate
pub is_final: bool,
}

impl std::fmt::Display for AddressFilter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Address: {:?}", self.address)?;
if self.is_final {
write!(f, " (Final)")
} else {
write!(f, " (Candidate)")
}
}
}
40 changes: 21 additions & 19 deletions massa-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@ version = "0.26.1"
edition = "2021"

[features]
testing = []
testing = ["dep:massa_channel", "dep:massa_grpc", "massa_grpc/testing"]

[dependencies]
jsonrpsee = { workspace = true, "features" = ["server", "macros"] }
futures = { workspace = true }
async-trait = { workspace = true }
serde = { workspace = true, "features" = ["derive"] }
serde_json = { workspace = true }
tower-http = { workspace = true, "features" = ["cors"] }
tower = { workspace = true, "features" = ["full"] }
hyper = { workspace = true }
tokio = { workspace = true, "features" = ["full"] }
tokio-stream = { workspace = true, "features" = ["sync"] }
tracing = { workspace = true }
itertools = { workspace = true }
parking_lot = { workspace = true, "features" = ["deadlock_detection"] }
massa_consensus_exports = { workspace = true }
massa_api_exports = { workspace = true }
massa_channel = { workspace = true, optional = true}
massa_consensus_exports = { workspace = true }
massa_execution_exports = { workspace = true }
massa_grpc = { workspace = true, "features" = ["testing"], optional = true}
massa_hash = { workspace = true }
massa_models = { workspace = true }
massa_pool_exports = { workspace = true }
massa_protocol_exports = { workspace = true }
massa_execution_exports = { workspace = true }
massa_pos_exports = { workspace = true }
massa_storage = { workspace = true }
massa_protocol_exports = { workspace = true }
massa_serialization = { workspace = true }
massa_signature = { workspace = true }
massa_storage = { workspace = true }
massa_time = { workspace = true }
massa_versioning = { workspace = true }
massa_hash = { workspace = true }
massa_wallet = { workspace = true }

async-trait = { workspace = true }
futures = { workspace = true }
hyper = { workspace = true }
itertools = { workspace = true }
jsonrpsee = { workspace = true, "features" = ["server", "macros"] }
parking_lot = { workspace = true, "features" = ["deadlock_detection"] }
serde = { workspace = true, "features" = ["derive"] }
serde_json = { workspace = true }
tokio = { workspace = true, "features" = ["full"] }
tokio-stream = { workspace = true, "features" = ["sync"] }
tower = { workspace = true, "features" = ["full"] }
tower-http = { workspace = true, "features" = ["cors"] }
tracing = { workspace = true }

[dev-dependencies]
massa_consensus_exports = { workspace = true, "features" = ["testing"] }
Expand Down
11 changes: 10 additions & 1 deletion massa-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use jsonrpsee::server::middleware::HostFilterLayer;
use jsonrpsee::server::{BatchRequestConfig, ServerBuilder, ServerHandle};
use jsonrpsee::RpcModule;
use massa_api_exports::{
address::AddressInfo,
address::{AddressFilter, AddressInfo},
block::{BlockInfo, BlockSummary},
config::APIConfig,
datastore::{DatastoreEntryInput, DatastoreEntryOutput},
Expand Down Expand Up @@ -54,6 +54,11 @@ mod api_trait;
mod private;
mod public;

#[cfg(feature = "testing")]
use massa_channel as _;
#[cfg(feature = "testing")]
use massa_grpc as _;

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -369,6 +374,10 @@ pub trait MassaRpc {
#[method(name = "get_addresses")]
async fn get_addresses(&self, arg: Vec<Address>) -> RpcResult<Vec<AddressInfo>>;

/// Get addresses bytecode.
#[method(name = "get_addresses_bytecode")]
async fn get_addresses_bytecode(&self, args: Vec<AddressFilter>) -> RpcResult<Vec<Vec<u8>>>;

/// Adds operations to pool. Returns operations that were ok and sent to pool.
#[method(name = "send_operations")]
async fn send_operations(&self, arg: Vec<OperationInput>) -> RpcResult<Vec<OperationId>>;
Expand Down
6 changes: 5 additions & 1 deletion massa-api/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{MassaRpcServer, Private, RpcServer, StopHandle, Value, API};
use async_trait::async_trait;
use jsonrpsee::core::{Error as JsonRpseeError, RpcResult};
use massa_api_exports::{
address::AddressInfo,
address::{AddressFilter, AddressInfo},
block::{BlockInfo, BlockSummary},
config::APIConfig,
datastore::{DatastoreEntryInput, DatastoreEntryOutput},
Expand Down Expand Up @@ -238,6 +238,10 @@ impl MassaRpcServer for API<Private> {
crate::wrong_api::<Vec<AddressInfo>>()
}

async fn get_addresses_bytecode(&self, _: Vec<AddressFilter>) -> RpcResult<Vec<Vec<u8>>> {
crate::wrong_api::<Vec<Vec<u8>>>()
}

async fn send_operations(&self, _: Vec<OperationInput>) -> RpcResult<Vec<OperationId>> {
crate::wrong_api::<Vec<OperationId>>()
}
Expand Down
Loading

0 comments on commit c6f6a5e

Please sign in to comment.