in fastpay_core/src/authority.rs [232:258]
fn handle_primary_synchronization_order(
&mut self,
order: PrimarySynchronizationOrder,
) -> Result<AccountInfoResponse, FastPayError> {
// Update recipient state; note that the blockchain client is trusted.
let recipient = order.recipient;
fp_ensure!(self.in_shard(&recipient), FastPayError::WrongShard);
let recipient_account = self
.accounts
.entry(recipient)
.or_insert_with(AccountOffchainState::new);
if order.transaction_index <= self.last_transaction_index {
// Ignore old transaction index.
return Ok(recipient_account.make_account_info(recipient));
}
fp_ensure!(
order.transaction_index == self.last_transaction_index.increment()?,
FastPayError::UnexpectedTransactionIndex
);
let recipient_balance = recipient_account.balance.try_add(order.amount.into())?;
let last_transaction_index = self.last_transaction_index.increment()?;
recipient_account.balance = recipient_balance;
recipient_account.synchronization_log.push(order);
self.last_transaction_index = last_transaction_index;
Ok(recipient_account.make_account_info(recipient))
}