fn add_bid(
        &mut self,
        public_key: PublicKey,
        delegation_rate: DelegationRate,
        amount: U512,
    ) -> Result<U512, Error> {
        let provided_account_hash = AccountHash::from_public_key(&public_key, |x| self.blake2b(x));

        if amount.is_zero() {
            return Err(Error::BondTooSmall);
        }

        if delegation_rate > DELEGATION_RATE_DENOMINATOR {
            return Err(Error::DelegationRateTooLarge);
        }

        if !self.is_allowed_session_caller(&provided_account_hash) {
            return Err(Error::InvalidContext);
        }

        let source = self.get_main_purse()?;

        let account_hash = AccountHash::from(&public_key);

        // Update bids or stakes
        let updated_amount = match self.read_bid(&account_hash)? {
            Some(mut bid) => {
                if bid.inactive() {
                    bid.activate();
                }
                self.mint_transfer_direct(
                    Some(PublicKey::System.to_account_hash()),
                    source,
                    *bid.bonding_purse(),
                    amount,
                    None,
                )
                .map_err(|_| Error::TransferToBidPurse)?
                .map_err(|_| Error::TransferToBidPurse)?;
                let updated_amount = bid
                    .with_delegation_rate(delegation_rate)
                    .increase_stake(amount)?;
                self.write_bid(account_hash, bid)?;
                updated_amount
            }
            None => {
                let bonding_purse = self.create_purse()?;
                self.mint_transfer_direct(
                    Some(PublicKey::System.to_account_hash()),
                    source,
                    bonding_purse,
                    amount,
                    None,
                )
                .map_err(|_| Error::TransferToBidPurse)?
                .map_err(|_| Error::TransferToBidPurse)?;
                let bid = Bid::unlocked(public_key, bonding_purse, amount, delegation_rate);
                self.write_bid(account_hash, bid)?;
                amount
            }
        };

        Ok(updated_amount)
    }
/// This entry point adds or modifies an entry in the `Key::Bid` section of the global state and
/// creates (or tops off) a bid purse. Post genesis, any new call on this entry point causes a
/// non-founding validator in the system to exist.
///
/// The logic works for both founding and non-founding validators, making it possible to adjust
/// their delegation rate and increase their stakes.
///
/// A validator with its bid inactive due to slashing can activate its bid again by increasing
/// its stake.
///
/// Validators cannot create a bid with 0 amount, and the delegation rate can't exceed
/// [`DELEGATION_RATE_DENOMINATOR`].
///
/// Returns a [`U512`] value indicating total amount of tokens staked for given `public_key`.
This entry point adds or modifies an entry in the `Key::Bid` section of the global state and
creates (or tops off) a bid purse. Post genesis, any new call on this entry point causes a
non-founding validator in the system to exist.

The logic works for both founding and non-founding validators, making it possible to adjust
their delegation rate and increase their stakes.

A validator with its bid inactive due to slashing can activate its bid again by increasing
its stake.

Validators cannot create a bid with 0 amount, and the delegation rate can't exceed
[`DELEGATION_RATE_DENOMINATOR`].

Returns a [`U512`] value indicating total amount of tokens staked for given `public_key`.
This entry point adds or modifies an entry in the ` Key :: Bid ` section of the global state and creates ( or tops off ) a bid purse . Post genesis any new call on this entry point causes a non - founding validator in the system to exist . The logic works for both founding and non - founding validators making it possible to adjust their delegation rate and increase their stakes . A validator with its bid inactive due to slashing can activate its bid again by increasing its stake . Validators cannot create a bid with 0 amount and the delegation rate can ' t exceed [ ` DELEGATION_RATE_DENOMINATOR ` ] . Returns a [ ` U512 ` ] value indicating total amount of tokens staked for given ` public_key ` .
fn add_bid(
        &mut self,
        public_key: PublicKey,
        delegation_rate: DelegationRate,
        amount: U512,
    ) -> Result<U512, Error> {
        let provided_account_hash = AccountHash::from_public_key(&public_key, |x| self.blake2b(x));
        if amount.is_zero() {
            return Err(Error::BondTooSmall);
        }
        if delegation_rate > DELEGATION_RATE_DENOMINATOR {
            return Err(Error::DelegationRateTooLarge);
        }
        if !self.is_allowed_session_caller(&provided_account_hash) {
            return Err(Error::InvalidContext);
        }
        let source = self.get_main_purse()?;
        let account_hash = AccountHash::from(&public_key);
        // Update bids or stakes
        let updated_amount = match self.read_bid(&account_hash)? {
            Some(mut bid) => {
                if bid.inactive() {
                    bid.activate();
                }
                self.mint_transfer_direct(
                    Some(PublicKey::System.to_account_hash()),
                    source,
                    *bid.bonding_purse(),
                    amount,
                    None,
                )
                .map_err(|_| Error::TransferToBidPurse)?
                .map_err(|_| Error::TransferToBidPurse)?;
                let updated_amount = bid
                    .with_delegation_rate(delegation_rate)
                    .increase_stake(amount)?;
                self.write_bid(account_hash, bid)?;
                updated_amount
            }
            None => {
                let bonding_purse = self.create_purse()?;
                self.mint_transfer_direct(
                    Some(PublicKey::System.to_account_hash()),
                    source,
                    bonding_purse,
                    amount,
                    None,
                )
                .map_err(|_| Error::TransferToBidPurse)?
                .map_err(|_| Error::TransferToBidPurse)?;
                let bid = Bid::unlocked(public_key, bonding_purse, amount, delegation_rate);
                self.write_bid(account_hash, bid)?;
                amount
            }
        };
        Ok(updated_amount)
    }
fn add_bid ( & mut self , public_key : PublicKey , delegation_rate : DelegationRate , amount : U512 , ) -> Result < U512 , Error > { let provided_account_hash = AccountHash :: from_public_key ( & public_key , | x | self . blake2b ( x ) ) ; if amount . is_zero ( ) { return Err ( Error :: BondTooSmall ) ; } if delegation_rate > DELEGATION_RATE_DENOMINATOR { return Err ( Error :: DelegationRateTooLarge ) ; } if ! self . is_allowed_session_caller ( & provided_account_hash ) { return Err ( Error :: InvalidContext ) ; } let source = self . get_main_purse ( ) ? ; let account_hash = AccountHash :: from ( & public_key ) ; // Update bids or stakes let updated_amount = match self . read_bid ( & account_hash ) ? { Some ( mut bid ) => { if bid . inactive ( ) { bid . activate ( ) ; } self . mint_transfer_direct ( Some ( PublicKey :: System . to_account_hash ( ) ) , source , * bid . bonding_purse ( ) , amount , None , ) . map_err ( | _ | Error :: TransferToBidPurse ) ? . map_err ( | _ | Error :: TransferToBidPurse ) ? ; let updated_amount = bid . with_delegation_rate ( delegation_rate ) . increase_stake ( amount ) ? ; self . write_bid ( account_hash , bid ) ? ; updated_amount } None => { let bonding_purse = self . create_purse ( ) ? ; self . mint_transfer_direct ( Some ( PublicKey :: System . to_account_hash ( ) ) , source , bonding_purse , amount , None , ) . map_err ( | _ | Error :: TransferToBidPurse ) ? . map_err ( | _ | Error :: TransferToBidPurse ) ? ; let bid = Bid :: unlocked ( public_key , bonding_purse , amount , delegation_rate ) ; self . write_bid ( account_hash , bid ) ? ; amount } } ; Ok ( updated_amount ) }
This entry point adds or modifies an entry in the `Key::Bid` section of the global state and
creates (or tops off) a bid purse.
This entry point adds or modifies an entry in the ` Key :: Bid ` section of the global state and creates ( or tops off ) a bid purse .
&mut self
public_key
PublicKey
delegation_rate
DelegationRate
amount
U512
&mut self
public_key
PublicKey
delegation_rate
DelegationRate
amount
U512