foundation

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package foundation server implementation of smartcontract functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearContext

func ClearContext()

ClearContext clears underlying gls context

func GetLogicalContext

func GetLogicalContext() *call.LogicContext

GetLogicalContext returns current calling context.

func GetPulseNumber

func GetPulseNumber() (pulse.Number, error)

GetPulseNumber returns current pulse from context.

func GetRequestReference

func GetRequestReference() (reference.Global, error)

GetRequestReference - Returns request reference from context.

func GetShardIndex

func GetShardIndex(s string, mod int) int

GetShardIndex calculates hash from string and gets it by mod

func MarshalMethodErrorResult

func MarshalMethodErrorResult(err error) ([]byte, error)

MarshalMethodErrorResult creates result data with logic error for any method.

func MarshalMethodResult

func MarshalMethodResult(returns ...interface{}) ([]byte, error)

MarshalMethodErrorResult creates result data with all `returns` returned by contract

func NewSource

func NewSource() rand.Source

NewSource returns source initialized with entropy from pulse.

func SetLogicalContext

func SetLogicalContext(ctx *call.LogicContext)

SetLogicalContext saves current calling context

func TrimAddress

func TrimAddress(address string) string

TrimAddress trims address

func TrimPublicKey

func TrimPublicKey(publicKey string) string

TrimPublicKey trims public key

func UnmarshalMethodResultSimplified

func UnmarshalMethodResultSimplified(data []byte, returns ...interface{}) error

UnmarshalMethodResultSimplified is simplified version of UnmarshalMethodResult that finds *foundation.Error in `returns` and saves there logicError in case it's not empty. This works as we force all methods in contracts to return error. Top level logic error has priority over error returned by contract. Example:

var i int
var contractError *foundation.Error
err := UnmarshalMethodResultSimplified(data, &i, &contractError)
if err != nil {
    ... system error ...
}
if contractError != nil {
    ... logic error set by system of returned by contract ...
}
...

func UnmarshalSig

func UnmarshalSig(b []byte) (r, s *big.Int, err error)

UnmarshalSig parses the two integer components of an ASN.1-encoded ECDSA signature.

func VerifySignature

func VerifySignature(rawRequest []byte, signature string, key string, rawpublicpem string, selfSigned bool) error

VerifySignature used for checking the signature using rawpublicpem and rawRequest. selfSigned flag need to compare public Keys.

Types

type BaseContract

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

BaseContract is a base embeddable struct for all insolar contracts

func (BaseContract) Foundation

func (bc BaseContract) Foundation() ContractFoundation

Foundation returns instance of foundation

func (*BaseContract) GetClass

func (bc *BaseContract) GetClass() reference.Global

GetClass - Returns class of contract

func (*BaseContract) GetCode

func (bc *BaseContract) GetCode() reference.Global

GetCode - Returns code of contract

func (*BaseContract) GetReference

func (bc *BaseContract) GetReference() reference.Global

GetReference - Returns public reference of contract

func (*BaseContract) InitFoundation

func (bc *BaseContract) InitFoundation(proxyHelper contract.ProxyHelper)

InitFoundation initializes foundation

func (*BaseContract) ResetFoundation

func (bc *BaseContract) ResetFoundation()

ResetFoundation nullifies foundation

func (*BaseContract) SelfDestruct

func (bc *BaseContract) SelfDestruct() error

SelfDestruct contract will be marked as deleted

type BaseContractInterface

type BaseContractInterface interface {
	GetReference() reference.Global
	GetClass() reference.Global
	GetCode() reference.Global
	Foundation() ContractFoundation
	InitFoundation(proxyHelper contract.ProxyHelper)
	ResetFoundation()
}

BaseContractInterface is an interface to deal with any contract same way

type ContractFoundation

type ContractFoundation interface {
	CurrentProxyCtx() contract.ProxyHelper
}

type ContractFoundationImpl

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

func (*ContractFoundationImpl) CurrentProxyCtx

func (cf *ContractFoundationImpl) CurrentProxyCtx() contract.ProxyHelper

CurrentProxyCtx returns foundation

type Error

type Error struct {
	S string
}

Error elementary string based error struct satisfying builtin error interface

foundation.Error{"some err"}

func UnmarshalMethodResult

func UnmarshalMethodResult(data []byte, returns ...interface{}) (*Error, error)

UnmarshalMethodResult extracts method result into provided pointers to existing variables. You should know what types method returns and number of returned variables. If result contains logic error that was created outside of contract then method returns this error *Error. Errors of serialized returned as second return value. Example:

var i int
var contractError *foundation.Error
logicError, err := UnmarshalMethodResult(data, &i, &contractError)
if err != nil {
    ... system error ...
}
if logicError != nil {
    ... logic error created with MarshalMethodErrorResult ...
}
if contractError != nil {
    ... contract returned error ...
}
...

func (*Error) Error

func (e *Error) Error() string

Error returns error in string format

type ProxyInterface

type ProxyInterface interface {
	GetReference(BaseContractInterface) reference.Global
	GetClass(BaseContractInterface) (reference.Global, error)
	GetCode(BaseContractInterface) (reference.Global, error)
}

ProxyInterface interface any proxy of a contract implements

func GetObject

func GetObject(ref reference.Global) ProxyInterface

GetObject creates proxy by address unimplemented

type Result

type Result struct {
	// Error - logic error, this field is not NIL if error is created outside
	// contract code, for example "object not found"
	Error *Error
	// Returns - all return values of contract's method, whatever it returns,
	// including errors
	Returns []interface{}
}

Result struct that serialized and saved on ledger as result of request

type StableMap

type StableMap map[string]string

StableMap is a `map[string]string` that can be deterministically serialized.

func NewStableMapFromInterface

func NewStableMapFromInterface(i interface{}) (StableMap, error)

NewStableMapFromInterface tries to parse interface{} as [][]string and creates new StableMap.

func (StableMap) MarshalBinary

func (m StableMap) MarshalBinary() ([]byte, error)

func (StableMap) MarshalJSON

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

func (*StableMap) UnmarshalBinary

func (m *StableMap) UnmarshalBinary(data []byte) error

func (*StableMap) UnmarshalJSON

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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