api

package
v0.0.0-...-bdfcca1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: Apache-2.0 Imports: 12 Imported by: 3

README

API for cosmos-sdk-based chains

TODOs: after PoC

  • APIs to other module

Documentation

Index

Constants

View Source
const CanonicalLength = 32
View Source
const (
	CostTransfer uint64 = 100
)

Variables

This section is empty.

Functions

func BuildContract

func BuildContract(arg types.InitiaCompilerArgument) ([]byte, error)

func CleanContractPackage

func CleanContractPackage(arg types.InitiaCompilerArgument, cleanCache, cleanByproduct, force bool) ([]byte, error)

func CreateContractPackage

func CreateContractPackage(arg types.InitiaCompilerArgument, name string) ([]byte, error)

func DecodeModuleBytes

func DecodeModuleBytes(
	moduleBytes []byte,
) ([]byte, error)

DecodeModuleBytes decode module bytes to MoveModule instance and return as jSON string

func DecodeMoveResource

func DecodeMoveResource(
	store KVStore,
	structTag []byte,
	resourceBytes []byte,
) ([]byte, error)

DecodeMoveResource decode resource bytes to move resource instance and return as jSON string

func DecodeScriptBytes

func DecodeScriptBytes(
	scriptBytes []byte,
) ([]byte, error)

DecodeScriptBytes decode script bytes to MoveFunction instance and return as jSON string

func ExecuteContract

func ExecuteContract(
	vm VM,
	store KVStore,
	api GoAPI,
	verbose bool,
	gasLimit uint64,
	sessionID []byte,
	sender []byte,
	message []byte,
) ([]byte, error)

ExecuteContract call ffi(`execute_contract`) to execute script with write_op reflection

func ExecuteScript

func ExecuteScript(
	vm VM,
	store KVStore,
	api GoAPI,
	verbose bool,
	gasLimit uint64,
	sessionID []byte,
	sender []byte,
	message []byte,
) ([]byte, error)

ExecuteScript call ffi(`execute_script`) to execute entry function with write_op reflection

func Initialize

func Initialize(
	vm VM,
	store KVStore,
	api GoAPI,
	verbose bool,
	moduleBundle []byte,
) error

Initialize call ffi(`initialize`) to initialize vm and publish standard libraries CONTRACT: should be executed at chain genesis

func LibinitiaVersion

func LibinitiaVersion() (string, error)

func PublishModuleBundle

func PublishModuleBundle(
	vm VM,
	store KVStore,
	api GoAPI,
	isVerbose bool,
	gasLimit uint64,
	sessionID []byte,
	sender []byte,
	moduleBundle []byte,
) ([]byte, error)

PublishModuleBundle call ffi(`publish_module_bundle`) to store module bundle

func QueryContract

func QueryContract(
	vm VM,
	store KVStore,
	api GoAPI,
	verbose bool,
	gasLimit uint64,
	message []byte,
) ([]byte, error)

QueryContract call ffi(`query_contract`) to get entry function execution result without write_op reflection

func ReleaseVM

func ReleaseVM(vm VM)

ReleaseVM call ffi(`release_vm`) to release vm instance

func TestContract

func TestContract(arg types.InitiaCompilerArgument, testConfig types.TestConfig) ([]byte, error)

Types

type DBState

type DBState struct {
	Store KVStore
	// CallID is used to lookup the proper frame for iterators associated with this contract call (iterator.go)
	CallID uint64
}

type Gas

type Gas = uint64

type GasMeter

type GasMeter interface {
	GasConsumed() Gas
}

GasMeter is a copy of an interface declaration from cosmos-sdk https://github.com/cosmos/cosmos-sdk/blob/18890a225b46260a9adc587be6fa1cc2aff101cd/store/types/gas.go#L34

type GoAPI

type GoAPI interface {
	GetBlockInfo() (uint64, uint64)
	AmountToShare([]byte, uint64) (uint64, error)
	ShareToAmount([]byte, uint64) (uint64, error)
	UnbondTimestamp() uint64
}

type KVStore

type KVStore interface {
	Get(key []byte) []byte
	Set(key, value []byte)
	Delete(key []byte)

	// Iterator over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// To iterate over entire domain, use store.Iterator(nil, nil)
	Iterator(start, end []byte) dbm.Iterator

	// Iterator over a domain of keys in descending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	ReverseIterator(start, end []byte) dbm.Iterator
}

KVStore copies a subset of types from cosmos-sdk We may wish to make this more generic sometime in the future, but not now https://github.com/cosmos/cosmos-sdk/blob/bef3689245bab591d7d169abd6bea52db97a70c7/store/types/store.go#L170

type Lookup

type Lookup struct {
	// contains filtered or unexported fields
}

func NewLookup

func NewLookup() *Lookup

func (Lookup) Delete

func (l Lookup) Delete(key []byte)

Delete wraps the underlying DB's Delete method panicing on error.

func (Lookup) Get

func (l Lookup) Get(key []byte) []byte

Get wraps the underlying DB's Get method panicing on error.

func (Lookup) Iterator

func (l Lookup) Iterator(start, end []byte) dbm.Iterator

Iterator wraps the underlying DB's Iterator method panicing on error.

func (Lookup) ReverseIterator

func (l Lookup) ReverseIterator(start, end []byte) dbm.Iterator

ReverseIterator wraps the underlying DB's ReverseIterator method panicing on error.

func (Lookup) Set

func (l Lookup) Set(key, value []byte)

Set wraps the underlying DB's Set method panicing on error.

type MockAPI

type MockAPI struct {
	BlockAPI   *MockBlockAPI
	StakingAPI *MockStakingAPI
}

func NewMockAPI

func NewMockAPI(blockAPI *MockBlockAPI, stakingAPI *MockStakingAPI) *MockAPI

func (MockAPI) AmountToShare

func (m MockAPI) AmountToShare(validator []byte, amount uint64) (uint64, error)

func (MockAPI) GetBlockInfo

func (m MockAPI) GetBlockInfo() (uint64, uint64)

func (MockAPI) ShareToAmount

func (m MockAPI) ShareToAmount(validator []byte, share uint64) (uint64, error)

func (MockAPI) UnbondTimestamp

func (m MockAPI) UnbondTimestamp() uint64

type MockBlockAPI

type MockBlockAPI struct {
	// contains filtered or unexported fields
}

func NewMockBlockAPI

func NewMockBlockAPI(height uint64, timestamp uint64) MockBlockAPI

NewMockBlockAPI return MockBlockAPI instance

func (MockBlockAPI) GetBlockInfo

func (m MockBlockAPI) GetBlockInfo() (uint64, uint64)

type MockStakingAPI

type MockStakingAPI struct {
	// contains filtered or unexported fields
}

func NewMockStakingAPI

func NewMockStakingAPI() MockStakingAPI

NewMockStakingAPI return MockStakingAPI instance

func (MockStakingAPI) AmountToShare

func (m MockStakingAPI) AmountToShare(validator []byte, amount uint64) (uint64, error)

func (MockStakingAPI) SetShareRatio

func (m MockStakingAPI) SetShareRatio(validator []byte, share uint64, amount uint64)

func (MockStakingAPI) ShareToAmount

func (m MockStakingAPI) ShareToAmount(validator []byte, share uint64) (uint64, error)

type ShareAmountRatio

type ShareAmountRatio struct {
	// contains filtered or unexported fields
}

type VM

type VM struct {
	// contains filtered or unexported fields
}

func AllocateVM

func AllocateVM() VM

AllocateVM call ffi(`allocate_vm`) to allocate vm instance

Jump to

Keyboard shortcuts

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