Struct validator_worker::sentry_interface::SentryApi
source · pub struct SentryApi<C: Unlocked, P = ChainsValidators> {
pub adapter: Adapter<C, UnlockedState>,
pub client: Client,
pub logger: Logger,
pub config: Config,
pub sentry_url: ApiUrl,
pub whoami: HashMap<ChainId, Validator>,
pub propagate_to: P,
}
Fields
adapter: Adapter<C, UnlockedState>
client: Client
logger: Logger
config: Config
sentry_url: ApiUrl
For all the calls that do not have information about the Chains
whoami: HashMap<ChainId, Validator>
Whilelisted chains for which this validator (Who Am I) can operate on.
Since the validator might have different urls for old vs new Campaigns,
we can override the URL based on the campaign, see crate::Worker
.
Auth token for this validator is generated for each Chain on SentryApi::new
propagate_to: P
If set with Validators
, propagate_to
should contain the whoami
Validator
in each Chain!
use SentryApi::init
or SentryApi::with_propagate
instead
Implementations
sourceimpl<C: Unlocked + 'static> SentryApi<C, ()>
impl<C: Unlocked + 'static> SentryApi<C, ()>
sourcepub fn new(
adapter: Adapter<C, UnlockedState>,
logger: Logger,
config: Config,
sentry_url: ApiUrl
) -> Result<SentryApi<C, ()>, Error>
pub fn new(
adapter: Adapter<C, UnlockedState>,
logger: Logger,
config: Config,
sentry_url: ApiUrl
) -> Result<SentryApi<C, ()>, Error>
sentry_url
is the default URL to which the current Who am I validator should make requests.
It is used to populate the config Chains with Authentication Token & [ApiUrl
].
This value can be overwritten using propagate_to
,
if any of the passed validators has the same [ValidatorId
].
sourcepub fn init(
adapter: Adapter<C, UnlockedState>,
logger: Logger,
config: Config,
sentry_url: ApiUrl,
propagate_to: ChainsValidators
) -> Result<SentryApi<C, ChainsValidators>, Error>
pub fn init(
adapter: Adapter<C, UnlockedState>,
logger: Logger,
config: Config,
sentry_url: ApiUrl,
propagate_to: ChainsValidators
) -> Result<SentryApi<C, ChainsValidators>, Error>
Initialize the SentryApi
and makes sure that [Adapter::whoami()
] is present in each chain Validators
.
Sets the Who am I [ApiUrl
] and the Authentication Token for a specific Chain for calls that require authentication.
sourcepub fn with_propagate(
self,
propagate_to: ChainsValidators
) -> Result<SentryApi<C, ChainsValidators>, Error>
pub fn with_propagate(
self,
propagate_to: ChainsValidators
) -> Result<SentryApi<C, ChainsValidators>, Error>
If the Who am I Validator is not found in propagate_to
it will be added.
Propagation should happen to all validators Sentry instances including Who am I
i.e. the current validator.
If a Chain in propagate_to is not setup (SentryApi::whoami
) for this instance, an error is returned.
sourceimpl<C: Unlocked + 'static, P> SentryApi<C, P>
impl<C: Unlocked + 'static, P> SentryApi<C, P>
pub async fn get_latest_msg(
&self,
channel: ChannelId,
from: ValidatorId,
message_types: &[MessageType]
) -> Result<Option<MessageTypes>, Error>
pub async fn get_our_latest_msg(
&self,
channel: ChannelId,
message_types: &[MessageType]
) -> Result<Option<MessageTypes>, Error>
sourcepub async fn get_last_approved(
&self,
channel: ChannelId
) -> Result<LastApprovedResponse<UncheckedState>, Error>
pub async fn get_last_approved(
&self,
channel: ChannelId
) -> Result<LastApprovedResponse<UncheckedState>, Error>
Get’s the last approved state and requesting a [primitives::validator::Heartbeat
], see [LastApprovedResponse
]
sourcepub async fn get_spenders_page(
&self,
channel_context: &ChainOf<Channel>,
page: u64
) -> Result<AllSpendersResponse, Error>
pub async fn get_spenders_page(
&self,
channel_context: &ChainOf<Channel>,
page: u64
) -> Result<AllSpendersResponse, Error>
page always starts from 0
pub async fn get_all_spenders(
&self,
channel_context: &ChainOf<Channel>
) -> Result<HashMap<Address, Spender>, Error>
sourcepub async fn get_accounting(
&self,
channel_context: &ChainOf<Channel>
) -> Result<AccountingResponse<CheckedState>, Error>
pub async fn get_accounting(
&self,
channel_context: &ChainOf<Channel>
) -> Result<AccountingResponse<CheckedState>, Error>
Get the accounting from Sentry
Balances
should always be in CheckedState
sourcepub async fn collect_channels(
&self
) -> Result<(HashSet<ChainOf<Channel>>, ChainsValidators), Error>
pub async fn collect_channels(
&self
) -> Result<(HashSet<ChainOf<Channel>>, ChainsValidators), Error>
Fetches all Campaign
s from the Who am I Sentry.
It builds the Channel
s to be processed alongside all the Validator
s’ url & auth token.