Skip to content

Commit

Permalink
feat(service-registry-api): add service-registry-api package (axelarn…
Browse files Browse the repository at this point in the history
  • Loading branch information
maancham authored Sep 18, 2024
1 parent 2b2aa47 commit 6bc955b
Show file tree
Hide file tree
Showing 34 changed files with 392 additions and 317 deletions.
23 changes: 22 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde_json = "1.0.89"
service-registry = { version = "^1.0.0", path = "contracts/service-registry" }
service-registry-api = { version = "^1.0.0", path = "packages/service-registry-api" }
sha3 = { version = "0.10.8", default-features = false, features = [] }
signature-verifier-api = { version = "^1.0.0", path = "packages/signature-verifier-api" }
stellar = { version = "^1.0.0", path = "external-gateways/stellar" }
Expand Down
2 changes: 1 addition & 1 deletion ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ router-api = { workspace = true }
serde = { version = "1.0.147", features = ["derive"] }
serde_json = { workspace = true }
serde_with = "3.2.0"
service-registry = { workspace = true }
service-registry-api = { workspace = true }
sha3 = { workspace = true }
stellar = { workspace = true }
stellar-rs = "0.3.2"
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/commands/bond_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmrs::tx::Msg;
use cosmrs::Coin;
use error_stack::Result;
use report::ResultCompatExt;
use service_registry::msg::ExecuteMsg;
use service_registry_api::msg::ExecuteMsg;
use valuable::Valuable;

use crate::commands::{broadcast_tx, verifier_pub_key};
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/commands/claim_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmrs::cosmwasm::MsgExecuteContract;
use cosmrs::tx::Msg;
use error_stack::Result;
use report::ResultCompatExt;
use service_registry::msg::ExecuteMsg;
use service_registry_api::msg::ExecuteMsg;
use valuable::Valuable;

use crate::commands::{broadcast_tx, verifier_pub_key};
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/commands/deregister_chain_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmrs::tx::Msg;
use error_stack::Result;
use report::ResultCompatExt;
use router_api::ChainName;
use service_registry::msg::ExecuteMsg;
use service_registry_api::msg::ExecuteMsg;
use valuable::Valuable;

use crate::commands::{broadcast_tx, verifier_pub_key};
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/commands/register_chain_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmrs::tx::Msg;
use error_stack::Result;
use report::ResultCompatExt;
use router_api::ChainName;
use service_registry::msg::ExecuteMsg;
use service_registry_api::msg::ExecuteMsg;
use valuable::Valuable;

use crate::commands::{broadcast_tx, verifier_pub_key};
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/commands/unbond_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmrs::cosmwasm::MsgExecuteContract;
use cosmrs::tx::Msg;
use error_stack::Result;
use report::ResultCompatExt;
use service_registry::msg::ExecuteMsg;
use service_registry_api::msg::ExecuteMsg;
use valuable::Valuable;

use crate::commands::{broadcast_tx, verifier_pub_key};
Expand Down
1 change: 1 addition & 0 deletions contracts/multisig-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ report = { workspace = true }
router-api = { workspace = true }
serde_json = "1.0.89"
service-registry = { workspace = true }
service-registry-api = { workspace = true }
sha3 = { workspace = true }
stellar = { workspace = true }
stellar-xdr = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion contracts/multisig-prover/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use itertools::Itertools;
use multisig::msg::Signer;
use multisig::verifier_set::VerifierSet;
use router_api::{ChainName, CrossChainId, Message};
use service_registry::WeightedVerifier;
use service_registry_api::WeightedVerifier;

use crate::contract::START_MULTISIG_REPLY_ID;
use crate::error::ContractError;
Expand Down
2 changes: 1 addition & 1 deletion contracts/multisig-prover/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum ContractError {
PublicKeyNotFound { participant: String },

#[error(transparent)]
ServiceRegistryError(#[from] service_registry::ContractError),
ServiceRegistryError(#[from] service_registry_api::error::ContractError),

#[error(transparent)]
NonEmptyError(#[from] nonempty::Error),
Expand Down
13 changes: 6 additions & 7 deletions contracts/multisig-prover/src/test/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use multisig::msg::Signer;
use multisig::multisig::Multisig;
use multisig::types::MultisigState;
use multisig::verifier_set::VerifierSet;
use service_registry::{
AuthorizationState, BondingState, Verifier, WeightedVerifier, VERIFIER_WEIGHT,
};
use service_registry::VERIFIER_WEIGHT;
use service_registry_api::{AuthorizationState, BondingState, Verifier, WeightedVerifier};

use super::test_data::{self, TestOperator};

Expand Down Expand Up @@ -113,12 +112,12 @@ fn mock_multisig(operators: Vec<TestOperator>) -> Multisig {
}

fn service_registry_mock_querier_handler(
msg: service_registry::msg::QueryMsg,
msg: service_registry_api::msg::QueryMsg,
operators: Vec<TestOperator>,
) -> QuerierResult {
let result = match msg {
service_registry::msg::QueryMsg::Service { service_name } => {
to_json_binary(&service_registry::Service {
service_registry_api::msg::QueryMsg::Service { service_name } => {
to_json_binary(&service_registry_api::Service {
name: service_name.to_string(),
coordinator_contract: Addr::unchecked(COORDINATOR_ADDRESS),
min_num_verifiers: 1,
Expand All @@ -129,7 +128,7 @@ fn service_registry_mock_querier_handler(
description: "verifiers".to_string(),
})
}
service_registry::msg::QueryMsg::ActiveVerifiers {
service_registry_api::msg::QueryMsg::ActiveVerifiers {
service_name: _,
chain_name: _,
} => to_json_binary(
Expand Down
1 change: 0 additions & 1 deletion contracts/rewards/src/contract/migrations/v1_0_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::collections::HashMap;
use std::marker::PhantomData;
use std::u64;

use axelar_wasm_std::error::ContractError;
use cosmwasm_schema::cw_serde;
Expand Down
1 change: 1 addition & 0 deletions contracts/service-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ report = { workspace = true }
router-api = { workspace = true }
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
service-registry-api = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion contracts/service-registry/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_schema::write_api;
use service_registry::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use service_registry::msg::InstantiateMsg;
use service_registry_api::msg::{ExecuteMsg, QueryMsg};

fn main() {
write_api! {
Expand Down
4 changes: 2 additions & 2 deletions contracts/service-registry/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use error_stack::ResultExt;
use router_api::ChainName;
use service_registry_api::msg::{ExecuteMsg, QueryMsg};

use crate::msg::{ExecuteMsg, QueryMsg};
use crate::{Service, Verifier, WeightedVerifier};

type Result<T> = error_stack::Result<T, Error>;
Expand Down Expand Up @@ -92,9 +92,9 @@ mod test {
use cosmwasm_std::testing::MockQuerier;
use cosmwasm_std::{from_json, to_json_binary, Addr, QuerierWrapper, SystemError, WasmQuery};
use router_api::ChainName;
use service_registry_api::msg::QueryMsg;

use crate::client::Client;
use crate::msg::QueryMsg;
use crate::{Service, Verifier, WeightedVerifier};

#[test]
Expand Down
10 changes: 6 additions & 4 deletions contracts/service-registry/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use cosmwasm_std::{
Storage,
};
use error_stack::{bail, Report, ResultExt};
use service_registry_api::error::ContractError;
use service_registry_api::{AuthorizationState, BondingState, Service};

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::{AuthorizationState, BondingState, Service, SERVICES, VERIFIERS};
use crate::state::{SERVICES, VERIFIERS};

mod execute;
mod migrations;
Expand Down Expand Up @@ -201,10 +202,11 @@ mod test {
coins, from_json, CosmosMsg, Empty, OwnedDeps, StdResult, Uint128, WasmQuery,
};
use router_api::ChainName;
use service_registry_api::msg::{UpdatedServiceParams, VerifierDetails};
use service_registry_api::{Verifier, WeightedVerifier};

use super::*;
use crate::msg::{UpdatedServiceParams, VerifierDetails};
use crate::state::{Verifier, WeightedVerifier, VERIFIER_WEIGHT};
use crate::state::VERIFIER_WEIGHT;

const GOVERNANCE_ADDRESS: &str = "governance";
const UNAUTHORIZED_ADDRESS: &str = "unauthorized";
Expand Down
15 changes: 10 additions & 5 deletions contracts/service-registry/src/contract/execute.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use axelar_wasm_std::nonempty;
use error_stack::Result;
use router_api::ChainName;
use service_registry_api::{self, AuthorizationState, Verifier};
use state::VERIFIERS;

use super::*;
use crate::msg::UpdatedServiceParams;
use crate::state::{self, AuthorizationState, Verifier, VERIFIERS};
use crate::state::{self};

#[allow(clippy::too_many_arguments)]
pub fn register_service(
Expand Down Expand Up @@ -134,7 +136,7 @@ pub fn bond_verifier(
(&service_name.clone(), &info.sender.clone()),
|sw| -> std::result::Result<Verifier, ContractError> {
match sw {
Some(verifier) => Ok(verifier.bond(bond)?),
Some(verifier) => Ok(state::bond_verifier(verifier, bond)?),
None => Ok(Verifier {
address: info.sender,
bonding_state: BondingState::Bonded {
Expand Down Expand Up @@ -210,7 +212,7 @@ pub fn unbond_verifier(
.ready_to_unbond(verifier.address.to_string())
.change_context(ContractError::FailedToUnbondVerifier)?;

let verifier = verifier.unbond(ready_to_unbond, env.block.time)?;
let verifier = state::unbond_verifier(verifier, ready_to_unbond, env.block.time)?;

VERIFIERS
.save(deps.storage, (&service_name, &info.sender), &verifier)
Expand All @@ -235,8 +237,11 @@ pub fn claim_stake(
.change_context(ContractError::StorageError)?
.ok_or(ContractError::VerifierNotFound)?;

let (verifier, released_bond) =
verifier.claim_stake(env.block.time, service.unbonding_period_days as u64)?;
let (verifier, released_bond) = state::claim_verifier_stake(
verifier,
env.block.time,
service.unbonding_period_days as u64,
)?;

VERIFIERS
.save(deps.storage, (&service_name, &info.sender), &verifier)
Expand Down
8 changes: 5 additions & 3 deletions contracts/service-registry/src/contract/query.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use cosmwasm_std::Order;
use axelar_wasm_std::address;
use cosmwasm_std::{Deps, Order};
use itertools::Itertools;
use router_api::ChainName;
use service_registry_api::error::ContractError;
use service_registry_api::*;

use super::*;
use crate::msg::VerifierDetails;
use crate::state::{WeightedVerifier, VERIFIERS, VERIFIERS_PER_CHAIN, VERIFIER_WEIGHT};
use crate::state::{SERVICES, VERIFIERS, VERIFIERS_PER_CHAIN, VERIFIER_WEIGHT};

pub fn active_verifiers(
deps: Deps,
Expand Down
3 changes: 1 addition & 2 deletions contracts/service-registry/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, StdResult, WasmMsg};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::msg::ExecuteMsg;
use service_registry_api::msg::ExecuteMsg;

/// ServiceRegistry is a wrapper around Addr that provides a lot of helpers
/// for working with this.
Expand Down
8 changes: 3 additions & 5 deletions contracts/service-registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
mod client;
pub use client::Client;
pub mod contract;
pub mod error;
pub mod helpers;
pub mod msg;
mod state;

pub use state::{
AuthorizationState, BondingState, Service, Verifier, WeightedVerifier, VERIFIER_WEIGHT,
pub use service_registry_api::{
AuthorizationState, BondingState, Service, Verifier, WeightedVerifier,
};

pub use crate::error::ContractError;
pub use state::VERIFIER_WEIGHT;
Loading

0 comments on commit 6bc955b

Please sign in to comment.