Skip to main content

Module 0x3::validator_wrapper

use 0x2::tx_context; use 0x2::versioned; use 0x3::validator;

Struct Validator

struct Validator has store

Fields

Constants

const EInvalidVersion: u64 = 0;

Function create_v1

public(friend) fun create_v1(validator: validator::ValidatorV1, ctx: &mut tx_context::TxContext): validator_wrapper::Validator

Implementation

public(package) fun create_v1(validator: ValidatorV1, ctx: &mut TxContext): Validator { Validator { 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(friend) fun load_validator_maybe_upgrade(self: &mut validator_wrapper::Validator): &mut validator::ValidatorV1

Implementation

public(package) fun load_validator_maybe_upgrade(self: &mut Validator): &mut ValidatorV1 { upgrade_to_latest(self); versioned::load_value_mut(&mut self.inner) }

Function destroy

Destroy the wrapper and retrieve the inner validator object.

public(friend) fun destroy(self: validator_wrapper::Validator): validator::ValidatorV1

Implementation

public(package) fun destroy(self: Validator): ValidatorV1 { upgrade_to_latest(&self); let Validator { inner } = self; versioned::destroy(inner) }

Function upgrade_to_latest

fun upgrade_to_latest(self: &validator_wrapper::Validator)

Implementation

fun upgrade_to_latest(self: &Validator) { 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: &validator_wrapper::Validator): u64

Implementation

fun version(self: &Validator): u64 { versioned::version(&self.inner) }