/** * A bag is a heterogeneous map-like collection. The collection is similar to `sui::table` in that * its keys and values are not stored within the `Bag` value, but instead are stored using Sui's * object system. The `Bag` struct acts only as a handle into the object system to retrieve those * keys and values. * Note that this means that `Bag` values with exactly the same key-value mapping will not be * equal, with `==`, at runtime. For example * ``` * let bag1 = bag::new(); * let bag2 = bag::new(); * bag::add(&mut bag1, 0, false); * bag::add(&mut bag1, 1, true); * bag::add(&mut bag2, 0, false); * bag::add(&mut bag2, 1, true); * // bag1 does not equal bag2, despite having the same entries * assert!(&bag1 != &bag2); * ``` * At it's core, `sui::bag` is a wrapper around `UID` that allows for access to * `sui::dynamic_field` while preventing accidentally stranding field values. A `UID` can be * deleted, even if it has dynamic fields associated with it, but a bag, on the other hand, must be * empty to be destroyed. */ import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client'; import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from '../../../_framework/reified'; import { FieldsWithTypes } from '../../../_framework/util'; import { UID } from '../object/structs'; export declare function isBag(type: string): boolean; export interface BagFields { /** the ID of this bag */ id: ToField; /** the number of key-value pairs in the bag */ size: ToField<'u64'>; } export type BagReified = Reified; export type BagJSONField = { id: string; size: string; }; export type BagJSON = { $typeName: typeof Bag.$typeName; $typeArgs: []; } & BagJSONField; export declare class Bag implements StructClass { __StructClass: true; static readonly $typeName: `0x2::bag::Bag`; static readonly $numTypeParams = 0; static readonly $isPhantom: readonly []; readonly $typeName: typeof Bag.$typeName; readonly $fullTypeName: `0x2::bag::Bag`; readonly $typeArgs: []; readonly $isPhantom: typeof Bag.$isPhantom; /** the ID of this bag */ readonly id: ToField; /** the number of key-value pairs in the bag */ readonly size: ToField<'u64'>; private constructor(); static reified(): BagReified; static get r(): BagReified; static phantom(): PhantomReified>; static get p(): PhantomReified>; private static instantiateBcs; private static cachedBcs; static get bcs(): ReturnType; static fromFields(fields: Record): Bag; static fromFieldsWithTypes(item: FieldsWithTypes): Bag; static fromBcs(data: Uint8Array): Bag; toJSONField(): BagJSONField; toJSON(): BagJSON; static fromJSONField(field: any): Bag; static fromJSON(json: Record): Bag; static fromCoreObject(obj: SuiClientTypes.Object<{ content: true; }>): Bag; static fetch(client: ClientWithCoreApi, id: string): Promise; }