module Block { resource T { // Height of the current block height: u64, } // This can only be invoked by the Association address, and only a single time. // Currently, it is invoked in the genesis transaction public initialize() { // Only callable by the Association address assert(get_txn_sender() == 0xA550C18, 1); move_to_sender(T { height: 0 }); return; } // Set the metadata for the current block. // The runtime always runs this before executing the transactions in a block. // TODO: make this private, support other metadata public prologue(height: u64) acquires T { let height_ref: &mut u64; let old_height: u64; height_ref = &mut borrow_global_mut(0xA550C18).height; old_height = *copy(height_ref); // ensure that height increases by 1 if (move(height) == copy(old_height) + 1) { *move(height_ref) = move(old_height) + 1; return; } else { // TODO: standardize this error code abort(99); } } // Get the current block height public get_current_height(): u64 acquires T { return *&(borrow_global(0xA550C18)).height; } }