std

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_ARRAY_SIZE = 8

random constant for the size to preallocate arrays before parsing

View Source
const MOCK_CONTRACT_ADDR = "test-contract"
View Source
const REGION_HEAD_SIZE uint32 = 12

Variables

This section is empty.

Functions

func BuildBase64Message

func BuildBase64Message(msg string) string

func BytesToInt64

func BytesToInt64(buf []byte) int64

func BytesToString

func BytesToString(buf []byte) string

func BytesToUint64

func BytesToUint64(b []byte) uint64

func Deallocate

func Deallocate(pointer unsafe.Pointer)

func DisplayMessage

func DisplayMessage(msg []byte) int

func Package_message

func Package_message(msg []byte) unsafe.Pointer

func TranslateToRegion

func TranslateToRegion(b []byte, ptr uintptr) uintptr

func TranslateToSlice

func TranslateToSlice(ptr uintptr) []byte

func Translate_range_custom

func Translate_range_custom(ptr uintptr) []byte

func Uint64toBytes

func Uint64toBytes(v uint64) []byte

Types

type AllBalancesQuery

type AllBalancesQuery struct {
	Address string `json:"address"`
}

type AllBalancesResponse

type AllBalancesResponse struct {
	Amount Coins `json:"amount"`
}

AllBalancesResponse is the expected response to AllBalancesQuery

type AllDelegationsQuery

type AllDelegationsQuery struct {
	Delegator string `json:"delegator"`
}

type AllDelegationsResponse

type AllDelegationsResponse struct {
	Delegations Delegations `json:"delegations"`
}

AllDelegationsResponse is the expected response to AllDelegationsQuery

type Api

type Api interface {
	CanonicalAddress(human string) (CanonicalAddr, error)
	HumanAddress(canonical CanonicalAddr) (string, error)
	Debug(msg string)
}

type Attribute

type Attribute struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type BalanceQuery

type BalanceQuery struct {
	Address string `json:"address"`
	Denom   string `json:"denom"`
}

type BalanceResponse

type BalanceResponse struct {
	Amount Coin `json:"amount"`
}

BalanceResponse is the expected response to BalanceQuery

type BankMsg

type BankMsg struct {
	Send SendMsg `json:"send"`
}

type BankQuery

type BankQuery struct {
	Balance     BalanceQuery     `json:"balance,omitempty"`
	AllBalances AllBalancesQuery `json:"all_balances,omitempty"`
}

func (BankQuery) IsEmpty

func (b BankQuery) IsEmpty() bool

type BlockInfo

type BlockInfo struct {
	// block height this transaction is executed
	Height uint64 `json:"height"`
	// time in seconds since unix epoch - since cosmwasm 0.3
	Time      uint64 `json:"time"`
	TimeNanos uint64 `json:"time_nanos"`
	ChainID   string `json:"chain_id"`
}

type BondedDenomResponse

type BondedDenomResponse struct {
	Denom string `json:"denom"`
}

type CanonicalAddr

type CanonicalAddr []byte

type Coin

type Coin struct {
	Denom  string `json:"denom"`  // type, eg. "ATOM"
	Amount string `json:"amount"` // string encoing of decimal value, eg. "12.3456"
}

Coin is a string representation of the sdk.Coin type (more portable than sdk.Int)

func NewCoin

func NewCoin(amount uint64, denom string) Coin

func TrimCoins

func TrimCoins(parsed []Coin) []Coin

We preallocate empty elements at the end for parsing. This will remove the ones that were not filled

func (Coin) IsEmpty

func (c Coin) IsEmpty() bool

type Coins

type Coins []Coin

Coins handles properly serializing empty amounts

func NewCoins

func NewCoins(amount uint64, denom string) Coins

func (Coins) MarshalJSON

func (c Coins) MarshalJSON() ([]byte, error)

MarshalJSON ensures that we get [] for empty arrays

type ContractInfo

type ContractInfo struct {
	// bech32 encoding of sdk.AccAddress of the contract, to be used when sending messages
	Address string `json:"address"`
}

type CosmosMsg

type CosmosMsg struct {
	Bank    BankMsg    `json:"bank,omitempty"`
	Custom  RawMessage `json:"custom,omitempty"`
	Staking StakingMsg `json:"staking,omitempty"`
	Wasm    WasmMsg    `json:"wasm,omitempty"`
}

CosmosMsg is an rust enum and only (exactly) one of the fields should be set Should we do a cleaner approach in Go? (type/data?)

type CosmosResponseError

type CosmosResponseError struct {
	Err StdError
}

func GenerateError

func GenerateError(errType ErrorType, msg string, msg_plus string) *CosmosResponseError

type DelegateMsg

type DelegateMsg struct {
	Validator string `json:"validator"`
	Amount    Coin   `json:"amount"`
}

type Delegation

type Delegation struct {
	Delegator string `json:"delegator"`
	Validator string `json:"validator"`
	Amount    Coin   `json:"amount"`
}

type DelegationQuery

type DelegationQuery struct {
	Delegator string `json:"delegator"`
	Validator string `json:"validator"`
}

type DelegationResponse

type DelegationResponse struct {
	Delegation *FullDelegation `json:"delegation,omitempty"`
}

DelegationResponse is the expected response to DelegationsQuery

type Delegations

type Delegations []Delegation

func (Delegations) MarshalJSON

func (d Delegations) MarshalJSON() ([]byte, error)

MarshalJSON ensures that we get [] for empty arrays

func (*Delegations) UnmarshalJSON

func (d *Delegations) UnmarshalJSON(data []byte) error

UnmarshalJSON ensures that we get [] for empty arrays

type Deps

type Deps struct {
	Storage Storage
	Api     Api
	Querier Querier
}

=========== Deps --> context =======

func MockDeps

func MockDeps(funds []Coin) *Deps

type Env

type Env struct {
	Block    BlockInfo    `json:"block"`
	Contract ContractInfo `json:"contract"`
}

Env defines the state of the blockchain environment this contract is running in. This must contain only trusted data - nothing from the Tx itself that has not been verfied (like Signer).

Env are json encoded to a byte slice before passing to the wasm contract.

func MockEnv

func MockEnv() Env

type ErrorType

type ErrorType uintptr
const (
	GenericError ErrorType = iota
	InvalidBase64Error
	InvalidUtf8Error
	NotFoundError
	NullPointerError
	ParseError
	SerializeError
	UnauthorizedError
	UnderflowError
)

type ExecuteMsg

type ExecuteMsg struct {
	// ContractAddr is the sdk.AccAddress of the contract, which uniquely defines
	// the contract ID and instance ID. The sdk module should maintain a reverse lookup table.
	ContractAddr string `json:"contract_addr"`
	// Msg is assumed to be a json-encoded message, which will be passed directly
	// as `userMsg` when calling `Handle` on the above-defined contract
	Msg []byte `json:"msg"`
	// Send is an optional amount of coins this contract sends to the called contract
	Send Coins `json:"send"`
}

ExecuteMsg is used to call another defined contract on this chain. The calling contract requires the callee to be defined beforehand, and the address should have been defined in initialization. And we assume the developer tested the ABIs and coded them together.

Since a contract is immutable once it is deployed, we don't need to transform this. If it was properly coded and worked once, it will continue to work throughout upgrades.

type FullDelegation

type FullDelegation struct {
	Delegator          string `json:"delegator"`
	Validator          string `json:"validator"`
	Amount             Coin   `json:"amount"`
	AccumulatedRewards []Coin `json:"accumulated_rewards"`
	CanRedelegate      Coin   `json:"can_redelegate"`
}

type GenericErr

type GenericErr struct {
	Msg string `json:"msg,omitempty"`
}

func (GenericErr) Error

func (e GenericErr) Error() string

type HandleResponse

type HandleResponse struct {
	// Messages comes directly from the contract and is it's request for action
	Messages []CosmosMsg `json:"messages"`
	// base64-encoded bytes to return as ABCI.Data field
	Data string `json:"data,rust_option"`
	// log message to return over abci interface
	Attributes []Attribute `json:"attributes"`
}

HandleResponse defines the return value on a successful handle

type HandleResultOk

type HandleResultOk struct {
	Ok HandleResponse `json:"ok"`
}

func HandleResultOkDefault

func HandleResultOkDefault() *HandleResultOk

type InitResponse

type InitResponse struct {
	// Messages comes directly from the contract and is it's request for action
	Messages []CosmosMsg `json:"messages"`
	// log message to return over abci interface
	Attributes []Attribute `json:"attributes"`
}

InitResponse defines the return value on a successful handle

type InitResultOk

type InitResultOk struct {
	Ok InitResponse `json:"ok"`
}

func InitResultOkOkDefault

func InitResultOkOkDefault() *InitResultOk

type InstantiateMsg

type InstantiateMsg struct {
	// CodeID is the reference to the wasm byte code as used by the Cosmos-SDK
	CodeID uint64 `json:"code_id"`
	// Msg is assumed to be a json-encoded message, which will be passed directly
	// as `userMsg` when calling `Handle` on the above-defined contract
	Msg []byte `json:"msg"`
	// Send is an optional amount of coins this contract sends to the called contract
	Send Coins `json:"send"`
}

type InvalidBase64

type InvalidBase64 struct {
	Msg string `json:"msg,omitempty"`
}

func (InvalidBase64) Error

func (e InvalidBase64) Error() string

type InvalidRequest

type InvalidRequest struct {
	Err     string `json:"error"`
	Request []byte `json:"request"`
}

func (InvalidRequest) Error

func (e InvalidRequest) Error() string

type InvalidResponse

type InvalidResponse struct {
	Err      string `json:"error"`
	Response []byte `json:"response"`
}

func (InvalidResponse) Error

func (e InvalidResponse) Error() string

type InvalidUtf8

type InvalidUtf8 struct {
	Msg string `json:"msg,omitempty"`
}

func (InvalidUtf8) Error

func (e InvalidUtf8) Error() string

type Iterator

type Iterator interface {
	Next() (key, value []byte, err error)
}

type MemRegion

type MemRegion struct {
	Offset   uint32
	Capacity uint32
	Length   uint32
}

func Build_region

func Build_region(size uint32, len uint32) (unsafe.Pointer, *MemRegion)

type MessageInfo

type MessageInfo struct {
	// bech32 encoding of sdk.AccAddress executing the contract
	Sender string `json:"sender"`
	// amount of funds send to the contract along with this message
	SentFunds []Coin `json:"sent_funds"`
}

func MockInfo

func MockInfo(sender string, funds []Coin) MessageInfo

type MigrateResponse

type MigrateResponse struct {
	// Messages comes directly from the contract and is it's request for action
	Messages []CosmosMsg `json:"messages"`
	// base64-encoded bytes to return as ABCI.Data field
	Data string `json:"data,rust_option"`
	// log message to return over abci interface
	Attributes []Attribute `json:"attributes"`
}

MigrateResponse defines the return value on a successful handle

type MigrateResultOk

type MigrateResultOk struct {
	Ok MigrateResponse `json:"ok"`
}

func MigrateResultOkDefault

func MigrateResultOkDefault() *MigrateResultOk

type MockApi

type MockApi struct{}

func (MockApi) CanonicalAddress

func (api MockApi) CanonicalAddress(human string) (CanonicalAddr, error)

func (MockApi) Debug

func (api MockApi) Debug(msg string)

func (MockApi) HumanAddress

func (api MockApi) HumanAddress(canonical CanonicalAddr) (string, error)

type MockIterator

type MockIterator struct {
	Iter dbm.Iterator
}

func (MockIterator) Next

func (iter MockIterator) Next() (key, value []byte, err error)

type MockQuerier

type MockQuerier struct {
	Balances map[string][]Coin
}

func NewMockQuerier

func NewMockQuerier(funds []Coin) *MockQuerier

func (*MockQuerier) GetBalance

func (q *MockQuerier) GetBalance(addr string) []Coin

func (*MockQuerier) HandleBank

func (q *MockQuerier) HandleBank(request BankQuery) (interface{}, error)

func (*MockQuerier) HandleQuery

func (q *MockQuerier) HandleQuery(request QueryRequest) (interface{}, error)

func (*MockQuerier) RawQuery

func (q *MockQuerier) RawQuery(raw []byte) ([]byte, error)

func (*MockQuerier) SetBalance

func (q *MockQuerier) SetBalance(addr string, balance []Coin)

type MockStorage

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

func NewMockStorage

func NewMockStorage() *MockStorage

func (*MockStorage) Get

func (s *MockStorage) Get(key []byte) ([]byte, error)

func (*MockStorage) Range

func (s *MockStorage) Range(start, end []byte, order Order) (iter Iterator, err error)

func (*MockStorage) Remove

func (s *MockStorage) Remove(key []byte) error

func (*MockStorage) Set

func (s *MockStorage) Set(key, value []byte) error

type NoSuchContract

type NoSuchContract struct {
	Addr string `json:"addr,omitempty"`
}

func (NoSuchContract) Error

func (e NoSuchContract) Error() string

type NotFound

type NotFound struct {
	Kind string `json:"kind,omitempty"`
}

func (NotFound) Error

func (e NotFound) Error() string

type NullPointer

type NullPointer struct {
	Msg string `json:"msg"`
}

func (NullPointer) Error

func (e NullPointer) Error() string

type OptionBinary

type OptionBinary struct {
	None string `json:"omitempty"`
	Some []byte `json:"omitempty"`
}

type Order

type Order uint32
const (
	Ascending  Order = 1
	Descending Order = 2
)

type ParseErr

type ParseErr struct {
	Target string `json:"target,omitempty"`
	Msg    string `json:"msg,omitempty"`
}

func (ParseErr) Error

func (e ParseErr) Error() string

type Querier

type Querier interface {
	RawQuery(request []byte) ([]byte, error)
}

type QuerierResult

type QuerierResult struct {
	Ok QueryResponse `json:"ok,omitempty"`
	// TODO: what is this format actually?
	Error string `json:"error,omitempty"`
}

This is a 2-level result

type QuerierWrapper

type QuerierWrapper struct {
	Querier
}

func (QuerierWrapper) QueryAllBalances

func (q QuerierWrapper) QueryAllBalances(addr string) ([]Coin, error)

func (QuerierWrapper) QueryBalance

func (q QuerierWrapper) QueryBalance(addr string, denom string) (Coin, error)

type QueryRequest

type QueryRequest struct {
	Bank    BankQuery    `json:"bank,omitempty"`
	Custom  RawMessage   `json:"custom,omitempty"`
	Staking StakingQuery `json:"staking,omitempty"`
	Wasm    WasmQuery    `json:"wasm,omitempty"`
}

QueryRequest is an rust enum and only (exactly) one of the fields should be set Should we do a cleaner approach in Go? (type/data?)

type QueryResponse

type QueryResponse struct {
	// this must be base64 encoded
	Ok string `json:"ok,omitempty,rust_option"`
	// TODO: what is this format actually?
	Error string `json:"error,omitempty"`
}

------- query detail types ---------

func BuildQueryResponse

func BuildQueryResponse(msg string) *QueryResponse

func BuildQueryResponseBinary

func BuildQueryResponseBinary(msg []byte) *QueryResponse

func (QueryResponse) Data

func (q QueryResponse) Data() ([]byte, error)

type RawMessage

type RawMessage []byte

RawMessage is a raw encoded JSON value. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding.

func (RawMessage) MarshalJSON

func (m RawMessage) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (*RawMessage) UnmarshalJSON

func (m *RawMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

type RawQuery

type RawQuery struct {
	ContractAddr string `json:"contract_addr"`
	Key          []byte `json:"key"`
}

RawQuery response is raw bytes ([]byte)

type ReadonlyStorage

type ReadonlyStorage interface {
	Get(key []byte) (value []byte, err error)
	Range(start, end []byte, order Order) (Iterator, error)
}

type RedelegateMsg

type RedelegateMsg struct {
	SrcValidator string `json:"src_validator"`
	DstValidator string `json:"dst_validator"`
	Amount       Coin   `json:"amount"`
}

type SendMsg

type SendMsg struct {
	FromAddress string `json:"from_address"`
	ToAddress   string `json:"to_address"`
	Amount      Coins  `json:"amount"`
}

SendMsg contains instructions for a Cosmos-SDK/SendMsg It has a fixed interface here and should be converted into the proper SDK format before dispatching

type SerializeErr

type SerializeErr struct {
	Source string `json:"source,omitempty"`
	Msg    string `json:"msg,omitempty"`
}

func (SerializeErr) Error

func (e SerializeErr) Error() string

type SliceHeader_Go

type SliceHeader_Go struct {
	Data uintptr
	Len  int
	Cap  int
}

type SliceHeader_tinyGo

type SliceHeader_tinyGo struct {
	Data uintptr
	Len  uintptr
	Cap  uintptr
}

type SmartQuery

type SmartQuery struct {
	ContractAddr string `json:"contract_addr"`
	Msg          []byte `json:"msg"`
}

SmartQuery respone is raw bytes ([]byte)

type StakingMsg

type StakingMsg struct {
	Delegate   DelegateMsg   `json:"delegate,omitempty"`
	Undelegate UndelegateMsg `json:"undelegate,omitempty"`
	Redelegate RedelegateMsg `json:"redelegate,omitempty"`
	Withdraw   WithdrawMsg   `json:"withdraw,omitempty"`
}

type StakingQuery

type StakingQuery struct {
	Validators     ezjson.EmptyStruct  `json:"validators,omitempty,opt_seen"`
	AllDelegations AllDelegationsQuery `json:"all_delegations,omitempty"`
	Delegation     DelegationQuery     `json:"delegation,omitempty"`
	BondedDenom    ezjson.EmptyStruct  `json:"bonded_denom,omitempty,opt_seen"`
}

func (StakingQuery) IsEmpty

func (s StakingQuery) IsEmpty() bool

type StdError

type StdError struct {
	GenericErr    GenericErr    `json:"generic_err,omitempty"`
	InvalidBase64 InvalidBase64 `json:"invalid_base64,omitempty"`
	InvalidUtf8   InvalidUtf8   `json:"invalid_utf8,omitempty"`
	NotFound      NotFound      `json:"not_found,omitempty"`
	NullPointer   NullPointer   `json:"null_pointer,omitempty"`
	ParseErr      ParseErr      `json:"parse_err,omitempty"`
	SerializeErr  SerializeErr  `json:"serialize_err,omitempty"`
	Unauthorized  Unauthorized  `json:"unauthorized,omitempty"`
	Underflow     Underflow     `json:"underflow,omitempty"`
}

StdError captures all errors returned from the Rust code as StdError. Exactly one of the fields should be set.

type Storage

type Storage interface {
	ReadonlyStorage

	Set(key, value []byte) error
	Remove(key []byte) error
}

type SystemError

type SystemError struct {
	InvalidRequest     InvalidRequest     `json:"invalid_request,omitempty"`
	InvalidResponse    InvalidResponse    `json:"invalid_response,omitempty"`
	NoSuchContract     NoSuchContract     `json:"no_such_contract,omitempty"`
	Unknown            Unknown            `json:"unknown,omitempty"`
	UnsupportedRequest UnsupportedRequest `json:"unsupported_request,omitempty"`
}

SystemError captures all errors returned from the Rust code as SystemError. Exactly one of the fields should be set.

func ToSystemError

func ToSystemError(err error) SystemError

ToSystemError will try to convert the given error to an SystemError. This is important to returning any Go error back to Rust.

If it is already StdError, return self. If it is an error, which could be a sub-field of StdError, embed it. If it is anything else, **return nil**

This may return nil on an unknown error, whereas ToStdError will always create a valid error type.

type Unauthorized

type Unauthorized struct {
	Msg string `json:"msg"`
}

func (Unauthorized) Error

func (e Unauthorized) Error() string

type UndelegateMsg

type UndelegateMsg struct {
	Validator string `json:"validator"`
	Amount    Coin   `json:"amount"`
}

type Underflow

type Underflow struct {
	Minuend    string `json:"minuend,omitempty"`
	Subtrahend string `json:"subtrahend,omitempty"`
}

func (Underflow) Error

func (e Underflow) Error() string

type Unknown

type Unknown struct {
	Msg string `json:"msg"`
}

func (Unknown) Error

func (e Unknown) Error() string

type UnsupportedRequest

type UnsupportedRequest struct {
	Kind string `json:"kind,omitempty"`
}

func (UnsupportedRequest) Error

func (e UnsupportedRequest) Error() string

type Validator

type Validator struct {
	Address string `json:"address"`
	// decimal string, eg "0.02"
	Commission string `json:"commission"`
	// decimal string, eg "0.02"
	MaxCommission string `json:"max_commission"`
	// decimal string, eg "0.02"
	MaxChangeRate string `json:"max_change_rate"`
}

type Validators

type Validators []Validator

TODO: Validators must JSON encode empty array as []

func (Validators) MarshalJSON

func (v Validators) MarshalJSON() ([]byte, error)

MarshalJSON ensures that we get [] for empty arrays

func (*Validators) UnmarshalJSON

func (v *Validators) UnmarshalJSON(data []byte) error

UnmarshalJSON ensures that we get [] for empty arrays

type ValidatorsResponse

type ValidatorsResponse struct {
	Validators Validators `json:"validators"`
}

ValidatorsResponse is the expected response to ValidatorsQuery

type WasmMsg

type WasmMsg struct {
	Execute     ExecuteMsg     `json:"execute,omitempty"`
	Instantiate InstantiateMsg `json:"instantiate,omitempty"`
}

type WasmQuery

type WasmQuery struct {
	Smart SmartQuery `json:"smart,omitempty"`
	Raw   RawQuery   `json:"raw,omitempty"`
}

func (WasmQuery) IsEmpty

func (w WasmQuery) IsEmpty() bool

type WithdrawMsg

type WithdrawMsg struct {
	Validator string `json:"validator"`
	// this is optional
	Recipient string `json:"recipient,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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