pub fn verify_and_store(&self,
                            tx_index:     &mut TxIndex,
                            tx_store:     &mut store::Transactions,
                            initial_sync: bool,
                            hash:         Hash32) -> TransactionResult<TransactionOk> {

        let mut stats: TransactionStats = Default::default();

        let p0 = Instant::now();

        self.verify_syntax()?;

        // store
        let ptr      = tx_store.write(self);

        if initial_sync {

            assert!(tx_index.set(hash, ptr, &[], true));

            return Ok(TransactionOk::VerifiedAndStored {ptr: ptr, stats: stats })

        }


        let p1 = Instant::now();
        stats.store_tx += p1 - p0;

        self.verify_input_scripts(tx_index, tx_store, ptr, &mut stats)?;

        let mut existing_ptrs = vec![];

        loop {

            let p2 = Instant::now();

            // Store reference in the hash_index.
            // This may fail if the tx is already in or if there are dependent transactions in
            // that are "guarding" this one.
            if tx_index.set(hash, ptr, &existing_ptrs, false) {

                let p3 = Instant::now();
                stats.store_tx_idx += p3 - p2;

                return Ok(TransactionOk::VerifiedAndStored {ptr: ptr, stats: stats })
            }
            else {

                let p3 = Instant::now();
                stats.store_tx_idx += p3 - p2;

                // First see if it already exists
                existing_ptrs = tx_index.get(hash);

                if existing_ptrs
                    .iter()
                    .any(|p| !p.is_guard()) {
                    assert_eq!(existing_ptrs.len(), 1);

                    return Ok(TransactionOk::AlreadyExists { ptr: existing_ptrs[0] })
                }

                // existing_ptrs (if any) are now inputs that are waiting for this transactions
                // they need to be verified
                self.verify_backtracking_outputs(tx_store, &existing_ptrs);

                let p4 = Instant::now();
                stats.backtracking += p4 - p3;

            }
        }

    }
/// Verifies and stores the transaction in the transaction_store and index
Verifies and stores the transaction in the transaction_store and index
Verifies and stores the transaction in the transaction_store and index
pub fn verify_and_store(&self,
                            tx_index:     &mut TxIndex,
                            tx_store:     &mut store::Transactions,
                            initial_sync: bool,
                            hash:         Hash32) -> TransactionResult<TransactionOk> {
        let mut stats: TransactionStats = Default::default();
        let p0 = Instant::now();
        self.verify_syntax()?;
        // store
        let ptr      = tx_store.write(self);
        if initial_sync {
            assert!(tx_index.set(hash, ptr, &[], true));
            return Ok(TransactionOk::VerifiedAndStored {ptr: ptr, stats: stats })
        }
        let p1 = Instant::now();
        stats.store_tx += p1 - p0;
        self.verify_input_scripts(tx_index, tx_store, ptr, &mut stats)?;
        let mut existing_ptrs = vec![];
        loop {
            let p2 = Instant::now();
            // Store reference in the hash_index.
            // This may fail if the tx is already in or if there are dependent transactions in
            // that are "guarding" this one.
            if tx_index.set(hash, ptr, &existing_ptrs, false) {
                let p3 = Instant::now();
                stats.store_tx_idx += p3 - p2;
                return Ok(TransactionOk::VerifiedAndStored {ptr: ptr, stats: stats })
            }
            else {
                let p3 = Instant::now();
                stats.store_tx_idx += p3 - p2;
                // First see if it already exists
                existing_ptrs = tx_index.get(hash);
                if existing_ptrs
                    .iter()
                    .any(|p| !p.is_guard()) {
                    assert_eq!(existing_ptrs.len(), 1);
                    return Ok(TransactionOk::AlreadyExists { ptr: existing_ptrs[0] })
                }
                // existing_ptrs (if any) are now inputs that are waiting for this transactions
                // they need to be verified
                self.verify_backtracking_outputs(tx_store, &existing_ptrs);
                let p4 = Instant::now();
                stats.backtracking += p4 - p3;
            }
        }
    }
pub fn verify_and_store ( & self , tx_index : & mut TxIndex , tx_store : & mut store :: Transactions , initial_sync : bool , hash : Hash32 ) -> TransactionResult < TransactionOk > { let mut stats : TransactionStats = Default :: default ( ) ; let p0 = Instant :: now ( ) ; self . verify_syntax ( ) ? ; // store let ptr = tx_store . write ( self ) ; if initial_sync { assert ! ( tx_index set ( hash ptr [ ] true ) ) ; return Ok ( TransactionOk :: VerifiedAndStored { ptr : ptr , stats : stats } ) } let p1 = Instant :: now ( ) ; stats . store_tx += p1 - p0 ; self . verify_input_scripts ( tx_index , tx_store , ptr , & mut stats ) ? ; let mut existing_ptrs = vec ! [ ] ; loop { let p2 = Instant :: now ( ) ; // Store reference in the hash_index. // This may fail if the tx is already in or if there are dependent transactions in // that are "guarding" this one. if tx_index . set ( hash , ptr , & existing_ptrs , false ) { let p3 = Instant :: now ( ) ; stats . store_tx_idx += p3 - p2 ; return Ok ( TransactionOk :: VerifiedAndStored { ptr : ptr , stats : stats } ) } else { let p3 = Instant :: now ( ) ; stats . store_tx_idx += p3 - p2 ; // First see if it already exists existing_ptrs = tx_index . get ( hash ) ; if existing_ptrs . iter ( ) . any ( | p | ! p . is_guard ( ) ) { assert_eq ! ( existing_ptrs len ( ) 1 ) ; return Ok ( TransactionOk :: AlreadyExists { ptr : existing_ptrs [ 0 ] } ) } // existing_ptrs (if any) are now inputs that are waiting for this transactions // they need to be verified self . verify_backtracking_outputs ( tx_store , & existing_ptrs ) ; let p4 = Instant :: now ( ) ; stats . backtracking += p4 - p3 ; } } }
Verifies and stores the transaction in the transaction_store and index
Verifies and stores the transaction in the transaction_store and index
&self
tx_index
&mut TxIndex
tx_store
&mut store::Transactions
initial_sync
bool
hash
Hash32
&self
tx_index
&mut TxIndex
tx_store
&mut store::Transactions
initial_sync
bool
hash
Hash32