Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOVE] Format all source files to be consistent #4526

Merged
merged 1 commit into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions aptos-move/framework/aptos-framework/sources/account.move
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ module aptos_framework::account {
}

struct CapabilityOffer<phantom T> has store { for: Option<address> }

struct RotationCapability has drop, store { account: address }

struct SignerCapability has drop, store { account: address }

struct OriginatingAddress has key {
Expand All @@ -55,8 +57,10 @@ module aptos_framework::account {
/// context because they include the TXN's unique sequence number.
struct RotationProofChallenge has copy, drop {
sequence_number: u64,
originator: address, // originating address
current_auth_key: address, // current auth key
originator: address,
// originating address
current_auth_key: address,
// current auth key
new_public_key: vector<u8>,
}

Expand Down Expand Up @@ -173,7 +177,7 @@ module aptos_framework::account {
borrow_global<Account>(addr).guid_creation_num
}

public fun get_sequence_number(addr: address) : u64 acquires Account {
public fun get_sequence_number(addr: address): u64 acquires Account {
borrow_global<Account>(addr).sequence_number
}

Expand All @@ -189,7 +193,7 @@ module aptos_framework::account {
account_resource.sequence_number = old_sequence_number + 1;
}

public fun get_authentication_key(addr: address) : vector<u8> acquires Account {
public fun get_authentication_key(addr: address): vector<u8> acquires Account {
*&borrow_global<Account>(addr).authentication_key
}

Expand All @@ -204,7 +208,7 @@ module aptos_framework::account {
account_resource.authentication_key = new_auth_key;
}

fun verify_key_rotation_signature_and_get_auth_key(scheme: u8, public_key_bytes: vector<u8>, signature: vector<u8>, challenge: &RotationProofChallenge) : vector<u8> {
fun verify_key_rotation_signature_and_get_auth_key(scheme: u8, public_key_bytes: vector<u8>, signature: vector<u8>, challenge: &RotationProofChallenge): vector<u8> {
if (scheme == ED25519_SCHEME) {
let pk = ed25519::new_unvalidated_public_key_from_bytes(public_key_bytes);
let sig = ed25519::new_signature_from_bytes(signature);
Expand Down Expand Up @@ -352,7 +356,7 @@ module aptos_framework::account {
}

/// Return a signer of the offerer, if there's an existing signer/rotation capability offer at the offerer's address
public fun create_authorized_signer(account: &signer, offerer_address: address) : signer acquires Account {
public fun create_authorized_signer(account: &signer, offerer_address: address): signer acquires Account {
assert!(exists_at(offerer_address), error::not_found(EACCOUNT_DOES_NOT_EXIST));

// Check if there's an existing signer capability offer from the offerer
Expand Down Expand Up @@ -387,15 +391,15 @@ module aptos_framework::account {
public(friend) fun create_framework_reserved_account(addr: address): (signer, SignerCapability) {
assert!(
addr == @0x1 ||
addr == @0x2 ||
addr == @0x3 ||
addr == @0x4 ||
addr == @0x5 ||
addr == @0x6 ||
addr == @0x7 ||
addr == @0x8 ||
addr == @0x9 ||
addr == @0xa,
addr == @0x2 ||
addr == @0x3 ||
addr == @0x4 ||
addr == @0x5 ||
addr == @0x6 ||
addr == @0x7 ||
addr == @0x8 ||
addr == @0x9 ||
addr == @0xa,
error::permission_denied(ENO_VALID_FRAMEWORK_RESERVED_ADDRESS),
);
let signer = create_account_unchecked(addr);
Expand Down Expand Up @@ -457,7 +461,7 @@ module aptos_framework::account {
}

#[test_only]
struct DummyResource has key { }
struct DummyResource has key {}

#[test(user = @0x1)]
public entry fun test_module_capability(user: signer) acquires DummyResource {
Expand All @@ -467,7 +471,7 @@ module aptos_framework::account {
let resource_account_from_cap = create_signer_with_capability(&signer_cap);
assert!(&resource_account == &resource_account_from_cap, 1);

move_to(&resource_account_from_cap, DummyResource { });
move_to(&resource_account_from_cap, DummyResource {});
borrow_global<DummyResource>(signer::address_of(&resource_account));
}

Expand Down Expand Up @@ -531,7 +535,7 @@ module aptos_framework::account {
#[expected_failure(abort_code = 262151)]
public entry fun test_empty_signature(alice: signer) acquires Account, OriginatingAddress {
create_account(signer::address_of(&alice));
let test_signature = vector::empty<u8>();
let test_signature = vector::empty<u8>();
let pk = x"0000000000000000000000000000000000000000000000000000000000000000";
rotate_authentication_key(&alice, ED25519_SCHEME, pk, ED25519_SCHEME, pk, test_signature, test_signature);
}
Expand All @@ -545,19 +549,19 @@ module aptos_framework::account {
alice
}

/*
TODO bring back with generic rotation capability
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just kill this TODO. Whoever wants to add this back in the future can go through the history and find it.

#[test(bob = @0x345)]
#[expected_failure(abort_code = 65544)]
public entry fun test_invalid_offer_rotation_capability(bob: signer) acquires Account {
let pk = x"f66bf0ce5ceb582b93d6780820c2025b9967aedaa259bdbb9f3d0297eced0e18";
let alice = create_account_from_ed25519_public_key(pk);
create_account(signer::address_of(&bob));
/*
TODO bring back with generic rotation capability
#[test(bob = @0x345)]
#[expected_failure(abort_code = 65544)]
public entry fun test_invalid_offer_rotation_capability(bob: signer) acquires Account {
let pk = x"f66bf0ce5ceb582b93d6780820c2025b9967aedaa259bdbb9f3d0297eced0e18";
let alice = create_account_from_ed25519_public_key(pk);
create_account(signer::address_of(&bob));

let invalid_signature = x"78f7d09ef7a9d8d7450d600b10231e6512610f919a63bd71bea1c907f7e101ed333bff360eeda97a8637a53fd622d597c03a0d6fd1315c6fa23719983ff7de0c";
offer_rotation_capability_ed25519(&alice, invalid_signature, pk, signer::address_of(&bob));
}
*/
let invalid_signature = x"78f7d09ef7a9d8d7450d600b10231e6512610f919a63bd71bea1c907f7e101ed333bff360eeda97a8637a53fd622d597c03a0d6fd1315c6fa23719983ff7de0c";
offer_rotation_capability_ed25519(&alice, invalid_signature, pk, signer::address_of(&bob));
}
*/

#[test(bob = @0x345)]
#[expected_failure(abort_code = 65544)]
Expand Down Expand Up @@ -588,7 +592,7 @@ TODO bring back with generic rotation capability
assert!(signer::address_of(&signer) == signer::address_of(&alice), 0);
}

#[test(bob = @0x345, charlie=@0x567)]
#[test(bob = @0x345, charlie = @0x567)]
#[expected_failure(abort_code = 393230)]
public entry fun test_invalid_check_signer_capability_and_create_authorized_signer(bob: signer, charlie: signer) acquires Account {
let pk = x"f66bf0ce5ceb582b93d6780820c2025b9967aedaa259bdbb9f3d0297eced0e18";
Expand All @@ -615,7 +619,7 @@ TODO bring back with generic rotation capability
revoke_signer_capability(&alice, signer::address_of(&bob));
}

#[test(bob = @0x345, charlie=@0x567)]
#[test(bob = @0x345, charlie = @0x567)]
#[expected_failure(abort_code = 393230)]
public entry fun test_invalid_revoke_signer_capability(bob: signer, charlie: signer) acquires Account {
let pk = x"f66bf0ce5ceb582b93d6780820c2025b9967aedaa259bdbb9f3d0297eced0e18";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
spec aptos_framework::account {
spec create_signer { // TODO: temporary mockup.
spec create_signer {
// TODO: temporary mockup.
pragma opaque;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
spec aptos_framework::aggregator {
spec module {
pragma verify=false;
pragma verify = false;
}

spec add { // TODO: temporary mockup.
spec add {
// TODO: temporary mockup.
pragma opaque;
}

spec sub { // TODO: temporary mockup.
spec sub {
// TODO: temporary mockup.
pragma opaque;
}

spec read { // TODO: temporary mockup.
spec read {
// TODO: temporary mockup.
pragma opaque;
}

spec destroy { // TODO: temporary mockup.
spec destroy {
// TODO: temporary mockup.
pragma opaque;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
spec aptos_framework::aggregator_factory {
spec module {
pragma verify=false;
pragma verify = false;
}

spec new_aggregator { // TODO: temporary mockup.
spec new_aggregator {
// TODO: temporary mockup.
pragma opaque;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module aptos_framework::optional_aggregator {
}

fun destroy_integer(integer: Integer) {
let Integer {value: _, limit: _ } = integer;
let Integer { value: _, limit: _ } = integer;
}

/// Struct that contains either an aggregator or a normal integer, both
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spec aptos_framework::optional_aggregator {
spec module {
pragma verify=false;
pragma verify = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module aptos_framework::aptos_account {
}

public entry fun transfer(source: &signer, to: address, amount: u64) {
if(!account::exists_at(to)) {
if (!account::exists_at(to)) {
create_account(to)
};
coin::transfer<AptosCoin>(source, to, amount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module aptos_framework::aptos_coin {
/// Cannot find delegation of mint capability to this account
const EDELEGATION_NOT_FOUND: u64 = 3;

struct AptosCoin has key { }
struct AptosCoin has key {}

struct MintCapStore has key {
mint_cap: MintCapability<AptosCoin>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module aptos_framework::aptos_governance {
system_addresses::assert_framework_reserved_address(aptos_framework);

if (!exists<GovernanceResponsbility>(@aptos_framework)) {
move_to(aptos_framework, GovernanceResponsbility{ signer_caps: simple_map::create<address, SignerCapability>() });
move_to(aptos_framework, GovernanceResponsbility { signer_caps: simple_map::create<address, SignerCapability>() });
};

let signer_caps = &mut borrow_global_mut<GovernanceResponsbility>(@aptos_framework).signer_caps;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spec aptos_framework::chain_status {
spec set_genesis_end {
pragma verify=false;
pragma verify = false;
}

spec schema RequiresIsOperating {
Expand Down
24 changes: 12 additions & 12 deletions aptos-move/framework/aptos-framework/sources/code.move
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ module aptos_framework::code {
/// The developer is responsible for not breaking memory layout of any resources he already
/// stored on chain.
public fun upgrade_policy_arbitrary(): UpgradePolicy {
UpgradePolicy{policy: 0}
UpgradePolicy { policy: 0 }
}

/// Whether a compatibility check should be performed for upgrades. The check only passes if
/// a new module has (a) the same public functions (b) for existing resources, no layout change.
public fun upgrade_policy_compat(): UpgradePolicy {
UpgradePolicy{policy: 1}
UpgradePolicy { policy: 1 }
}

/// Whether the modules in the package are immutable and cannot be upgraded.
public fun upgrade_policy_immutable(): UpgradePolicy {
UpgradePolicy{policy: 2}
UpgradePolicy { policy: 2 }
}

/// Whether the upgrade policy can be changed. In general, the policy can be only
Expand All @@ -121,7 +121,7 @@ module aptos_framework::code {
system_addresses::assert_aptos_framework(aptos_framework);
let addr = signer::address_of(package_owner);
if (!exists<PackageRegistry>(addr)) {
move_to(package_owner, PackageRegistry{packages: vector[metadata]})
move_to(package_owner, PackageRegistry { packages: vector[metadata] })
} else {
vector::push_back(&mut borrow_global_mut<PackageRegistry>(addr).packages, metadata)
}
Expand All @@ -138,7 +138,7 @@ module aptos_framework::code {

let addr = signer::address_of(owner);
if (!exists<PackageRegistry>(addr)) {
move_to(owner, PackageRegistry{packages: vector::empty()})
move_to(owner, PackageRegistry { packages: vector::empty() })
};

// Checks for valid dependencies to other packages
Expand Down Expand Up @@ -178,8 +178,8 @@ module aptos_framework::code {
if (features::code_dependency_check_enabled())
request_publish_with_allowed_deps(addr, module_names, allowed_deps, code, policy.policy)
else
// The new `request_publish_with_allowed_deps` has not yet rolled out, so call downwards
// compatible code.
// The new `request_publish_with_allowed_deps` has not yet rolled out, so call downwards
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks bad. Can we throw {} around the if/else?

// compatible code.
request_publish(addr, module_names, code, policy.policy)
}

Expand All @@ -195,10 +195,10 @@ module aptos_framework::code {

/// Checks whether the given package is upgradable, and returns true if a compatibility check is needed.
fun check_upgradability(
old_pack: &PackageMetadata, new_pack: &PackageMetadata, new_modules: &vector<String>) {
old_pack: &PackageMetadata, new_pack: &PackageMetadata, new_modules: &vector<String>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good formatting rule. The parameters should not be intended the same as the body

assert!(old_pack.upgrade_policy.policy < upgrade_policy_immutable().policy,
error::invalid_argument(EUPGRADE_IMMUTABLE));
assert!(can_change_upgrade_policy_to( old_pack.upgrade_policy, new_pack.upgrade_policy),
assert!(can_change_upgrade_policy_to(old_pack.upgrade_policy, new_pack.upgrade_policy),
error::invalid_argument(EUPGRADE_WEAKER_POLICY));
let old_modules = get_module_names(old_pack);
let i = 0;
Expand Down Expand Up @@ -243,7 +243,7 @@ module aptos_framework::code {
// Allow all modules from this address, by using "" as a wildcard in the AllowedDep
let account = dep.account;
let module_name = string::utf8(b"");
vector::push_back(&mut allowed_module_deps, AllowedDep{account, module_name});
vector::push_back(&mut allowed_module_deps, AllowedDep { account, module_name });
i = i + 1;
continue
};
Expand Down Expand Up @@ -272,7 +272,7 @@ module aptos_framework::code {
while (k < r) {
let account = dep.account;
let module_name = vector::borrow(&dep_pack.modules, k).name;
vector::push_back(&mut allowed_module_deps, AllowedDep{account, module_name});
vector::push_back(&mut allowed_module_deps, AllowedDep { account, module_name });
k = k + 1;
};
break
Expand All @@ -290,7 +290,7 @@ module aptos_framework::code {
/// requires to be upgradable for maintenance and evolution, and is configured to be `compatible`.
fun is_policy_exempted_address(addr: address): bool {
addr == @1 || addr == @2 || addr == @3 || addr == @4 || addr == @5 ||
addr == @6 || addr == @7 || addr == @8 || addr == @9 || addr == @10
addr == @6 || addr == @7 || addr == @8 || addr == @9 || addr == @10
}

/// Get the names of the modules in a package.
Expand Down
8 changes: 5 additions & 3 deletions aptos-move/framework/aptos-framework/sources/code.spec.move
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
spec aptos_framework::code {
spec module {
pragma verify=false;
pragma verify = false;
}

spec request_publish { // TODO: temporary mockup.
spec request_publish {
// TODO: temporary mockup.
pragma opaque;
}

spec request_publish_with_allowed_deps { // TODO: temporary mockup.
spec request_publish_with_allowed_deps {
// TODO: temporary mockup.
pragma opaque;
}
}
Loading