Skip to content

Commit

Permalink
simplified mn
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Dec 13, 2023
1 parent 05bf81a commit 66c7a5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
38 changes: 3 additions & 35 deletions lib/ain-ocean/src/api/masternode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,20 @@ use crate::{
api_paged_response::ApiPagedResponse,
api_query::PaginationQuery,
error::OceanResult,
model::masternode::{MasternodeData, MasternodeState, MasternodeCreation, MasternodeOwner, MasternodeOperator},
model::masternode::MasternodeData,
};

async fn list_masternodes(Query(query): Query<PaginationQuery>) -> OceanResult<Json<ApiPagedResponse<MasternodeData>>> {
let masternodes = vec![
MasternodeData {
id: "e86c027861cc0af423313f4152a44a83296a388eb51bf1a6dde9bd75bed55fb4".into(),
sort: "00000000e86c027861cc0af423313f4152a44a83296a388eb51bf1a6dde9bd75bed55fb4".into(),
state: MasternodeState::Enabled,
minted_blocks: 2,
owner: MasternodeOwner {
address: "mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU".into(),
},
operator: MasternodeOperator {
address: "mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy".into(),
},
creation: MasternodeCreation {
height: 0
},
resign: None,
timelock: 0
}
MasternodeData::new("0"),
];
Ok(Json(ApiPagedResponse::of(masternodes, query.size, |masternode| {
masternode.clone().id
})))
}

async fn get_masternode(Path(masternode_id): Path<String>) -> OceanResult<Json<MasternodeData>> {
Ok(Json(MasternodeData {
id: "e86c027861cc0af423313f4152a44a83296a388eb51bf1a6dde9bd75bed55fb4".into(),
sort: "00000000e86c027861cc0af423313f4152a44a83296a388eb51bf1a6dde9bd75bed55fb4".into(),
state: MasternodeState::Enabled,
minted_blocks: 2,
owner: MasternodeOwner {
address: "mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU".into(),
},
operator: MasternodeOperator {
address: "mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy".into(),
},
creation: MasternodeCreation {
height: 0
},
resign: None,
timelock: 0
}))
Ok(Json(MasternodeData::new(&masternode_id)))
}

pub fn router() -> Router {
Expand Down
21 changes: 21 additions & 0 deletions lib/ain-ocean/src/model/masternode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ pub struct MasternodeData {
pub resign: Option<MasternodeResign>,
pub timelock: i32,
}
impl MasternodeData {
pub fn new(id: &str) -> Self {
Self {
id: id.repeat(64),
sort: id.repeat(72),
state: MasternodeState::Enabled,
minted_blocks: 2,
owner: MasternodeOwner {
address: id.repeat(34),
},
operator: MasternodeOperator {
address: id.repeat(34),
},
creation: MasternodeCreation {
height: 0
},
resign: None,
timelock: 0
}
}
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
Expand Down

0 comments on commit 66c7a5b

Please sign in to comment.