Skip to content

Commit

Permalink
add admin cap
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 committed Sep 2, 2024
1 parent d572c03 commit af16ca0
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 101 deletions.
Binary file modified frameworks/framework-release/released/8/0x2/package.rpd
Binary file not shown.
Binary file modified frameworks/framework-release/released/8/0x3/package.rpd
Binary file not shown.
Binary file modified frameworks/framework-release/released/8/stdlib
Binary file not shown.
13 changes: 13 additions & 0 deletions frameworks/moveos-stdlib/doc/core_addresses.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Function `assert_system_reserved_address`](#0x2_core_addresses_assert_system_reserved_address)
- [Function `is_system_reserved_address`](#0x2_core_addresses_is_system_reserved_address)
- [Function `is_reserved_address`](#0x2_core_addresses_is_reserved_address)
- [Function `list_system_reserved_addresses`](#0x2_core_addresses_list_system_reserved_addresses)


<pre><code><b>use</b> <a href="">0x1::signer</a>;
Expand Down Expand Up @@ -124,3 +125,15 @@ Return true if <code>addr</code> is either the VM address or an Rooch system add

<pre><code><b>public</b> <b>fun</b> <a href="core_addresses.md#0x2_core_addresses_is_reserved_address">is_reserved_address</a>(addr: <b>address</b>): bool
</code></pre>



<a name="0x2_core_addresses_list_system_reserved_addresses"></a>

## Function `list_system_reserved_addresses`

List all the on chain governance's reserved addresses.


<pre><code><b>public</b> <b>fun</b> <a href="core_addresses.md#0x2_core_addresses_list_system_reserved_addresses">list_system_reserved_addresses</a>(): <a href="">vector</a>&lt;<b>address</b>&gt;
</code></pre>
18 changes: 18 additions & 0 deletions frameworks/moveos-stdlib/sources/core_addresses.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module moveos_std::core_addresses {
use std::signer;
use std::vector;

/// The operation can only be performed by the VM
const ErrorNotVM: u64 = 1;
Expand Down Expand Up @@ -54,4 +55,21 @@ module moveos_std::core_addresses {
public fun is_reserved_address(addr: address): bool {
is_system_reserved_address(addr) || is_vm_address(addr)
}

/// List all the on chain governance's reserved addresses.
public fun list_system_reserved_addresses(): vector<address> {
let addrs = vector::empty<address>();
vector::push_back(&mut addrs, @0x1);
vector::push_back(&mut addrs, @0x2);
vector::push_back(&mut addrs, @0x3);
vector::push_back(&mut addrs, @0x4);
vector::push_back(&mut addrs, @0x5);
vector::push_back(&mut addrs, @0x6);
vector::push_back(&mut addrs, @0x7);
vector::push_back(&mut addrs, @0x8);
vector::push_back(&mut addrs, @0x9);
vector::push_back(&mut addrs, @0xa);

addrs
}
}
2 changes: 1 addition & 1 deletion frameworks/rooch-framework/doc/gas_coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Mint gas coin to the given account.

## Function `faucet_entry`

Entry point for the faucet, anyone can get Gas via this function on local/dev net, otherwise only sequencer account can call this function.
Entry point for the faucet, anyone can get Gas via this function on local/dev net, otherwise only admin account can call this function.


<pre><code><b>public</b> entry <b>fun</b> <a href="gas_coin.md#0x3_gas_coin_faucet_entry">faucet_entry</a>(<a href="">account</a>: &<a href="">signer</a>, amount: <a href="">u256</a>)
Expand Down
39 changes: 3 additions & 36 deletions frameworks/rooch-framework/doc/genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@


<pre><code><b>use</b> <a href="">0x1::option</a>;
<b>use</b> <a href="">0x1::vector</a>;
<b>use</b> <a href="">0x2::account</a>;
<b>use</b> <a href="">0x2::core_addresses</a>;
<b>use</b> <a href="">0x2::module_store</a>;
<b>use</b> <a href="">0x2::signer</a>;
<b>use</b> <a href="">0x2::tx_context</a>;
<b>use</b> <a href="account.md#0x3_account">0x3::account</a>;
<b>use</b> <a href="account_coin_store.md#0x3_account_coin_store">0x3::account_coin_store</a>;
Expand Down Expand Up @@ -51,39 +54,3 @@ GenesisContext is a genesis init parameters in the TxContext.

<pre><code><b>const</b> <a href="genesis.md#0x3_genesis_ErrorGenesisInit">ErrorGenesisInit</a>: u64 = 1;
</code></pre>



<a name="0x3_genesis_MoveosStdAccount"></a>



<pre><code><b>const</b> <a href="genesis.md#0x3_genesis_MoveosStdAccount">MoveosStdAccount</a>: <b>address</b> = 0x2;
</code></pre>



<a name="0x3_genesis_BitcoinMoveAccount"></a>



<pre><code><b>const</b> <a href="genesis.md#0x3_genesis_BitcoinMoveAccount">BitcoinMoveAccount</a>: <b>address</b> = 0x4;
</code></pre>



<a name="0x3_genesis_MoveStdAccount"></a>



<pre><code><b>const</b> <a href="genesis.md#0x3_genesis_MoveStdAccount">MoveStdAccount</a>: <b>address</b> = 0x1;
</code></pre>



<a name="0x3_genesis_RoochFrameworkAccount"></a>



<pre><code><b>const</b> <a href="genesis.md#0x3_genesis_RoochFrameworkAccount">RoochFrameworkAccount</a>: <b>address</b> = 0x3;
</code></pre>
64 changes: 44 additions & 20 deletions frameworks/rooch-framework/doc/onchain_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@


- [Resource `OnchainConfig`](#0x3_onchain_config_OnchainConfig)
- [Resource `AdminCap`](#0x3_onchain_config_AdminCap)
- [Constants](#@Constants_0)
- [Function `genesis_init`](#0x3_onchain_config_genesis_init)
- [Function `admin`](#0x3_onchain_config_admin)
- [Function `ensure_admin`](#0x3_onchain_config_ensure_admin)
- [Function `sequencer`](#0x3_onchain_config_sequencer)
- [Function `update_framework_version`](#0x3_onchain_config_update_framework_version)
- [Function `framework_version`](#0x3_onchain_config_framework_version)
- [Function `onchain_config`](#0x3_onchain_config_onchain_config)
- [Function `ensure_sequencer`](#0x3_onchain_config_ensure_sequencer)
- [Function `add_to_publishing_allowlist`](#0x3_onchain_config_add_to_publishing_allowlist)
- [Function `remove_from_publishing_allowlist`](#0x3_onchain_config_remove_from_publishing_allowlist)
- [Function `change_feature_flags`](#0x3_onchain_config_change_feature_flags)
Expand All @@ -39,16 +41,28 @@ OnchainConfig is framework configurations stored on chain.



<a name="0x3_onchain_config_AdminCap"></a>

## Resource `AdminCap`

AdminCap is the capability for admin operations, such as update onchain configurations.


<pre><code><b>struct</b> <a href="onchain_config.md#0x3_onchain_config_AdminCap">AdminCap</a> <b>has</b> store, key
</code></pre>



<a name="@Constants_0"></a>

## Constants


<a name="0x3_onchain_config_ErrorNotSequencer"></a>
<a name="0x3_onchain_config_ErrorNotAdmin"></a>



<pre><code><b>const</b> <a href="onchain_config.md#0x3_onchain_config_ErrorNotSequencer">ErrorNotSequencer</a>: u64 = 1;
<pre><code><b>const</b> <a href="onchain_config.md#0x3_onchain_config_ErrorNotAdmin">ErrorNotAdmin</a>: u64 = 1;
</code></pre>


Expand All @@ -64,6 +78,28 @@ OnchainConfig is framework configurations stored on chain.



<a name="0x3_onchain_config_admin"></a>

## Function `admin`



<pre><code><b>public</b> <b>fun</b> <a href="onchain_config.md#0x3_onchain_config_admin">admin</a>(): <b>address</b>
</code></pre>



<a name="0x3_onchain_config_ensure_admin"></a>

## Function `ensure_admin`



<pre><code><b>public</b> <b>fun</b> <a href="onchain_config.md#0x3_onchain_config_ensure_admin">ensure_admin</a>(<a href="">account</a>: &<a href="">signer</a>)
</code></pre>



<a name="0x3_onchain_config_sequencer"></a>

## Function `sequencer`
Expand Down Expand Up @@ -108,27 +144,15 @@ OnchainConfig is framework configurations stored on chain.



<a name="0x3_onchain_config_ensure_sequencer"></a>

## Function `ensure_sequencer`



<pre><code><b>public</b> <b>fun</b> <a href="onchain_config.md#0x3_onchain_config_ensure_sequencer">ensure_sequencer</a>(<a href="">account</a>: &<a href="">signer</a>)
</code></pre>



<a name="0x3_onchain_config_add_to_publishing_allowlist"></a>

## Function `add_to_publishing_allowlist`

When module_publishing_allowlist_feature is enabled, only address in allowlist
can publish modules.
Add <code>publisher</code> to publishing allowlist.
When module_publishing_allowlist_feature is enabled, only packed_id in allowlist can be published.
Add <code>package_id</code> to publishing allowlist.


<pre><code><b>public</b> entry <b>fun</b> <a href="onchain_config.md#0x3_onchain_config_add_to_publishing_allowlist">add_to_publishing_allowlist</a>(<a href="">account</a>: &<a href="">signer</a>, publisher: <b>address</b>)
<pre><code><b>public</b> entry <b>fun</b> <a href="onchain_config.md#0x3_onchain_config_add_to_publishing_allowlist">add_to_publishing_allowlist</a>(<a href="">account</a>: &<a href="">signer</a>, package_id: <b>address</b>)
</code></pre>


Expand All @@ -137,10 +161,10 @@ Add <code>publisher</code> to publishing allowlist.

## Function `remove_from_publishing_allowlist`

Remove <code>publisher</code> from publishing allowlist.
Remove <code>package_id</code> from publishing allowlist.


<pre><code><b>public</b> entry <b>fun</b> <a href="onchain_config.md#0x3_onchain_config_remove_from_publishing_allowlist">remove_from_publishing_allowlist</a>(<a href="">account</a>: &<a href="">signer</a>, publisher: <b>address</b>)
<pre><code><b>public</b> entry <b>fun</b> <a href="onchain_config.md#0x3_onchain_config_remove_from_publishing_allowlist">remove_from_publishing_allowlist</a>(<a href="">account</a>: &<a href="">signer</a>, package_id: <b>address</b>)
</code></pre>


Expand Down
9 changes: 0 additions & 9 deletions frameworks/rooch-framework/doc/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ Event for framework upgrades
## Constants


<a name="0x3_upgrade_ErrorNotSequencer"></a>



<pre><code><b>const</b> <a href="upgrade.md#0x3_upgrade_ErrorNotSequencer">ErrorNotSequencer</a>: u64 = 1;
</code></pre>



<a name="0x3_upgrade_MoveosStdAccount"></a>


Expand Down
4 changes: 2 additions & 2 deletions frameworks/rooch-framework/sources/gas_coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ module rooch_framework::gas_coin {
faucet(addr, amount);
}

/// Entry point for the faucet, anyone can get Gas via this function on local/dev net, otherwise only sequencer account can call this function.
/// Entry point for the faucet, anyone can get Gas via this function on local/dev net, otherwise only admin account can call this function.
public entry fun faucet_entry(account: &signer, amount: u256) {
if(!chain_id::is_local_or_dev()){
onchain_config::ensure_sequencer(account);
onchain_config::ensure_admin(account);
};
let addr = signer::address_of(account);
faucet(addr, amount);
Expand Down
24 changes: 14 additions & 10 deletions frameworks/rooch-framework/sources/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
module rooch_framework::genesis {

use std::option;
use std::vector;
use moveos_std::signer;
use moveos_std::tx_context;
use moveos_std::module_store;
use moveos_std::core_addresses;
use rooch_framework::account;
use rooch_framework::auth_validator_registry;
use rooch_framework::builtin_validators;
Expand All @@ -20,11 +23,6 @@ module rooch_framework::genesis {

const ErrorGenesisInit: u64 = 1;

const MoveStdAccount: address = @0x1;
const MoveosStdAccount: address = @0x2;
const RoochFrameworkAccount: address = @0x3;
const BitcoinMoveAccount: address = @0x4;

/// GenesisContext is a genesis init parameters in the TxContext.
struct GenesisContext has copy,store,drop{
chain_id: u64,
Expand All @@ -33,7 +31,13 @@ module rooch_framework::genesis {
}

fun init(){
let genesis_account = &account::create_system_account(@rooch_framework);
// create all system accounts
let system_addresses = core_addresses::list_system_reserved_addresses();
vector::for_each(system_addresses, |addr| {
let _ = account::create_system_account(addr);
});

let genesis_account = &signer::module_signer<GenesisContext>();
let genesis_context_option = tx_context::get_attribute<GenesisContext>();
assert!(option::is_some(&genesis_context_option), ErrorGenesisInit);
let genesis_context = option::extract(&mut genesis_context_option);
Expand All @@ -55,10 +59,10 @@ module rooch_framework::genesis {
};

// issue framework packages upgrade cap to sequencer
module_store::issue_upgrade_cap_by_system(genesis_account, MoveStdAccount, sequencer_addr);
module_store::issue_upgrade_cap_by_system(genesis_account, MoveosStdAccount, sequencer_addr);
module_store::issue_upgrade_cap_by_system(genesis_account, RoochFrameworkAccount, sequencer_addr);
module_store::issue_upgrade_cap_by_system(genesis_account, BitcoinMoveAccount, sequencer_addr);
let system_addresses = core_addresses::list_system_reserved_addresses();
vector::for_each(system_addresses, |addr| {
module_store::issue_upgrade_cap_by_system(genesis_account, addr, sequencer_addr);
});

// give some gas coin to the sequencer
gas_coin::faucet(sequencer_addr, 1000000_00000000u256);
Expand Down
Loading

0 comments on commit af16ca0

Please sign in to comment.