I have got a mystery that I decide to reuse produced lasthash for the next block without any Copy or Clone because of high safe code(because I think if we used Copy and Clone afterward the Blockchain will be Hk by DoubleXpends or OverXpend). I used Rc<RefCell> but I have got this error:
(followed lines:
refered1_base_maked_block.prev_block_hash,
refered1_base_maked_block.option_transactions,)
I can preceded lines solve by adding new Rc<RefCell for two types but I do not want do it.
I'm stuck in a loop repeating this puzzle for all non-primitives types!
What is solution instead of using Clone?
cannot move out of dereference of `RefMut<'_, library_blockchain::Block>`
move occurs because value has type `Vec<OptionTransaction>`, which does not implement the `Copy` trait
//-------------Making Block
let mut base_maked_block: Rc<RefCell<Block>> = Rc::new(RefCell::new(
Block::new(i as u32, now(), last_hash.to_vec(), maked_transaction, difficulty)
));
let mut refered1_base_maked_block=base_maked_block.borrow_mut();
refered1_base_maked_block.mine();
let refered1_block=Block::new(
refered1_base_maked_block.index,
refered1_base_maked_block.timestamp,
refered1_base_maked_block.prev_block_hash,
refered1_base_maked_block.option_transactions,
refered1_base_maked_block.difficulty
);
let b=*refered1_base_maked_block;
blockchain.update_with_block(b).expect("\n\nFailed to add genesis block");
let refered2_base_maked_block=base_maked_block.borrow();
last_hash =refered2_base_maked_block.prev_block_hash.to_vec().into_boxed_slice();
println!("**last hash new:**\n{:?}\n",&last_hash);
Types:
pub struct Block {
pub index: u32,
pub timestamp: u128,
pub hash: Hash,
pub prev_block_hash: Hash,
pub nonce: u64,
pub option_transactions: Vec<OptionTransaction>,
pub difficulty: u128,
}