Class Args

Args for remote function call.

Remarks

  • This class can serialize assembly script native types into bytes, in order to make smart-contract function call easier.

  • In a smart-contract exposed function, use this class to deserialize the string argument, using the next... methods.

  • In a smart-contract, to call another smart-contract function, use this class to serialize the arguments you want to pass to the smart-contract function call.

Hierarchy

  • Args

Constructors

  • Initializes a new instance of Args.

    Parameters

    • serialized: StaticArray<number> = []

      The serialized arguments. Default: []

    • offset: number = 0

      The offset to start deserializing from. Default: 0

    Returns Args

Accessors

  • get offset(): number
  • Gets the offset to start deserializing from.

    Returns number

    the offset

Methods

  • This method adds an argument to the serialized byte array if the argument is an instance of a handled type (bool, String of u32.MAX_VALUE characters maximum, Uint8Array, StaticArray, u8, u32, i32, u64, i64, f32, f64, Serializable).

    Type Parameters

    • T

    Parameters

    • arg: T

      the argument to add

    Returns Args

    the modified Arg instance

    Remarks

    If the type of the object to add isn't handled, it returns an error message: "args doesn't know how to serialize the given type."

  • This method adds an array of elements that implement Serializable.

    Type Parameters

    Parameters

    • arg: T[]

      the argument to add

    Returns Args

    the modified Arg instance

    Remarks

    This will perform a deep copy of your objects thanks to the serialize method you define in your class.

    See

    Serializable

  • Deserializes a boolean from a serialized array starting from the current offset.

    Returns Result<bool>

    a Result object:

    • Containing the next deserialized boolean starting from the current offset
    • Containing false and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing false and an error message: "can't deserialize bool from given argument: out of range".

  • Deserializes a bytes array from a serialized array starting from the current offset.

    Returns Result<StaticArray<number>>

    a Result object:

    • Containing the next deserialized StaticArray of u8 starting from the current offset
    • Containing an empty StaticArray and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing an empty StaticArray of u8 and an error message: "can't deserialize bytes from given argument: out of range". In this case, the offset will not be changed.

  • Deserializes an F32 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized f32 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize f32 from given argument: out of range".

  • Deserializes an f64 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized f64 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize f64 from given argument: out of range".

  • Deserializes an array of fixed size elements starting from the current offset.

    Type Parameters

    • T

    Returns Result<T[]>

    a Result object:

    • Containing the next deserialized array of fixed size elements
    • Containing an empty array and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result object containing an empty array and an error message: "can't deserialize length of array from given argument". In this case, the offset will not be changed.

  • Deserializes an i16 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized i16 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize i16 from given argument: out of range".

  • Deserializes an i256 from a serialized array starting from the current offset.

    Returns Result<i256>

    a Result object:

    • Containing the next deserialized i256 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize i256 from given argument: out of range".

  • Deserializes an i32 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized i32 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize i32 from given argument: out of range".

  • Deserializes an I64 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized I64 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize i64 from given argument: out of range".

  • Deserialize an object by calling its deserialize method.

    Type Parameters

    Returns Result<T>

    a Result object:

    • Containing the next deserialized object starting from the current offset
    • Containing the object and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing the object and an error message: "Can't deserialize object " + type of the object.

  • Deserializes an array of serializable objects from a serialized array starting from the current offset.

    Type Parameters

    Returns Result<T[]>

    a Result object:

    • Containing the next deserialized array of objects that implement Serializable objects starting from the current offset
    • Containing an empty array and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing an empty array and an error message: "can't deserialize length of array from given argument".

  • Deserializes a string from a serialized array starting from the current offset.

    Returns Result<string>

    a Result object:

    • Containing the next deserialized string starting from the current offset.
    • Containing an empty string and an error message if the deserialization failed.

    Remarks

    If the deserialization failed, it returns a Result object containing an empty string and an error message: "can't deserialize string from given argument: out of range". In this case, the offset will not be changed.

  • Deserializes an array of strings starting from the current offset.

    Returns Result<string[]>

    a Result object:

    • Containing the next deserialized array of strings
    • Containing an empty array and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result object containing an empty array and an error message: "can't deserialize length of array from given argument". In this case, the offset will not be changed.

  • Deserializes an U128 from a serialized array starting from the current offset.

    Returns Result<u128>

    a Result object:

    • Containing the next deserialized U128 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize u128 from given argument: out of range".

  • Deserializes an u16 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized u16 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize u16 from given argument: out of range".

  • Deserializes an u256 from a serialized array starting from the current offset.

    Returns Result<u256>

    a Result object:

    • Containing the next deserialized u256 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize u256 from given argument: out of range".

  • Deserializes an u32 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized u32 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize u32 from given argument: out of range".

  • Deserializes an U64 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized U64 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize u64 from given argument: out of range".

  • Deserializes an u8 from a serialized array starting from the current offset.

    Returns Result<number>

    a Result object:

    • Containing the next deserialized u8 starting from the current offset
    • Containing 0 and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing 0 and an error message: "can't deserialize u8 from given argument: out of range".

  • Deserializes an array of u8 from a serialized array starting from the current offset.

    Returns Result<Uint8Array>

    a Result object:

    • Containing the next deserialized array of u8 starting from the current offset
    • Containing an empty Uint8Array and an error message if the deserialization failed

    Remarks

    If the deserialization failed, it returns a Result containing an empty Uint8Array and an error message: "can't deserialize Uint8Array from given argument: out of range".

  • Returns the serialized arguments.

    Returns StaticArray<number>

    The serialized arguments as a static array of bytes.

Generated using TypeDoc