pub fn future_result(
        &mut self,
        chain: &Chain,
        futures: GenerateFuture,
    ) -> Option<(Block, Vec<TxVerifiable>)> {
        // wait threads finish
        let mut mined = None;
        for (result, worker) in futures.get() {
            // note: ignore if already mined block found
            if mined.is_none() {
                let flag = worker.get_flag().clone();

                match result {
                    WorkerResult::PoW((work_hash, coinbase, bytes)) => {
                        // generate block
                        let (bias,) = self.new_block_info.get(&flag).cloned().unwrap();
                        let header = BlockHeader::from_bytes(bytes.as_ref());
                        let txs_len = self.unconfirmed.txs.len() + 1;
                        let mut txs_hash = Vec::with_capacity(txs_len);
                        let coinbase_hash = U256::from(coinbase.hash().as_slice());
                        txs_hash.push(coinbase_hash.clone());
                        txs_hash.extend_from_slice(&self.unconfirmed.txs);
                        assert_eq!(header.merkleroot, calc_merkleroot_hash(txs_hash.clone()));
                        let block = Block::new(work_hash, self.height, flag, bias, header, txs_hash);

                        // don't need to generate signature
                        // note: PoW coinbase don't have signature and input

                        // generate txs
                        let coinbase = TxVerifiable {
                            hash: coinbase_hash,
                            body: coinbase,
                            signature: vec![],
                            inputs_cache: vec![],
                        };
                        let txs = self.unconfirmed.get_mining_block_txs(coinbase, &chain.tables);

                        // success
                        mined = Some((block, txs));
                    },
                    WorkerResult::PoS((work_hash, coinbase, mut header, amount)) => {
                        // generate block
                        let (bias,) = self.new_block_info.get(&flag).cloned().unwrap();
                        let txs_len = self.unconfirmed.txs.len() + 1;
                        let mut txs_hash = Vec::with_capacity(txs_len);
                        let coinbase_hash = U256::from(coinbase.hash().as_slice());
                        txs_hash.push(coinbase_hash.clone());
                        txs_hash.extend_from_slice(&self.unconfirmed.txs);
                        header.merkleroot = calc_merkleroot_hash(txs_hash.clone());
                        let block = Block::new(work_hash, self.height, flag, bias, header, txs_hash);

                        // generate signature
                        // note: staking signature is header's not tx's
                        let mut output_of_input = coinbase.outputs[0].clone();
                        output_of_input.2 = amount;
                        let signature = chain
                            .account
                            .get_single_sign_by_addr(&output_of_input.0, block.header.to_bytes().as_ref())
                            .expect("generate signature for PoS mining");

                        // generate txs
                        let coinbase = TxVerifiable {
                            hash: coinbase_hash,
                            body: coinbase,
                            signature: vec![signature],
                            inputs_cache: vec![output_of_input],
                        };
                        let txs = self.unconfirmed.get_mining_block_txs(coinbase, &chain.tables);

                        // success
                        mined = Some((block, txs));
                    },
                    WorkerResult::PoC((work_hash, mut header, plot)) => {
                        // generate coinbase
                        let coinbase = TxBody {
                            version: 0,
                            txtype: TxType::PoS,
                            time: header.time,
                            deadline: header.time + 10800,
                            inputs: vec![],
                            outputs: vec![TxOutput(plot.addr, 0, self.reward)],
                            gas_price: 0,
                            gas_amount: 0,
                            message: TxMessage::Nothing,
                        };

                        // generate block
                        let (bias,) = self.new_block_info.get(&flag).cloned().unwrap();
                        let txs_len = self.unconfirmed.txs.len() + 1;
                        let mut txs_hash = Vec::with_capacity(txs_len);
                        let coinbase_hash = U256::from(coinbase.hash().as_slice());
                        txs_hash.push(coinbase_hash.clone());
                        txs_hash.extend_from_slice(&self.unconfirmed.txs);
                        header.merkleroot = calc_merkleroot_hash(txs_hash.clone());
                        let block = Block::new(work_hash, self.height, flag, bias, header, txs_hash);

                        // generate signature
                        // note: staking signature is header's not tx's
                        let signature = chain
                            .account
                            .get_single_sign_by_addr(&plot.addr, block.header.to_bytes().as_ref())
                            .expect("generate signature for PoC mining");

                        // generate txs
                        let coinbase = TxVerifiable {
                            hash: coinbase_hash,
                            body: coinbase,
                            signature: vec![signature],
                            inputs_cache: vec![],
                        };
                        let txs = self.unconfirmed.get_mining_block_txs(coinbase, &chain.tables);

                        // success
                        mined = Some((block, txs));
                    },
                    WorkerResult::NotFoundWork => (),
                }
            }

            // return worker
            self.threads.push(worker);
        }

        // success
        mined
    }
/// get result from future and get new block
get result from future and get new block
get result from future and get new block
pub fn future_result(
        &mut self,
        chain: &Chain,
        futures: GenerateFuture,
    ) -> Option<(Block, Vec<TxVerifiable>)> {
        // wait threads finish
        let mut mined = None;
        for (result, worker) in futures.get() {
            // note: ignore if already mined block found
            if mined.is_none() {
                let flag = worker.get_flag().clone();
                match result {
                    WorkerResult::PoW((work_hash, coinbase, bytes)) => {
                        // generate block
                        let (bias,) = self.new_block_info.get(&flag).cloned().unwrap();
                        let header = BlockHeader::from_bytes(bytes.as_ref());
                        let txs_len = self.unconfirmed.txs.len() + 1;
                        let mut txs_hash = Vec::with_capacity(txs_len);
                        let coinbase_hash = U256::from(coinbase.hash().as_slice());
                        txs_hash.push(coinbase_hash.clone());
                        txs_hash.extend_from_slice(&self.unconfirmed.txs);
                        assert_eq!(header.merkleroot, calc_merkleroot_hash(txs_hash.clone()));
                        let block = Block::new(work_hash, self.height, flag, bias, header, txs_hash);
                        // don't need to generate signature
                        // note: PoW coinbase don't have signature and input
                        // generate txs
                        let coinbase = TxVerifiable {
                            hash: coinbase_hash,
                            body: coinbase,
                            signature: vec![],
                            inputs_cache: vec![],
                        };
                        let txs = self.unconfirmed.get_mining_block_txs(coinbase, &chain.tables);
                        // success
                        mined = Some((block, txs));
                    },
                    WorkerResult::PoS((work_hash, coinbase, mut header, amount)) => {
                        // generate block
                        let (bias,) = self.new_block_info.get(&flag).cloned().unwrap();
                        let txs_len = self.unconfirmed.txs.len() + 1;
                        let mut txs_hash = Vec::with_capacity(txs_len);
                        let coinbase_hash = U256::from(coinbase.hash().as_slice());
                        txs_hash.push(coinbase_hash.clone());
                        txs_hash.extend_from_slice(&self.unconfirmed.txs);
                        header.merkleroot = calc_merkleroot_hash(txs_hash.clone());
                        let block = Block::new(work_hash, self.height, flag, bias, header, txs_hash);
                        // generate signature
                        // note: staking signature is header's not tx's
                        let mut output_of_input = coinbase.outputs[0].clone();
                        output_of_input.2 = amount;
                        let signature = chain
                            .account
                            .get_single_sign_by_addr(&output_of_input.0, block.header.to_bytes().as_ref())
                            .expect("generate signature for PoS mining");
                        // generate txs
                        let coinbase = TxVerifiable {
                            hash: coinbase_hash,
                            body: coinbase,
                            signature: vec![signature],
                            inputs_cache: vec![output_of_input],
                        };
                        let txs = self.unconfirmed.get_mining_block_txs(coinbase, &chain.tables);
                        // success
                        mined = Some((block, txs));
                    },
                    WorkerResult::PoC((work_hash, mut header, plot)) => {
                        // generate coinbase
                        let coinbase = TxBody {
                            version: 0,
                            txtype: TxType::PoS,
                            time: header.time,
                            deadline: header.time + 10800,
                            inputs: vec![],
                            outputs: vec![TxOutput(plot.addr, 0, self.reward)],
                            gas_price: 0,
                            gas_amount: 0,
                            message: TxMessage::Nothing,
                        };
                        // generate block
                        let (bias,) = self.new_block_info.get(&flag).cloned().unwrap();
                        let txs_len = self.unconfirmed.txs.len() + 1;
                        let mut txs_hash = Vec::with_capacity(txs_len);
                        let coinbase_hash = U256::from(coinbase.hash().as_slice());
                        txs_hash.push(coinbase_hash.clone());
                        txs_hash.extend_from_slice(&self.unconfirmed.txs);
                        header.merkleroot = calc_merkleroot_hash(txs_hash.clone());
                        let block = Block::new(work_hash, self.height, flag, bias, header, txs_hash);
                        // generate signature
                        // note: staking signature is header's not tx's
                        let signature = chain
                            .account
                            .get_single_sign_by_addr(&plot.addr, block.header.to_bytes().as_ref())
                            .expect("generate signature for PoC mining");
                        // generate txs
                        let coinbase = TxVerifiable {
                            hash: coinbase_hash,
                            body: coinbase,
                            signature: vec![signature],
                            inputs_cache: vec![],
                        };
                        let txs = self.unconfirmed.get_mining_block_txs(coinbase, &chain.tables);
                        // success
                        mined = Some((block, txs));
                    },
                    WorkerResult::NotFoundWork => (),
                }
            }
            // return worker
            self.threads.push(worker);
        }
        // success
        mined
    }
pub fn future_result ( & mut self , chain : & Chain , futures : GenerateFuture , ) -> Option < ( Block , Vec < TxVerifiable > ) > { // wait threads finish let mut mined = None ; for ( result , worker ) in futures . get ( ) { // note: ignore if already mined block found if mined . is_none ( ) { let flag = worker . get_flag ( ) . clone ( ) ; match result { WorkerResult :: PoW ( ( work_hash , coinbase , bytes ) ) => { // generate block let ( bias , ) = self . new_block_info . get ( & flag ) . cloned ( ) . unwrap ( ) ; let header = BlockHeader :: from_bytes ( bytes . as_ref ( ) ) ; let txs_len = self . unconfirmed . txs . len ( ) + 1 ; let mut txs_hash = Vec :: with_capacity ( txs_len ) ; let coinbase_hash = U256 :: from ( coinbase . hash ( ) . as_slice ( ) ) ; txs_hash . push ( coinbase_hash . clone ( ) ) ; txs_hash . extend_from_slice ( & self . unconfirmed . txs ) ; assert_eq ! ( header merkleroot calc_merkleroot_hash ( txs_hash clone ( ) ) ) ; let block = Block :: new ( work_hash , self . height , flag , bias , header , txs_hash ) ; // don't need to generate signature // note: PoW coinbase don't have signature and input // generate txs let coinbase = TxVerifiable { hash : coinbase_hash , body : coinbase , signature : vec ! [ ] , inputs_cache : vec ! [ ] , } ; let txs = self . unconfirmed . get_mining_block_txs ( coinbase , & chain . tables ) ; // success mined = Some ( ( block , txs ) ) ; } , WorkerResult :: PoS ( ( work_hash , coinbase , mut header , amount ) ) => { // generate block let ( bias , ) = self . new_block_info . get ( & flag ) . cloned ( ) . unwrap ( ) ; let txs_len = self . unconfirmed . txs . len ( ) + 1 ; let mut txs_hash = Vec :: with_capacity ( txs_len ) ; let coinbase_hash = U256 :: from ( coinbase . hash ( ) . as_slice ( ) ) ; txs_hash . push ( coinbase_hash . clone ( ) ) ; txs_hash . extend_from_slice ( & self . unconfirmed . txs ) ; header . merkleroot = calc_merkleroot_hash ( txs_hash . clone ( ) ) ; let block = Block :: new ( work_hash , self . height , flag , bias , header , txs_hash ) ; // generate signature // note: staking signature is header's not tx's let mut output_of_input = coinbase . outputs [ 0 ] . clone ( ) ; output_of_input . 2 = amount ; let signature = chain . account . get_single_sign_by_addr ( & output_of_input . 0 , block . header . to_bytes ( ) . as_ref ( ) ) . expect ( " " ) ; // generate txs let coinbase = TxVerifiable { hash : coinbase_hash , body : coinbase , signature : vec ! [ signature ] , inputs_cache : vec ! [ output_of_input ] , } ; let txs = self . unconfirmed . get_mining_block_txs ( coinbase , & chain . tables ) ; // success mined = Some ( ( block , txs ) ) ; } , WorkerResult :: PoC ( ( work_hash , mut header , plot ) ) => { // generate coinbase let coinbase = TxBody { version : 0 , txtype : TxType :: PoS , time : header . time , deadline : header . time + 10800 , inputs : vec ! [ ] , outputs : vec ! [ TxOutput ( plot addr 0 self reward ) ] , gas_price : 0 , gas_amount : 0 , message : TxMessage :: Nothing , } ; // generate block let ( bias , ) = self . new_block_info . get ( & flag ) . cloned ( ) . unwrap ( ) ; let txs_len = self . unconfirmed . txs . len ( ) + 1 ; let mut txs_hash = Vec :: with_capacity ( txs_len ) ; let coinbase_hash = U256 :: from ( coinbase . hash ( ) . as_slice ( ) ) ; txs_hash . push ( coinbase_hash . clone ( ) ) ; txs_hash . extend_from_slice ( & self . unconfirmed . txs ) ; header . merkleroot = calc_merkleroot_hash ( txs_hash . clone ( ) ) ; let block = Block :: new ( work_hash , self . height , flag , bias , header , txs_hash ) ; // generate signature // note: staking signature is header's not tx's let signature = chain . account . get_single_sign_by_addr ( & plot . addr , block . header . to_bytes ( ) . as_ref ( ) ) . expect ( " " ) ; // generate txs let coinbase = TxVerifiable { hash : coinbase_hash , body : coinbase , signature : vec ! [ signature ] , inputs_cache : vec ! [ ] , } ; let txs = self . unconfirmed . get_mining_block_txs ( coinbase , & chain . tables ) ; // success mined = Some ( ( block , txs ) ) ; } , WorkerResult :: NotFoundWork => ( ) , } } // return worker self . threads . push ( worker ) ; } // success mined }
get result from future and get new block
get result from future and get new block
&mut self
chain
&Chain
futures
GenerateFuture
&mut self
chain
&Chain
futures
GenerateFuture