Skip to content

Commit

Permalink
[move] Patch locked deposits (0LNetworkCommunity#100)
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com>
  • Loading branch information
sirouk and 0o-de-lally committed Aug 16, 2024
1 parent d8d46ae commit bd7e865
Show file tree
Hide file tree
Showing 22 changed files with 464 additions and 457 deletions.
18 changes: 8 additions & 10 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// This module defines a struct storing the metadata of the block and new block events.
module diem_framework::block {
use std::error;
use std::features;
use std::vector;
use std::option;

Expand All @@ -12,7 +11,6 @@ module diem_framework::block {
use diem_framework::state_storage;
use diem_framework::system_addresses;
use diem_framework::timestamp;
use diem_framework::transaction_fee;
// use diem_std::debug::print;

//////// 0L ////////
Expand Down Expand Up @@ -141,14 +139,14 @@ module diem_framework::block {
};
emit_new_block_event(&vm, &mut block_metadata_ref.new_block_events, new_block_event);

if (features::collect_and_distribute_gas_fees()) {
// Assign the fees collected from the previous block to the previous block proposer.
// If for any reason the fees cannot be assigned, this function burns the collected coins.
transaction_fee::process_collected_fees();
// Set the proposer of this block as the receiver of the fees, so that the fees for this
// block are assigned to the right account.
transaction_fee::register_proposer_for_fee_collection(proposer);
};
// if (features::collect_and_distribute_gas_fees()) {
// // Assign the fees collected from the previous block to the previous block proposer.
// // If for any reason the fees cannot be assigned, this function burns the collected coins.
// transaction_fee::process_collected_fees();
// // Set the proposer of this block as the receiver of the fees, so that the fees for this
// // block are assigned to the right account.
// transaction_fee::register_proposer_for_fee_collection(proposer);
// };

// Performance scores have to be updated before the epoch transition as the transaction that triggers the
// transition is the last block in the previous epoch.
Expand Down
48 changes: 1 addition & 47 deletions framework/libra-framework/sources/modified_source/coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module diem_framework::coin {
use std::error;
use std::option::{Self, Option};
use std::signer;
use std::fixed_point32;

use diem_framework::account::{Self, WithdrawCapability};
use diem_framework::aggregator_factory;
Expand All @@ -14,15 +13,13 @@ module diem_framework::coin {
use diem_framework::system_addresses;

use diem_std::type_info;
use diem_std::math64;
// use diem_std::debug::print;

friend ol_framework::gas_coin;
friend ol_framework::burn;
friend ol_framework::ol_account;
friend diem_framework::genesis;
friend diem_framework::genesis_migration;
friend ol_framework::rewards;
friend diem_framework::transaction_fee;


Expand Down Expand Up @@ -241,58 +238,15 @@ module diem_framework::coin {
type_info::account_address(&type_info)
}

#[view]
// #[view]
/// Returns the balance of `owner` for provided `CoinType`.
public fun balance<CoinType>(owner: address): u64 acquires CoinStore {
// should not abort if the VM might call this
if (!is_account_registered<CoinType>(owner)) return 0;
borrow_global<CoinStore<CoinType>>(owner).coin.value
}

#[view]
/// Returns a human readable version of the balance with (integer, decimal_part)
public fun balance_human<CoinType>(owner: address): (u64, u64) acquires CoinStore, CoinInfo {
assert!(
is_account_registered<CoinType>(owner),
error::not_found(ECOIN_STORE_NOT_PUBLISHED),
);

let unscaled_value = borrow_global<CoinStore<CoinType>>(owner).coin.value;
assert!(unscaled_value > 0, error::out_of_range(EZERO_COIN_AMOUNT));

let decimal_places = decimals<CoinType>();
let scaling = math64::pow(10, (decimal_places as u64));
let value = fixed_point32::create_from_rational(unscaled_value, scaling);
// multply will TRUNCATE.
let integer_part = fixed_point32::multiply_u64(1, value);

let decimal_part = unscaled_value - (integer_part * scaling);

(integer_part, decimal_part)
}

#[test(source = @0x1)]
public entry fun test_human_read(
source: signer,
) acquires CoinInfo, CoinStore {
let source_addr = signer::address_of(&source);
account::create_account_for_test(source_addr);
let (burn_cap, freeze_cap, mint_cap) = initialize_and_register_fake_money(&source, 8, true);

let coins_minted = mint<FakeMoney>(1234567890, &mint_cap);
deposit(source_addr, coins_minted);
// assert!(balance<FakeMoney>(source_addr) == 100, 0);

let (integer, decimal) = balance_human<FakeMoney>(source_addr);
assert!(integer == 12, 7357001);
assert!(decimal == 34567890, 7357002);

move_to(&source, FakeMoneyCapabilities {
burn_cap,
freeze_cap,
mint_cap,
});
}

#[view]
/// Returns `true` if the type `CoinType` is an initialized coin.
Expand Down
Loading

0 comments on commit bd7e865

Please sign in to comment.