Documentation ¶
Overview ¶
Package foundation server implementation of smartcontract functions
Index ¶
- func ClearContext()
- func GetLogicalContext() *call.LogicContext
- func GetPulseNumber() (pulse.Number, error)
- func GetRequestReference() (reference.Global, error)
- func GetShardIndex(s string, mod int) int
- func MarshalMethodErrorResult(err error) ([]byte, error)
- func MarshalMethodResult(returns ...interface{}) ([]byte, error)
- func NewSource() rand.Source
- func SetLogicalContext(ctx *call.LogicContext)
- func TrimAddress(address string) string
- func TrimPublicKey(publicKey string) string
- func UnmarshalMethodResultSimplified(data []byte, returns ...interface{}) error
- func UnmarshalSig(b []byte) (r, s *big.Int, err error)
- func VerifySignature(rawRequest []byte, signature string, key string, rawpublicpem string, ...) error
- type BaseContract
- func (bc BaseContract) Foundation() ContractFoundation
- func (bc *BaseContract) GetClass() reference.Global
- func (bc *BaseContract) GetCode() reference.Global
- func (bc *BaseContract) GetReference() reference.Global
- func (bc *BaseContract) InitFoundation(proxyHelper contract.ProxyHelper)
- func (bc *BaseContract) ResetFoundation()
- func (bc *BaseContract) SelfDestruct() error
- type BaseContractInterface
- type ContractFoundation
- type ContractFoundationImpl
- type Error
- type ProxyInterface
- type Result
- type StableMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLogicalContext ¶
func GetLogicalContext() *call.LogicContext
GetLogicalContext returns current calling context.
func GetPulseNumber ¶
GetPulseNumber returns current pulse from context.
func GetRequestReference ¶
GetRequestReference - Returns request reference from context.
func GetShardIndex ¶
GetShardIndex calculates hash from string and gets it by mod
func MarshalMethodErrorResult ¶
MarshalMethodErrorResult creates result data with logic error for any method.
func MarshalMethodResult ¶
MarshalMethodErrorResult creates result data with all `returns` returned by contract
func SetLogicalContext ¶
func SetLogicalContext(ctx *call.LogicContext)
SetLogicalContext saves current calling context
func UnmarshalMethodResultSimplified ¶
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 ¶
UnmarshalSig parses the two integer components of an ASN.1-encoded ECDSA signature.
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 ¶
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 ... } ...
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 ¶
StableMap is a `map[string]string` that can be deterministically serialized.
func NewStableMapFromInterface ¶
NewStableMapFromInterface tries to parse interface{} as [][]string and creates new StableMap.