sdk

package
v0.0.0-...-d492368 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0, MIT Imports: 19 Imported by: 1

Documentation

Overview

Package sdk : a go-fvm-sdk for creation actors.

Index

Constants

This section is empty.

Variables

WriteCborArray marshal cbor array to bytes

Functions

func Abort

func Abort(ctx context.Context, code ferrors.ExitCode, msg string)

Abort abort execution, code must be non-okay value

func AvailableGas

func AvailableGas(ctx context.Context) (uint64, error)

AvailableGas current gas

func BalanceOf

func BalanceOf(ctx context.Context, actorID abi.ActorID) (*abi.TokenAmount, error)

BalanceOf Returns balanece of account

func BaseFee

func BaseFee(ctx context.Context) (abi.TokenAmount, error)

BaseFee gets the base fee for the current epoch.

func BatchVerifySeals

func BatchVerifySeals(ctx context.Context, sealVerifyInfos []proof.SealVerifyInfo) ([]bool, error)

BatchVerifySeals batch verifies seals

func Caller

func Caller(ctx context.Context) (abi.ActorID, error)

Caller get caller, from address of message todo cache invocation in context

func CallerAddress

func CallerAddress(ctx context.Context) (address.Address, error)

CallerAddress return caller address

func Charge

func Charge(ctx context.Context, name string, compute uint64) error

Charge charges the gas

func ComputeUnsealedSectorCid

func ComputeUnsealedSectorCid(
	ctx context.Context,
	proofType abi.RegisteredSealProof,
	pieces []abi.PieceInfo,
) (cid.Cid, error)

ComputeUnsealedSectorCid computes an unsealed sector CID (CommD) from its constituent piece CIDs (CommPs) and sizes.

func Constructor

func Constructor(ctx context.Context, state cbor.Marshaler) error

Constructor construct a acor with initialize state

func CreateActor

func CreateActor(ctx context.Context, actorID abi.ActorID, codeCid cid.Cid, addr address.Address) error

CreateActor Creates a new actor of the specified type in the state tree, under the provided address. TODO this syscall will change to calculate the address internally.

func CurrEpoch

func CurrEpoch(ctx context.Context) (abi.ChainEpoch, error)

CurrEpoch get network current epoch

func CurrentBalance

func CurrentBalance(ctx context.Context) abi.TokenAmount

CurrentBalance gets the current balance for the calling actor.

func EmitEvent

func EmitEvent(ctx context.Context, evt types.ActorEvent) error

EmitEvent emit event to fvm

func Exit

func Exit(ctx context.Context, code ferrors.ExitCode, data []byte, msg string)

Exit abort contract with data and exit message

func ExitWithBlkId

func ExitWithBlkId(ctx context.Context, code ferrors.ExitCode, blkId types.BlockID, msg string)

ExitWithBlkId abort contract with specify block id and exit message avoid to create block again sometimes

func Get

func Get(ctx context.Context, cid cid.Cid) ([]byte, error)

Get get a block. It's valid to call this on:

1. All CIDs returned by prior calls to `get_root`... 2. All CIDs returned by prior calls to `put`... 3. Any children of a blocks returned by prior calls to `get`...

...during the current invocation.

func GetActorCodeCid

func GetActorCodeCid(ctx context.Context, addr address.Address) (cid.Cid, error)

GetActorCodeCid look up the code ID at an actor address. Returns `None` if the actor cannot be found.

func GetBeaconRandomness

func GetBeaconRandomness(ctx context.Context, dst crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) (abi.Randomness, error)

GetBeaconRandomness gets 32 bytes of randomness from the beacon system (currently Drand). The supplied output buffer must have at least 32 bytes of capacity. If this syscall succeeds, exactly 32 bytes will be written starting at the supplied offset.

func GetBlock

func GetBlock(ctx context.Context, id types.BlockID, size *uint32) ([]byte, error)

GetBlock gets the data of the block referenced by BlockId. If the caller knows the size, this function will read the block in a single syscall. Otherwise, any block over 1KiB will take two syscalls.

func GetBuiltinActorType

func GetBuiltinActorType(ctx context.Context, codeCid cid.Cid) (types.ActorType, error)

GetBuiltinActorType determines whether the supplied CodeCID belongs to a built-in actor type, and to which.

func GetChainRandomness

func GetChainRandomness(ctx context.Context, dst crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) (abi.Randomness, error)

GetChainRandomness gets 32 bytes of randomness from the ticket chain. The supplied output buffer must have at least 32 bytes of capacity. If this syscall succeeds, exactly 32 bytes will be written starting at the supplied offset.

func GetCodeCidForType

func GetCodeCidForType(ctx context.Context, actorT types.ActorType) (cid.Cid, error)

GetCodeCidForType Returns the CodeCID for a built-in actor type. Aborts with IllegalArgument if the supplied type is invalid.

func HashBlake2b

func HashBlake2b(ctx context.Context, data []byte) ([32]byte, error)

HashBlake2b hashes input data using blake2b with 256 bit output.

func InitializeAccount

func InitializeAccount(ctx context.Context, addr address.Address) (abi.ActorID, error)

InitializeAccount create an account actor for address

func IsAccountAddress

func IsAccountAddress(ctx context.Context, addr address.Address) bool

IsAccountAddress use check whether specific address is action type

func IsNil

func IsNil(obj interface{}) bool

IsNil check whether interface is nil

func LoadState

func LoadState(ctx context.Context, state cbor.Unmarshaler)

LoadState loads actors current state

func LoadStateFromCid

func LoadStateFromCid(ctx context.Context, cid cid.Cid, state cbor.Unmarshaler)

LoadStateFromCid load actor state by message cid

func LookupDelegatedAddress

func LookupDelegatedAddress(ctx context.Context, actorID abi.ActorID) (address.Address, error)

LookupDelegatedAddress look up the address at an actor ID. Returns `None` if the actor cannot be found.

func MethodNumber

func MethodNumber(ctx context.Context) (abi.MethodNum, error)

MethodNumber method number

func MsgGasPremium

func MsgGasPremium(ctx context.Context) (abi.TokenAmount, error)

MsgGasPremium gaspremium in message

func MustAddressFromActorId

func MustAddressFromActorId(actorId abi.ActorID) address.Address

MustAddressFromActorId convert actor id to address, panic if marshal fail, used it carefully

func MustCborMarshal

func MustCborMarshal(obj cbor.Marshaler) []byte

MustCborMarshal marshal obj to bytes, panic if marshal fail, used it carefully

func NextActorAddress

func NextActorAddress(ctx context.Context) (address.Address, error)

NextActorAddress generates a new actor address for an actor deployed by the calling actor.

func Origin

func Origin(ctx context.Context) (abi.ActorID, error)

Origin get origin direct caller

func OriginAddress

func OriginAddress(ctx context.Context) (address.Address, error)

OriginAddress return message origin caller address

func ParamsRaw

func ParamsRaw(ctx context.Context, id types.BlockID) (*types.ParamsRaw, error)

ParamsRaw returns the message codec and parameters.

func Put

func Put(ctx context.Context, mhCode uint64, mhSize uint32, codec uint64, data []byte) (cid.Cid, error)

Put store a block. The block will only be persisted in the state-tree if the CID is "linked in" to the actor's state-tree before the end of the current invocation.

func PutBlock

func PutBlock(ctx context.Context, codec types.Codec, data []byte) (types.BlockID, error)

PutBlock writes the supplied block and returns the BlockId.

func Receiver

func Receiver(ctx context.Context) (abi.ActorID, error)

Receiver get recevier, to address of message

func ReceiverAddress

func ReceiverAddress(ctx context.Context) (address.Address, error)

ReceiverAddress return message to address

func ResolveAddress

func ResolveAddress(ctx context.Context, addr address.Address) (abi.ActorID, error)

ResolveAddress resolves the ID address of an actor. Returns `None` if the address cannot be resolved. Successfully resolving an address doesn't necessarily mean the actor exists (e.g., if the addresss was already an actor ID).

func ResolveOrInitAddress

func ResolveOrInitAddress(ctx context.Context, addr address.Address) (abi.ActorID, error)

ResolveOrInitAddress get actor id from address, if not found create one

func Root

func Root(ctx context.Context) (cid.Cid, error)

Root Get the IPLD root CID. Fails if the actor doesn't have state (before the first call to `set_root` and after actor deletion).

func SameAddress

func SameAddress(ctx context.Context, addrA, addrB address.Address) bool

SameAddress check if two address is the same actor

func SaveState

func SaveState(ctx context.Context, state cbor.Marshaler) cid.Cid

SaveState save actor state

func SelfDestruct

func SelfDestruct(ctx context.Context, addr addr.Address) error

SelfDestruct destroys the calling actor, sending its current balance to the supplied address, which cannot be itself.

Fails if the beneficiary doesn't exist or is the actor being deleted.

func Send

func Send(ctx context.Context, to address.Address, method abi.MethodNum, params types.RawBytes, value abi.TokenAmount, opts ...SendOption) (*types.Receipt, error)

Send call another actor

func SetRoot

func SetRoot(ctx context.Context, c cid.Cid) error

SetRoot set the actor's state-tree root.

Fails if:

- The new root is not in the actor's "reachable" set. - Fails if the actor has been deleted.

func TipsetCid

func TipsetCid(ctx context.Context, epoch abi.ChainEpoch) (*cid.Cid, error)

TipsetCid gets cid

func TipsetTimestamp

func TipsetTimestamp(ctx context.Context) (uint64, error)

TipsetTimestamp gets Timestamp

func TotalFilCircSupply

func TotalFilCircSupply(ctx context.Context) (abi.TokenAmount, error)

TotalFilCircSupply gets the circulating supply.

func ValueReceived

func ValueReceived(ctx context.Context) (abi.TokenAmount, error)

ValueReceived the amount was transferred in message

func VerifyAggregateSeals

func VerifyAggregateSeals(ctx context.Context, info *types.AggregateSealVerifyProofAndInfos) (bool, error)

VerifyAggregateSeals verifies aggregate proof of replication of sectors

func VerifyConsensusFault

func VerifyConsensusFault(
	ctx context.Context,
	h1 []byte,
	h2 []byte,
	extra []byte,
) (*runtime.ConsensusFault, error)

VerifyConsensusFault verifies that two block headers provide proof of a consensus fault: - both headers mined by the same actor - headers are different - first header is of the same or lower epoch as the second - at least one of the headers appears in the current chain at or after epoch `earliest` - the headers provide evidence of a fault (see the spec for the different fault types). The parameters are all serialized block headers. The third "extra" parameter is consulted only for the "parent grinding fault", in which case it must be the sibling of h1 (same parent tipset) and one of the blocks in the parent of h2 (i.e. h2's grandparent). Returns None and an error if the headers don't prove a fault.

func VerifyPost

func VerifyPost(ctx context.Context, info *proof.WindowPoStVerifyInfo) (bool, error)

VerifyPost verifies a sector seal proof.

func VerifyReplicaUpdate

func VerifyReplicaUpdate(ctx context.Context, info *types.ReplicaUpdateInfo) (bool, error)

VerifyReplicaUpdate verifies sector replica update

func VerifySeal

func VerifySeal(ctx context.Context, info *proof.SealVerifyInfo) (bool, error)

VerifySeal verifies a sector seal proof.

func VerifySignature

func VerifySignature(
	ctx context.Context,
	signature *crypto.Signature,
	signer *address.Address,
	plainText []byte,
) (bool, error)

VerifySignature verifies that a signature is valid for an address and plaintext.

func Version

func Version(ctx context.Context) (network.Version, error)

Version network version

Types

type Logger

type Logger interface {
	Enabled(ctx context.Context) bool
	Log(ctx context.Context, args ...interface{})
	Logf(ctx context.Context, format string, a ...interface{})
	StoreArtifact(ctx context.Context, name string, data []byte)
}

Logger is a debug-only logger that uses the FVM syscalls.

func NewLogger

func NewLogger() (Logger, error)

NewLogger create a logging if debugging is enabled.

type MethodInfo

type MethodInfo struct {
	// use alias name instead of function name
	Alias string
	// function gen tool get method params and return  by this field
	Func interface{}
	// indicate whether this method is a readonly function,  not need to send message when invoke this query state
	Readonly bool
}

MethodInfo used to mark actor export function.

type SendOption

type SendOption func(cfg sendCfg)

SendOption options for set send params

func WithGasLimit

func WithGasLimit(gasLimit uint64) SendOption

WithGasLimit used to set gas limit for send call

func WithReadonly

func WithReadonly() SendOption

WithReadonly used to set readonly mode for send call

Directories

Path Synopsis
Package adt provides amt array and map for contract to store something big, avoid to load big data most code move from https://github.com/filecoin-project/specs-actors/tree/master/actors/util/adt
Package adt provides amt array and map for contract to store something big, avoid to load big data most code move from https://github.com/filecoin-project/specs-actors/tree/master/actors/util/adt
Package ferrors fvm errors
Package ferrors fvm errors
Package frc42dispatch implement frc42 reference https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0042.md
Package frc42dispatch implement frc42 reference https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0042.md
Package internal definite type/function for both sys and sdk
Package internal definite type/function for both sys and sdk
sys
Package sys is used to interact with fvm and in this package non-fvm file used to index for ide, this can be convenient for development file with _call suffix defines the wasm export function file with _simulate used to simulate system call, useful for actor unit test others file was wrap for _call file, make the type and style more closely match the standard of go
Package sys is used to interact with fvm and in this package non-fvm file used to index for ide, this can be convenient for development file with _call suffix defines the wasm export function file with _simulate used to simulate system call, useful for actor unit test others file was wrap for _call file, make the type and style more closely match the standard of go
simulated
Package simulated is simulated of fvm
Package simulated is simulated of fvm
Package types go-fvm-sdk types
Package types go-fvm-sdk types

Jump to

Keyboard shortcuts

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