-
-
Save mgild/c6c5bb029c7b13a05eac6b8c15747de9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use crate::error::Error; | |
| use crate::*; | |
| use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; | |
| use near_sdk::serde::{Deserialize, Serialize}; | |
| #[derive(Default, Clone, BorshSerialize, BorshDeserialize, Serialize, Deserialize)] | |
| pub struct AggregatorRead { | |
| pub address: Uuid, | |
| pub payer: Option<Uuid>, | |
| } | |
| impl AggregatorRead { | |
| fn validate(&self, ctx: &Contract) -> Result<(), Error> { | |
| let aggregator = ctx | |
| .aggregators | |
| .get(&self.address) | |
| .ok_or(Error::InvalidAggregator)?; | |
| require(aggregator.latest_confirmed_round.id > 0, Error::AggregatorEmpty)?; | |
| if aggregator.read_charge > 0 { | |
| let payer_key = self.payer.ok_or(Error::InvalidEscrow)?; | |
| let payer = ctx.escrows.get(&payer_key).ok_or(Error::InvalidEscrow)?; | |
| let queue = ctx.queues.get(&aggregator.queue).ok_or(Error::InvalidQueue)?; | |
| require(queue.mint == payer.mint, Error::MintMismatch)?; | |
| } | |
| Ok(()) | |
| } | |
| fn actuate(&self, ctx: &mut Contract) -> Result<AggregatorRound, Error> { | |
| let aggregator = ctx.aggregators.get(&self.address).unwrap(); | |
| if aggregator.read_charge > 0 { | |
| let mut reward_wallet = ctx.escrows.get(&aggregator.reward_escrow).unwrap(); | |
| let payer_key = self.payer.unwrap(); | |
| let mut payer = ctx.escrows.get(&payer_key).unwrap(); | |
| payer.send(ctx, &mut reward_wallet, aggregator.read_charge)?; | |
| } | |
| Ok(aggregator.latest_confirmed_round) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment