Skip to main content

Module sui::accumulator_metadata

use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::accumulator;
use sui::address;
use sui::bag;
use sui::dynamic_field;
use sui::hex;
use sui::object;
use sui::party;
use sui::transfer;
use sui::tx_context;
use sui::vec_map;

Struct OwnerKey

=== Accumulator metadata ===

Metadata system has been removed, but structs must remain for backwards compatibility.

public struct OwnerKey has copy, drop, store
Click to open
Fields
owner: address

Struct Owner

An owner field, to which all AccumulatorMetadata fields for the owner are attached.

public struct Owner has store
Click to open
Fields
balances: sui::bag::Bag
The individual balances owned by the owner.
owner: address

Struct MetadataKey

public struct MetadataKey<phantom T> has copy, drop, store
Click to open
Fields

Struct Metadata

A metadata field for a balance field with type T.

public struct Metadata<phantom T> has store
Click to open
Fields
fields: sui::bag::Bag
Any per-balance fields we wish to add in the future.

Struct AccumulatorObjectCountKey

=== Accumulator object count storage === Key for storing the net count of accumulator objects as a dynamic field on the accumulator root.

public struct AccumulatorObjectCountKey has copy, drop, store
Click to open
Fields

Constants

const EInvariantViolation: u64 = 0;

Function record_accumulator_object_changes

Records changes in the net count of accumulator objects. Called by the barrier transaction as part of accumulator settlement.

This value is copied to the Sui system state object at end-of-epoch by the WriteAccumulatorStorageCost transaction, for use in storage fund accounting. Copying once at end-of-epoch lets us avoid depending on the Sui system state object in the settlement barrier transaction.

fun record_accumulator_object_changes(accumulator_root: &mut sui::accumulator::AccumulatorRoot, objects_created: u64, objects_destroyed: u64)
Click to open
Implementation
fun record_accumulator_object_changes(
    accumulator_root: &mut AccumulatorRoot,
    objects_created: u64,
    objects_destroyed: u64,
) {
    let key = AccumulatorObjectCountKey();
    if (dynamic_field::exists_(accumulator_root.id_mut(), key)) {
        let current_count: &mut u64 = dynamic_field::borrow_mut(accumulator_root.id_mut(), key);
        assert!(*current_count + objects_created >= objects_destroyed, EInvariantViolation);
        *current_count = *current_count + objects_created - objects_destroyed;
    } else {
        assert!(objects_created >= objects_destroyed, EInvariantViolation);
        dynamic_field::add(accumulator_root.id_mut(), key, objects_created - objects_destroyed);
    };
}

Function get_accumulator_object_count

Returns the current count of accumulator objects stored as a dynamic field.

fun get_accumulator_object_count(accumulator_root: &sui::accumulator::AccumulatorRoot): u64
Click to open
Implementation
fun get_accumulator_object_count(accumulator_root: &AccumulatorRoot): u64 {
    let key = AccumulatorObjectCountKey();
    if (dynamic_field::exists_(accumulator_root.id(), key)) {
        *dynamic_field::borrow(accumulator_root.id(), key)
    } else {
        0
    }
}