Skip to content
Open
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
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 aptos-move/e2e-move-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ aptos-vm-environment = { workspace = true }
bcs = { workspace = true }
claims = { workspace = true }
hex = { workspace = true }
libsecp256k1 = { workspace = true }
move-binary-format = { workspace = true }
move-core-types = { workspace = true }
move-model = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "attestation_gated"
version = "0.0.0"

[dependencies]
AptosFramework = { local = "../../../../../framework/aptos-framework" }

[addresses]
gated = "0xcafe"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/// A minimal consumer of `aptos_framework::attestation_policy`: the whole integration surface a
/// business touches is one call at the top of each gated entry function.
module gated::vault {
use std::signer;
use aptos_framework::attestation_policy;

/// Matches `attestation_policy::ACTION_TRANSFER`.
const ACTION_TRANSFER: u8 = 1;

/// Counts gated actions that went through, so a test can tell a success from a no-op.
struct Transfers has key {
count: u64,
total: u64
}

public entry fun transfer(user: &signer, policy: address, amount: u64) acquires Transfers {
attestation_policy::require(policy, signer::address_of(user), ACTION_TRANSFER, amount);
record(user, amount);
}

public entry fun transfer_authorized(
user: &signer, policy: address, amount: u64, authorization: vector<u8>
) acquires Transfers {
attestation_policy::require_authorized(
policy,
signer::address_of(user),
ACTION_TRANSFER,
amount,
authorization
);
record(user, amount);
}

#[view]
public fun count_of(user: address): u64 acquires Transfers {
if (exists<Transfers>(user)) { Transfers[user].count } else { 0 }
}

fun record(user: &signer, amount: u64) acquires Transfers {
let addr = signer::address_of(user);
if (!exists<Transfers>(addr)) {
move_to(user, Transfers { count: 0, total: 0 });
};
let transfers = &mut Transfers[addr];
transfers.count += 1;
transfers.total += amount;
}
}
Loading
Loading