Module sui_system::validator_wrapper
- Struct
ValidatorWrapper
- Constants
- Function
create_v1
- Function
load_validator_maybe_upgrade
- Function
destroy
- Function
upgrade_to_latest
- Function
version
use std::address;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::type_name;
use std::u64;
use std::vector;
use sui::address;
use sui::bag;
use sui::balance;
use sui::coin;
use sui::config;
use sui::deny_list;
use sui::dynamic_field;
use sui::dynamic_object_field;
use sui::event;
use sui::hex;
use sui::object;
use sui::sui;
use sui::table;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::url;
use sui::vec_set;
use sui::versioned;
use sui_system::staking_pool;
use sui_system::validator;
use sui_system::validator_cap;
Struct ValidatorWrapper
public struct ValidatorWrapper has store
Click to open
Fields
- inner: sui::versioned::Versioned
Constants
const EInvalidVersion: u64 = 0;
Function create_v1
public(package) fun create_v1(validator: sui_system::validator::Validator, ctx: &mut sui::tx_context::TxContext): sui_system::validator_wrapper::ValidatorWrapper
Click to open
Implementation
public(package) fun create_v1(validator: Validator, ctx: &mut TxContext): ValidatorWrapper {
ValidatorWrapper {
inner: versioned::create(1, validator, ctx)
}
}
Function load_validator_maybe_upgrade
This function should always return the latest supported version. If the inner version is old, we upgrade it lazily in-place.
public(package) fun load_validator_maybe_upgrade(self: &mut sui_system::validator_wrapper::ValidatorWrapper): &mut sui_system::validator::Validator
Click to open
Implementation
public(package) fun load_validator_maybe_upgrade(self: &mut ValidatorWrapper): &mut Validator {
upgrade_to_latest(self);
versioned::load_value_mut(&mut self.inner)
}
Function destroy
Destroy the wrapper and retrieve the inner validator object.
public(package) fun destroy(self: sui_system::validator_wrapper::ValidatorWrapper): sui_system::validator::Validator
Click to open
Implementation
public(package) fun destroy(self: ValidatorWrapper): Validator {
upgrade_to_latest(&self);
let ValidatorWrapper { inner } = self;
versioned::destroy(inner)
}
Function upgrade_to_latest
fun upgrade_to_latest(self: &sui_system::validator_wrapper::ValidatorWrapper)
Click to open
Implementation
fun upgrade_to_latest(self: &ValidatorWrapper) {
let version = version(self);
// TODO: When new versions are added, we need to explicitly upgrade here.
assert!(version == 1, EInvalidVersion);
}
Function version
fun version(self: &sui_system::validator_wrapper::ValidatorWrapper): u64
Click to open
Implementation
fun version(self: &ValidatorWrapper): u64 {
versioned::version(&self.inner)
}