Skip to content

Commit

Permalink
[AptosFramework] add TransactionPublishingOption and support module p…
Browse files Browse the repository at this point in the history
…ublishing
  • Loading branch information
zekun000 authored and aptos-bot committed Mar 10, 2022
1 parent 4508231 commit 883915d
Show file tree
Hide file tree
Showing 46 changed files with 645 additions and 26 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/src/tests/index_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async fn test_get_ledger_info() {

let expected = json!({
"chain_id": 4,
"epoch": 0,
"ledger_version": ledger_info.version().to_string(),
"ledger_timestamp": ledger_info.timestamp().to_string(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: AptosConsensusConfig
: AptosFramework
? address: "00000000000000000000000000000001"
name: AptosTransactionPublishingOption
: AptosFramework
? address: "00000000000000000000000000000001"
name: AptosVMConfig
: AptosFramework
Expand Down Expand Up @@ -71,6 +74,9 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: DiemTimestamp
: CoreFramework
? address: "00000000000000000000000000000001"
name: DiemTransactionPublishingOption
: CoreFramework
? address: "00000000000000000000000000000001"
name: DiemVMConfig
: CoreFramework
Expand Down Expand Up @@ -128,7 +134,7 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: Vector
: Std
source_digest: 9F4226D30A15C73B60E96142306F135748D0316095B6E59FEECDD7F22672B78A
source_digest: DA08D1587A621A2176DC31EA2F668DDCC181E956AEEEC308F6ED822900CE042D
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ transaction in addition to the core prologue and epilogue.
<b>use</b> <a href="AptosValidatorOperatorConfig.md#0x1_AptosValidatorOperatorConfig">0x1::AptosValidatorOperatorConfig</a>;
<b>use</b> <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/MoveStdlib/docs/BCS.md#0x1_BCS">0x1::BCS</a>;
<b>use</b> <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/CoreFramework/docs/DiemTimestamp.md#0x1_DiemTimestamp">0x1::DiemTimestamp</a>;
<b>use</b> <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/CoreFramework/docs/DiemTransactionPublishingOption.md#0x1_DiemTransactionPublishingOption">0x1::DiemTransactionPublishingOption</a>;
<b>use</b> <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/MoveStdlib/docs/Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/MoveStdlib/docs/Hash.md#0x1_Hash">0x1::Hash</a>;
<b>use</b> <a href="Marker.md#0x1_Marker">0x1::Marker</a>;
Expand Down Expand Up @@ -101,6 +102,15 @@ transaction in addition to the core prologue and epilogue.



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



<pre><code><b>const</b> <a href="AptosAccount.md#0x1_AptosAccount_EMODULE_NOT_ALLOWED">EMODULE_NOT_ALLOWED</a>: u64 = 8;
</code></pre>



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


Expand All @@ -110,6 +120,15 @@ transaction in addition to the core prologue and epilogue.



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



<pre><code><b>const</b> <a href="AptosAccount.md#0x1_AptosAccount_ESCRIPT_NOT_ALLOWED">ESCRIPT_NOT_ALLOWED</a>: u64 = 9;
</code></pre>



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


Expand Down Expand Up @@ -375,6 +394,7 @@ Rotate the authentication key for the account under cap.account_address
txn_expiration_time: u64,
chain_id: u8,
) {
<b>assert</b>!(<a href="../../../../../../../aptos-framework/releases/artifacts/current/build/CoreFramework/docs/DiemTransactionPublishingOption.md#0x1_DiemTransactionPublishingOption_is_module_allowed">DiemTransactionPublishingOption::is_module_allowed</a>(), <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/MoveStdlib/docs/Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="AptosAccount.md#0x1_AptosAccount_EMODULE_NOT_ALLOWED">EMODULE_NOT_ALLOWED</a>));
<a href="AptosAccount.md#0x1_AptosAccount_prologue_common">prologue_common</a>(sender, txn_sequence_number, txn_public_key, txn_gas_price, txn_max_gas_units, txn_expiration_time, chain_id)
}
</code></pre>
Expand All @@ -389,7 +409,7 @@ Rotate the authentication key for the account under cap.account_address



<pre><code><b>fun</b> <a href="AptosAccount.md#0x1_AptosAccount_script_prologue">script_prologue</a>(sender: signer, txn_sequence_number: u64, txn_public_key: vector&lt;u8&gt;, txn_gas_price: u64, txn_max_gas_units: u64, txn_expiration_time: u64, chain_id: u8, _script_hash: vector&lt;u8&gt;)
<pre><code><b>fun</b> <a href="AptosAccount.md#0x1_AptosAccount_script_prologue">script_prologue</a>(sender: signer, txn_sequence_number: u64, txn_public_key: vector&lt;u8&gt;, txn_gas_price: u64, txn_max_gas_units: u64, txn_expiration_time: u64, chain_id: u8, script_hash: vector&lt;u8&gt;)
</code></pre>


Expand All @@ -406,8 +426,9 @@ Rotate the authentication key for the account under cap.account_address
txn_max_gas_units: u64,
txn_expiration_time: u64,
chain_id: u8,
_script_hash: vector&lt;u8&gt;,
script_hash: vector&lt;u8&gt;,
) {
<b>assert</b>!(<a href="../../../../../../../aptos-framework/releases/artifacts/current/build/CoreFramework/docs/DiemTransactionPublishingOption.md#0x1_DiemTransactionPublishingOption_is_script_allowed">DiemTransactionPublishingOption::is_script_allowed</a>(&script_hash), <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/MoveStdlib/docs/Errors.md#0x1_Errors_invalid_state">Errors::invalid_state</a>(<a href="AptosAccount.md#0x1_AptosAccount_ESCRIPT_NOT_ALLOWED">ESCRIPT_NOT_ALLOWED</a>));
<a href="AptosAccount.md#0x1_AptosAccount_prologue_common">prologue_common</a>(sender, txn_sequence_number, txn_public_key, txn_gas_price, txn_max_gas_units, txn_expiration_time, chain_id)
}
</code></pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

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

# Module `0x1::AptosTransactionPublishingOption`



- [Function `initialize`](#0x1_AptosTransactionPublishingOption_initialize)
- [Function `set_module_publishing_allowed`](#0x1_AptosTransactionPublishingOption_set_module_publishing_allowed)


<pre><code><b>use</b> <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/MoveStdlib/docs/Capability.md#0x1_Capability">0x1::Capability</a>;
<b>use</b> <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/CoreFramework/docs/DiemTransactionPublishingOption.md#0x1_DiemTransactionPublishingOption">0x1::DiemTransactionPublishingOption</a>;
<b>use</b> <a href="Marker.md#0x1_Marker">0x1::Marker</a>;
</code></pre>



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

## Function `initialize`



<pre><code><b>public</b> <b>fun</b> <a href="AptosTransactionPublishingOption.md#0x1_AptosTransactionPublishingOption_initialize">initialize</a>(core_resource_account: &signer, script_allow_list: vector&lt;vector&lt;u8&gt;&gt;, module_publishing_allowed: bool)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="AptosTransactionPublishingOption.md#0x1_AptosTransactionPublishingOption_initialize">initialize</a>(
core_resource_account: &signer,
script_allow_list: vector&lt;vector&lt;u8&gt;&gt;,
module_publishing_allowed: bool,
) {
<a href="../../../../../../../aptos-framework/releases/artifacts/current/build/CoreFramework/docs/DiemTransactionPublishingOption.md#0x1_DiemTransactionPublishingOption_initialize">DiemTransactionPublishingOption::initialize</a>&lt;ChainMarker&gt;(core_resource_account, script_allow_list, module_publishing_allowed);
}
</code></pre>



</details>

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

## Function `set_module_publishing_allowed`



<pre><code><b>public</b> <b>fun</b> <a href="AptosTransactionPublishingOption.md#0x1_AptosTransactionPublishingOption_set_module_publishing_allowed">set_module_publishing_allowed</a>(account: &signer, is_allowed: bool)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="AptosTransactionPublishingOption.md#0x1_AptosTransactionPublishingOption_set_module_publishing_allowed">set_module_publishing_allowed</a>(account: &signer, is_allowed: bool) {
<a href="../../../../../../../aptos-framework/releases/artifacts/current/build/CoreFramework/docs/DiemTransactionPublishingOption.md#0x1_DiemTransactionPublishingOption_set_module_publishing_allowed">DiemTransactionPublishingOption::set_module_publishing_allowed</a>(is_allowed, <a href="../../../../../../../aptos-framework/releases/artifacts/current/build/MoveStdlib/docs/Capability.md#0x1_Capability_acquire">Capability::acquire</a>(account, &<a href="Marker.md#0x1_Marker_get">Marker::get</a>()));
}
</code></pre>



</details>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<pre><code><b>use</b> <a href="AptosAccount.md#0x1_AptosAccount">0x1::AptosAccount</a>;
<b>use</b> <a href="AptosConsensusConfig.md#0x1_AptosConsensusConfig">0x1::AptosConsensusConfig</a>;
<b>use</b> <a href="AptosTransactionPublishingOption.md#0x1_AptosTransactionPublishingOption">0x1::AptosTransactionPublishingOption</a>;
<b>use</b> <a href="AptosVMConfig.md#0x1_AptosVMConfig">0x1::AptosVMConfig</a>;
<b>use</b> <a href="AptosValidatorConfig.md#0x1_AptosValidatorConfig">0x1::AptosValidatorConfig</a>;
<b>use</b> <a href="AptosValidatorOperatorConfig.md#0x1_AptosValidatorOperatorConfig">0x1::AptosValidatorOperatorConfig</a>;
Expand All @@ -35,7 +36,7 @@



<pre><code><b>fun</b> <a href="Genesis.md#0x1_Genesis_initialize">initialize</a>(core_resource_account: signer, _tc_account: signer, core_resource_account_auth_key: vector&lt;u8&gt;, _tc_auth_key: vector&lt;u8&gt;, _initial_script_allow_list: vector&lt;vector&lt;u8&gt;&gt;, _is_open_module: bool, instruction_schedule: vector&lt;u8&gt;, native_schedule: vector&lt;u8&gt;, chain_id: u8, initial_diem_version: u64, consensus_config: vector&lt;u8&gt;)
<pre><code><b>fun</b> <a href="Genesis.md#0x1_Genesis_initialize">initialize</a>(core_resource_account: signer, _tc_account: signer, core_resource_account_auth_key: vector&lt;u8&gt;, _tc_auth_key: vector&lt;u8&gt;, initial_script_allow_list: vector&lt;vector&lt;u8&gt;&gt;, is_open_module: bool, instruction_schedule: vector&lt;u8&gt;, native_schedule: vector&lt;u8&gt;, chain_id: u8, initial_diem_version: u64, consensus_config: vector&lt;u8&gt;)
</code></pre>


Expand All @@ -49,8 +50,8 @@
_tc_account: signer,
core_resource_account_auth_key: vector&lt;u8&gt;,
_tc_auth_key: vector&lt;u8&gt;,
_initial_script_allow_list: vector&lt;vector&lt;u8&gt;&gt;,
_is_open_module: bool,
initial_script_allow_list: vector&lt;vector&lt;u8&gt;&gt;,
is_open_module: bool,
instruction_schedule: vector&lt;u8&gt;,
native_schedule: vector&lt;u8&gt;,
chain_id: u8,
Expand All @@ -60,6 +61,8 @@
<a href="Genesis.md#0x1_Genesis_initialize_internal">initialize_internal</a>(
&core_resource_account,
core_resource_account_auth_key,
initial_script_allow_list,
is_open_module,
instruction_schedule,
native_schedule,
chain_id,
Expand All @@ -79,7 +82,7 @@



<pre><code><b>fun</b> <a href="Genesis.md#0x1_Genesis_initialize_internal">initialize_internal</a>(core_resource_account: &signer, core_resource_account_auth_key: vector&lt;u8&gt;, instruction_schedule: vector&lt;u8&gt;, native_schedule: vector&lt;u8&gt;, chain_id: u8, initial_diem_version: u64, consensus_config: vector&lt;u8&gt;)
<pre><code><b>fun</b> <a href="Genesis.md#0x1_Genesis_initialize_internal">initialize_internal</a>(core_resource_account: &signer, core_resource_account_auth_key: vector&lt;u8&gt;, initial_script_allow_list: vector&lt;vector&lt;u8&gt;&gt;, is_open_module: bool, instruction_schedule: vector&lt;u8&gt;, native_schedule: vector&lt;u8&gt;, chain_id: u8, initial_diem_version: u64, consensus_config: vector&lt;u8&gt;)
</code></pre>


Expand All @@ -91,6 +94,8 @@
<pre><code><b>fun</b> <a href="Genesis.md#0x1_Genesis_initialize_internal">initialize_internal</a>(
core_resource_account: &signer,
core_resource_account_auth_key: vector&lt;u8&gt;,
initial_script_allow_list: vector&lt;vector&lt;u8&gt;&gt;,
is_open_module: bool,
instruction_schedule: vector&lt;u8&gt;,
native_schedule: vector&lt;u8&gt;,
chain_id: u8,
Expand Down Expand Up @@ -120,6 +125,7 @@

<a href="AptosValidatorConfig.md#0x1_AptosValidatorConfig_initialize">AptosValidatorConfig::initialize</a>(core_resource_account);
<a href="AptosValidatorOperatorConfig.md#0x1_AptosValidatorOperatorConfig_initialize">AptosValidatorOperatorConfig::initialize</a>(core_resource_account);
<a href="AptosTransactionPublishingOption.md#0x1_AptosTransactionPublishingOption_initialize">AptosTransactionPublishingOption::initialize</a>(core_resource_account, initial_script_allow_list, is_open_module);

<a href="TestCoin.md#0x1_TestCoin_initialize">TestCoin::initialize</a>(core_resource_account, 1000000);

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module AptosFramework::AptosAccount {
use CoreFramework::Account;
use CoreFramework::DiemTimestamp;
use CoreFramework::SystemAddresses;
use CoreFramework::DiemTransactionPublishingOption;
use AptosFramework::Marker;
use AptosFramework::AptosValidatorConfig;
use AptosFramework::AptosValidatorOperatorConfig;
Expand All @@ -29,6 +30,8 @@ module AptosFramework::AptosAccount {
const ECANT_PAY_GAS_DEPOSIT: u64 = 5;
const EWRITESET_NOT_ALLOWED: u64 = 6;
const EMULTI_AGENT_NOT_SUPPORTED: u64 = 7;
const EMODULE_NOT_ALLOWED: u64 = 8;
const ESCRIPT_NOT_ALLOWED: u64 = 9;

public(friend) fun create_account_internal(account_address: address, auth_key_prefix: vector<u8>): (signer, vector<u8>) {
assert!(
Expand Down Expand Up @@ -128,6 +131,7 @@ module AptosFramework::AptosAccount {
txn_expiration_time: u64,
chain_id: u8,
) {
assert!(DiemTransactionPublishingOption::is_module_allowed(), Errors::invalid_state(EMODULE_NOT_ALLOWED));
prologue_common(sender, txn_sequence_number, txn_public_key, txn_gas_price, txn_max_gas_units, txn_expiration_time, chain_id)
}

Expand All @@ -139,8 +143,9 @@ module AptosFramework::AptosAccount {
txn_max_gas_units: u64,
txn_expiration_time: u64,
chain_id: u8,
_script_hash: vector<u8>,
script_hash: vector<u8>,
) {
assert!(DiemTransactionPublishingOption::is_script_allowed(&script_hash), Errors::invalid_state(ESCRIPT_NOT_ALLOWED));
prologue_common(sender, txn_sequence_number, txn_public_key, txn_gas_price, txn_max_gas_units, txn_expiration_time, chain_id)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module AptosFramework::AptosTransactionPublishingOption {
use Std::Capability;
use AptosFramework::Marker::{Self, ChainMarker};
use CoreFramework::DiemTransactionPublishingOption;

public fun initialize(
core_resource_account: &signer,
script_allow_list: vector<vector<u8>>,
module_publishing_allowed: bool,
) {
DiemTransactionPublishingOption::initialize<ChainMarker>(core_resource_account, script_allow_list, module_publishing_allowed);
}

public fun set_module_publishing_allowed(account: &signer, is_allowed: bool) {
DiemTransactionPublishingOption::set_module_publishing_allowed(is_allowed, Capability::acquire(account, &Marker::get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module AptosFramework::Genesis {
use CoreFramework::ValidatorConfig;
use CoreFramework::ValidatorOperatorConfig;
use AptosFramework::AptosConsensusConfig;
use AptosFramework::AptosTransactionPublishingOption;
use AptosFramework::AptosValidatorConfig;
use AptosFramework::AptosValidatorOperatorConfig;
use AptosFramework::AptosValidatorSet;
Expand All @@ -23,8 +24,8 @@ module AptosFramework::Genesis {
_tc_account: signer,
core_resource_account_auth_key: vector<u8>,
_tc_auth_key: vector<u8>,
_initial_script_allow_list: vector<vector<u8>>,
_is_open_module: bool,
initial_script_allow_list: vector<vector<u8>>,
is_open_module: bool,
instruction_schedule: vector<u8>,
native_schedule: vector<u8>,
chain_id: u8,
Expand All @@ -34,6 +35,8 @@ module AptosFramework::Genesis {
initialize_internal(
&core_resource_account,
core_resource_account_auth_key,
initial_script_allow_list,
is_open_module,
instruction_schedule,
native_schedule,
chain_id,
Expand All @@ -45,6 +48,8 @@ module AptosFramework::Genesis {
fun initialize_internal(
core_resource_account: &signer,
core_resource_account_auth_key: vector<u8>,
initial_script_allow_list: vector<vector<u8>>,
is_open_module: bool,
instruction_schedule: vector<u8>,
native_schedule: vector<u8>,
chain_id: u8,
Expand Down Expand Up @@ -74,6 +79,7 @@ module AptosFramework::Genesis {

AptosValidatorConfig::initialize(core_resource_account);
AptosValidatorOperatorConfig::initialize(core_resource_account);
AptosTransactionPublishingOption::initialize(core_resource_account, initial_script_allow_list, is_open_module);

TestCoin::initialize(core_resource_account, 1000000);

Expand Down Expand Up @@ -178,6 +184,8 @@ module AptosFramework::Genesis {
initialize_internal(
core_resource_account,
x"0000000000000000000000000000000000000000000000000000000000000000",
Vector::empty(),
true,
x"", // instruction_schedule not needed for unit tests
x"", // native schedule not needed for unit tests
4u8, // TESTING chain ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module AptosFramework::Marker {

friend AptosFramework::AptosAccount;
friend AptosFramework::AptosConsensusConfig;
friend AptosFramework::AptosTransactionPublishingOption;
friend AptosFramework::AptosValidatorConfig;
friend AptosFramework::AptosValidatorOperatorConfig;
friend AptosFramework::AptosValidatorSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: DiemTimestamp
: CoreFramework
? address: "00000000000000000000000000000001"
name: DiemTransactionPublishingOption
: CoreFramework
? address: "00000000000000000000000000000001"
name: DiemVMConfig
: CoreFramework
Expand Down Expand Up @@ -88,7 +91,7 @@ compiled_package_info:
? address: "00000000000000000000000000000001"
name: Vector
: Std
source_digest: C1C17355E0E39239912E53B03C168597E91ED7623DD0317218EE8C79CB2DD442
source_digest: FB8886BBA9CCC906E15186C33992217BE360FF711DC5E0878234ADF20954EF71
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 883915d

Please sign in to comment.