pub fn compose_block_and_confirmation(
    latest_onchain_header: Header,
    top_call_hashes: Vec<H256>,
    shard: ShardIdentifier,
    state_hash_apriori: H256,
    state: &mut StfState,
) -> SgxResult<(OpaqueCall, SignedSidechainBlock)> {
    let signer_pair = ed25519::unseal_pair()?;
    let layer_one_head = latest_onchain_header.hash();

    let block_number = match Stf::get_sidechain_block_number(state) {
        Some(number) => number + 1,
        None => return Err(sgx_status_t::SGX_ERROR_UNEXPECTED),
    };
    Stf::update_sidechain_block_number(state, block_number);

    let block_number: u64 = block_number; //FIXME! Should be either u64 or u32! Not both..
    let parent_hash = match Stf::get_last_block_hash(state) {
        Some(hash) => hash,
        None => return Err(sgx_status_t::SGX_ERROR_UNEXPECTED),
    };
    // hash previous of state
    let state_hash_aposteriori = state::hash_of(state.state.clone())?;
    let state_update = state.state_diff.clone().encode();

    // create encrypted payload
    let mut payload: Vec<u8> =
        StatePayload::new(state_hash_apriori, state_hash_aposteriori, state_update).encode();
    aes::de_or_encrypt(&mut payload)?;

    let block = SidechainBlock::construct_block(
        signer_pair.public().into(),
        block_number,
        parent_hash,
        layer_one_head,
        shard,
        top_call_hashes,
        payload,
    );

    let signed_block = block.sign(&signer_pair);

    let block_hash = blake2_256(&block.encode());
    debug!("Block hash 0x{}", hex::encode_hex(&block_hash));
    Stf::update_last_block_hash(state, block_hash.into());

    let xt_block = [SUBSRATEE_REGISTRY_MODULE, BLOCK_CONFIRMED];
    let opaque_call =
        OpaqueCall((xt_block, shard, block_hash, state_hash_aposteriori.encode()).encode());
    Ok((opaque_call, signed_block))
}
/// Composes a sidechain block of a shard
Composes a sidechain block of a shard
Composes a sidechain block of a shard
pub fn compose_block_and_confirmation(
    latest_onchain_header: Header,
    top_call_hashes: Vec<H256>,
    shard: ShardIdentifier,
    state_hash_apriori: H256,
    state: &mut StfState,
) -> SgxResult<(OpaqueCall, SignedSidechainBlock)> {
    let signer_pair = ed25519::unseal_pair()?;
    let layer_one_head = latest_onchain_header.hash();
    let block_number = match Stf::get_sidechain_block_number(state) {
        Some(number) => number + 1,
        None => return Err(sgx_status_t::SGX_ERROR_UNEXPECTED),
    };
    Stf::update_sidechain_block_number(state, block_number);
    let block_number: u64 = block_number; //FIXME! Should be either u64 or u32! Not both..
    let parent_hash = match Stf::get_last_block_hash(state) {
        Some(hash) => hash,
        None => return Err(sgx_status_t::SGX_ERROR_UNEXPECTED),
    };
    // hash previous of state
    let state_hash_aposteriori = state::hash_of(state.state.clone())?;
    let state_update = state.state_diff.clone().encode();
    // create encrypted payload
    let mut payload: Vec<u8> =
        StatePayload::new(state_hash_apriori, state_hash_aposteriori, state_update).encode();
    aes::de_or_encrypt(&mut payload)?;
    let block = SidechainBlock::construct_block(
        signer_pair.public().into(),
        block_number,
        parent_hash,
        layer_one_head,
        shard,
        top_call_hashes,
        payload,
    );
    let signed_block = block.sign(&signer_pair);
    let block_hash = blake2_256(&block.encode());
    debug!("Block hash 0x{}", hex::encode_hex(&block_hash));
    Stf::update_last_block_hash(state, block_hash.into());
    let xt_block = [SUBSRATEE_REGISTRY_MODULE, BLOCK_CONFIRMED];
    let opaque_call =
        OpaqueCall((xt_block, shard, block_hash, state_hash_aposteriori.encode()).encode());
    Ok((opaque_call, signed_block))
}
pub fn compose_block_and_confirmation ( latest_onchain_header : Header , top_call_hashes : Vec < H256 > , shard : ShardIdentifier , state_hash_apriori : H256 , state : & mut StfState , ) -> SgxResult < ( OpaqueCall , SignedSidechainBlock ) > { let signer_pair = ed25519 :: unseal_pair ( ) ? ; let layer_one_head = latest_onchain_header . hash ( ) ; let block_number = match Stf :: get_sidechain_block_number ( state ) { Some ( number ) => number + 1 , None => return Err ( sgx_status_t :: SGX_ERROR_UNEXPECTED ) , } ; Stf :: update_sidechain_block_number ( state , block_number ) ; let block_number : u64 = block_number ; //FIXME! Should be either u64 or u32! Not both.. let parent_hash = match Stf :: get_last_block_hash ( state ) { Some ( hash ) => hash , None => return Err ( sgx_status_t :: SGX_ERROR_UNEXPECTED ) , } ; // hash previous of state let state_hash_aposteriori = state :: hash_of ( state . state . clone ( ) ) ? ; let state_update = state . state_diff . clone ( ) . encode ( ) ; // create encrypted payload let mut payload : Vec < u8 > = StatePayload :: new ( state_hash_apriori , state_hash_aposteriori , state_update ) . encode ( ) ; aes :: de_or_encrypt ( & mut payload ) ? ; let block = SidechainBlock :: construct_block ( signer_pair . public ( ) . into ( ) , block_number , parent_hash , layer_one_head , shard , top_call_hashes , payload , ) ; let signed_block = block . sign ( & signer_pair ) ; let block_hash = blake2_256 ( & block . encode ( ) ) ; debug ! ( " " hex encode_hex ( block_hash ) ) ; Stf :: update_last_block_hash ( state , block_hash . into ( ) ) ; let xt_block = [ SUBSRATEE_REGISTRY_MODULE , BLOCK_CONFIRMED ] ; let opaque_call = OpaqueCall ( ( xt_block , shard , block_hash , state_hash_aposteriori . encode ( ) ) . encode ( ) ) ; Ok ( ( opaque_call , signed_block ) ) }
Composes a sidechain block of a shard
Composes a sidechain block of a shard
latest_onchain_header
Header
top_call_hashes
Vec<H256>
shard
ShardIdentifier
state_hash_apriori
H256
state
&mut StfState
latest_onchain_header
Header
top_call_hashes
Vec<H256>
shard
ShardIdentifier
state_hash_apriori
H256
state
&mut StfState