u64

package
v0.1.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2022 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Uint64

Example
package main

import (
	"fmt"

	globalSym "bitbucket.org/taubyte/go-sdk-symbols/globals"
	"bitbucket.org/taubyte/go-sdk/globals/scope"
	"bitbucket.org/taubyte/go-sdk/globals/u64"
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	globalSym.MockData{
		Data: map[string][]uint8{
			"/uint64/count":             {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10},
			"/application/uint64/count": {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x15},
		},
	}.Mock()

	{
		count, err := u64.GetOrCreate("count")
		if err != nil {
			return
		}

		fmt.Println("Global scope:", count.Value())

		err = count.Set(23)
		if err != nil {
			return
		}

		count, err = u64.Get("count")
		if err != nil {
			return
		}

		fmt.Println("Global scope set:", count.Value())
	}

	{
		count, err := u64.Get("count", scope.Application)
		if err != nil {
			return
		}

		fmt.Println("Application scope:", count.Value())
	}

}
Output:

Global scope: 16
Global scope set: 23
Application scope: 533

func Get

func Get(name string, scope ...internal.Option) (Uint64, error)

func GetOrCreate

func GetOrCreate(name string, scope ...internal.Option) (Uint64, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL