fn add_payment_with_timestamp(
        &mut self,
        memo: Memo,
        payment: Transfer,
        created_at_time: Option<TimeStamp>,
        now: TimeStamp,
    ) -> Result<(BlockHeight, HashOf<EncodedBlock>), String> {
        self.purge_old_transactions(now);

        let created_at_time = created_at_time.unwrap_or(now);

        if created_at_time + self.transaction_window < now {
            return Err("Rejecting expired transaction.".to_owned());
        }

        if created_at_time > now + ic_types::ingress::PERMITTED_DRIFT {
            return Err("Rejecting transaction with timestamp in the future.".to_owned());
        }

        let transaction = Transaction {
            transfer: payment.clone(),
            memo,
            created_at_time,
        };

        let transaction_hash = transaction.hash();

        if self.transactions_by_hash.contains_key(&transaction_hash) {
            return Err("Transaction already exists on chain.".to_owned());
        }

        let block = Block::new_from_transaction(self.blockchain.last_hash, transaction, now);
        let block_timestamp = block.timestamp;

        self.balances.add_payment(&payment);

        let height = self.blockchain.add_block(block)?;

        self.transactions_by_hash.insert(transaction_hash, height);
        self.transactions_by_height.push_back(TransactionInfo {
            block_timestamp,
            transaction_hash,
        });

        let to_trim = if self.balances.store.len()
            >= self.maximum_number_of_accounts + self.accounts_overflow_trim_quantity
        {
            self.balances
                .select_accounts_to_trim(self.accounts_overflow_trim_quantity)
        } else {
            vec![]
        };

        for (balance, account) in to_trim {
            let transfer = Transfer::Burn {
                from: account,
                amount: balance,
            };
            self.balances.add_payment(&transfer);
            self.blockchain
                .add_block(Block::new_from_transaction(
                    self.blockchain.last_hash,
                    Transaction {
                        transfer,
                        memo: Memo::default(),
                        created_at_time: now,
                    },
                    now,
                ))
                .unwrap();
        }

        Ok((height, self.blockchain.last_hash.unwrap()))
    }
/// Internal version of `add_payment` that takes a timestamp, for
/// testing.
Internal version of `add_payment` that takes a timestamp, for
testing.
Internal version of ` add_payment ` that takes a timestamp for testing .
fn add_payment_with_timestamp(
        &mut self,
        memo: Memo,
        payment: Transfer,
        created_at_time: Option<TimeStamp>,
        now: TimeStamp,
    ) -> Result<(BlockHeight, HashOf<EncodedBlock>), String> {
        self.purge_old_transactions(now);
        let created_at_time = created_at_time.unwrap_or(now);
        if created_at_time + self.transaction_window < now {
            return Err("Rejecting expired transaction.".to_owned());
        }
        if created_at_time > now + ic_types::ingress::PERMITTED_DRIFT {
            return Err("Rejecting transaction with timestamp in the future.".to_owned());
        }
        let transaction = Transaction {
            transfer: payment.clone(),
            memo,
            created_at_time,
        };
        let transaction_hash = transaction.hash();
        if self.transactions_by_hash.contains_key(&transaction_hash) {
            return Err("Transaction already exists on chain.".to_owned());
        }
        let block = Block::new_from_transaction(self.blockchain.last_hash, transaction, now);
        let block_timestamp = block.timestamp;
        self.balances.add_payment(&payment);
        let height = self.blockchain.add_block(block)?;
        self.transactions_by_hash.insert(transaction_hash, height);
        self.transactions_by_height.push_back(TransactionInfo {
            block_timestamp,
            transaction_hash,
        });
        let to_trim = if self.balances.store.len()
            >= self.maximum_number_of_accounts + self.accounts_overflow_trim_quantity
        {
            self.balances
                .select_accounts_to_trim(self.accounts_overflow_trim_quantity)
        } else {
            vec![]
        };
        for (balance, account) in to_trim {
            let transfer = Transfer::Burn {
                from: account,
                amount: balance,
            };
            self.balances.add_payment(&transfer);
            self.blockchain
                .add_block(Block::new_from_transaction(
                    self.blockchain.last_hash,
                    Transaction {
                        transfer,
                        memo: Memo::default(),
                        created_at_time: now,
                    },
                    now,
                ))
                .unwrap();
        }
        Ok((height, self.blockchain.last_hash.unwrap()))
    }
fn add_payment_with_timestamp ( & mut self , memo : Memo , payment : Transfer , created_at_time : Option < TimeStamp > , now : TimeStamp , ) -> Result < ( BlockHeight , HashOf < EncodedBlock > ) , String > { self . purge_old_transactions ( now ) ; let created_at_time = created_at_time . unwrap_or ( now ) ; if created_at_time + self . transaction_window < now { return Err ( " " . to_owned ( ) ) ; } if created_at_time > now + ic_types :: ingress :: PERMITTED_DRIFT { return Err ( " " . to_owned ( ) ) ; } let transaction = Transaction { transfer : payment . clone ( ) , memo , created_at_time , } ; let transaction_hash = transaction . hash ( ) ; if self . transactions_by_hash . contains_key ( & transaction_hash ) { return Err ( " " . to_owned ( ) ) ; } let block = Block :: new_from_transaction ( self . blockchain . last_hash , transaction , now ) ; let block_timestamp = block . timestamp ; self . balances . add_payment ( & payment ) ; let height = self . blockchain . add_block ( block ) ? ; self . transactions_by_hash . insert ( transaction_hash , height ) ; self . transactions_by_height . push_back ( TransactionInfo { block_timestamp , transaction_hash , } ) ; let to_trim = if self . balances . store . len ( ) >= self . maximum_number_of_accounts + self . accounts_overflow_trim_quantity { self . balances . select_accounts_to_trim ( self . accounts_overflow_trim_quantity ) } else { vec ! [ ] } ; for ( balance , account ) in to_trim { let transfer = Transfer :: Burn { from : account , amount : balance , } ; self . balances . add_payment ( & transfer ) ; self . blockchain . add_block ( Block :: new_from_transaction ( self . blockchain . last_hash , Transaction { transfer , memo : Memo :: default ( ) , created_at_time : now , } , now , ) ) . unwrap ( ) ; } Ok ( ( height , self . blockchain . last_hash . unwrap ( ) ) ) }
Internal version of `add_payment` that takes a timestamp, for
testing.
Internal version of ` add_payment ` that takes a timestamp for testing .
&mut self
memo
Memo
payment
Transfer
created_at_time
Option<TimeStamp>
now
TimeStamp
&mut self
memo
Memo
payment
Transfer
created_at_time
Option<TimeStamp>
now
TimeStamp