filecoin

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const FilecoinPrecision = uint64(1_000_000_000_000_000_000)

Variables

View Source
var EmptyInt = BigInt{}
View Source
var EmptyTSK = TipSetKey{}

Functions

func SizeStr

func SizeStr(bi BigInt) string

SizeStr formats byte sizes in humand readble format

Types

type API

type API interface {
	ChainHead(context.Context) (*TipSet, error)
	GasEstimateMessageGas(context.Context, *Message, *MessageSendSpec, TipSetKey) (*Message, error)
	StateGetActor(context.Context, address.Address, TipSetKey) (*Actor, error)
	MpoolPush(context.Context, *SignedMessage) (cid.Cid, error)
	StateWaitMsg(context.Context, cid.Cid, uint64) (*MsgLookup, error)
	StateSearchMsg(context.Context, cid.Cid) (*MsgLookup, error)
	StateAccountKey(context.Context, address.Address, TipSetKey) (address.Address, error)
	StateLookupID(context.Context, address.Address, TipSetKey) (address.Address, error)
	StateReadState(context.Context, address.Address, TipSetKey) (*ActorState, error)
	StateNetworkVersion(context.Context, TipSetKey) (network.Version, error)
	StateMarketBalance(context.Context, address.Address, TipSetKey) (MarketBalance, error)
	StateDealProviderCollateralBounds(context.Context, abi.PaddedPieceSize, bool, TipSetKey) (DealCollateralBounds, error)
	StateMinerInfo(context.Context, address.Address, TipSetKey) (MinerInfo, error)
	StateMinerProvingDeadline(context.Context, address.Address, TipSetKey) (*dline.Info, error)
	StateCall(context.Context, *Message, TipSetKey) (*InvocResult, error)
	ChainReadObj(context.Context, cid.Cid) ([]byte, error)
	ChainGetMessage(context.Context, cid.Cid) (*Message, error)
	Close()
}

API declares minimum required methods for interacting with the Filecoin Blockchain We can support different filecoin implementations such as lotus or venus

func NewLotusRPC

func NewLotusRPC(ctx context.Context, addr string, header http.Header) (API, error)

NewLotusRPC starts a new lotus RPC client

type APIEndpoint

type APIEndpoint struct {
	Address string
	Header  http.Header
}

APIEndpoint address and auth token to access a remote api

type Actor

type Actor struct {
	Code    cid.Cid
	Head    cid.Cid
	Nonce   uint64
	Balance BigInt
}

func (*Actor) MarshalCBOR

func (t *Actor) MarshalCBOR(w io.Writer) error

func (*Actor) UnmarshalCBOR

func (t *Actor) UnmarshalCBOR(r io.Reader) error

type ActorState

type ActorState struct {
	Balance BigInt
	State   interface{}
}

type BeaconEntry

type BeaconEntry struct {
	Round uint64
	Data  []byte
}

func (*BeaconEntry) MarshalCBOR

func (t *BeaconEntry) MarshalCBOR(w io.Writer) error

func (*BeaconEntry) UnmarshalCBOR

func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error

type BigInt

type BigInt = big2.Int

func BigAdd

func BigAdd(a, b BigInt) BigInt

func BigDiv

func BigDiv(a, b BigInt) BigInt

func BigMul

func BigMul(a, b BigInt) BigInt

func BigSub

func BigSub(a, b BigInt) BigInt

func NewInt

func NewInt(i uint64) BigInt

type BlockHeader

type BlockHeader struct {
	Miner address.Address // 0

	Ticket *Ticket // 1

	ElectionProof *ElectionProof // 2

	BeaconEntries []BeaconEntry // 3

	WinPoStProof []proof.PoStProof // 4

	Parents []cid.Cid // 5

	ParentWeight BigInt // 6

	Height abi.ChainEpoch // 7

	ParentStateRoot cid.Cid // 8

	ParentMessageReceipts cid.Cid // 8

	Messages cid.Cid // 10

	BLSAggregate *crypto.Signature // 11

	Timestamp uint64 // 12

	BlockSig *crypto.Signature // 13

	ForkSignaling uint64 // 14

	// ParentBaseFee is the base fee after executing parent tipset
	ParentBaseFee abi.TokenAmount // 15
	// contains filtered or unexported fields
}

func (*BlockHeader) Cid

func (blk *BlockHeader) Cid() cid.Cid

func (*BlockHeader) LastTicket

func (blk *BlockHeader) LastTicket() *Ticket

func (*BlockHeader) MarshalCBOR

func (t *BlockHeader) MarshalCBOR(w io.Writer) error

func (*BlockHeader) Serialize

func (blk *BlockHeader) Serialize() ([]byte, error)

func (*BlockHeader) ToStorageBlock

func (blk *BlockHeader) ToStorageBlock() (block.Block, error)

func (*BlockHeader) UnmarshalCBOR

func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error

type DealCollateralBounds

type DealCollateralBounds struct {
	Min abi.TokenAmount
	Max abi.TokenAmount
}

DealCollateralBounds is the Min and Max collateral a storage provider can issue

type ElectionProof

type ElectionProof struct {
	WinCount int64
	VRFProof []byte
}

func (*ElectionProof) MarshalCBOR

func (t *ElectionProof) MarshalCBOR(w io.Writer) error

func (*ElectionProof) UnmarshalCBOR

func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error

type ExecutionTrace

type ExecutionTrace struct {
	Msg        *Message
	MsgRct     *MessageReceipt
	Error      string
	Duration   time.Duration
	GasCharges []*GasTrace

	Subcalls []ExecutionTrace
}

ExecutionTrace is a tree of all the call results executed during a state transition

type ExpTipSet

type ExpTipSet struct {
	Cids   []cid.Cid
	Blocks []*BlockHeader
	Height abi.ChainEpoch
}

func (*ExpTipSet) MarshalCBOR

func (t *ExpTipSet) MarshalCBOR(w io.Writer) error

func (*ExpTipSet) UnmarshalCBOR

func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error

type FIL

type FIL BigInt

func ParseFIL

func ParseFIL(s string) (FIL, error)

func (FIL) Short

func (f FIL) Short() string

func (FIL) String

func (f FIL) String() string

func (FIL) Unitless

func (f FIL) Unitless() string

type GasTrace

type GasTrace struct {
	Name string

	Location          []Loc `json:"loc"`
	TotalGas          int64 `json:"tg"`
	ComputeGas        int64 `json:"cg"`
	StorageGas        int64 `json:"sg"`
	TotalVirtualGas   int64 `json:"vtg"`
	VirtualComputeGas int64 `json:"vcg"`
	VirtualStorageGas int64 `json:"vsg"`

	TimeTaken time.Duration `json:"tt"`
	Extra     interface{}   `json:"ex,omitempty"`

	Callers []uintptr `json:"-"`
}

GasTrace is more detailed explanation of gas computation

type InvocResult

type InvocResult struct {
	MsgCid         cid.Cid
	Msg            *Message
	MsgRct         *MessageReceipt
	GasCost        MsgGasCost
	ExecutionTrace ExecutionTrace
	Error          string
	Duration       time.Duration
}

InvocResult is returned when calling a state change on the Filecoin blockchain

type Loc

type Loc struct {
	File     string
	Line     int
	Function string
}

Loc is a locater of source code reference

type LotusAPI

type LotusAPI struct {
	Methods struct {
		ChainHead                         func(context.Context) (*TipSet, error)
		GasEstimateMessageGas             func(context.Context, *Message, *MessageSendSpec, TipSetKey) (*Message, error)
		StateGetActor                     func(context.Context, address.Address, TipSetKey) (*Actor, error)
		MpoolPush                         func(context.Context, *SignedMessage) (cid.Cid, error)
		StateWaitMsg                      func(context.Context, cid.Cid, uint64) (*MsgLookup, error)
		StateSearchMsg                    func(context.Context, cid.Cid) (*MsgLookup, error)
		StateAccountKey                   func(context.Context, address.Address, TipSetKey) (address.Address, error)
		StateLookupID                     func(context.Context, address.Address, TipSetKey) (address.Address, error)
		StateReadState                    func(context.Context, address.Address, TipSetKey) (*ActorState, error)
		StateNetworkVersion               func(context.Context, TipSetKey) (network.Version, error)
		StateMarketBalance                func(context.Context, address.Address, TipSetKey) (MarketBalance, error)
		StateDealProviderCollateralBounds func(context.Context, abi.PaddedPieceSize, bool, TipSetKey) (DealCollateralBounds, error)
		StateMinerInfo                    func(context.Context, address.Address, TipSetKey) (MinerInfo, error)
		StateMinerProvingDeadline         func(context.Context, address.Address, TipSetKey) (*dline.Info, error)
		StateCall                         func(context.Context, *Message, TipSetKey) (*InvocResult, error)
		ChainReadObj                      func(context.Context, cid.Cid) ([]byte, error)
		ChainGetMessage                   func(context.Context, cid.Cid) (*Message, error)
	}
	// contains filtered or unexported fields
}

LotusAPI tells the rpc client how to handle the different methods

func (*LotusAPI) ChainGetMessage

func (a *LotusAPI) ChainGetMessage(ctx context.Context, c cid.Cid) (*Message, error)

func (*LotusAPI) ChainHead

func (a *LotusAPI) ChainHead(ctx context.Context) (*TipSet, error)

func (*LotusAPI) ChainReadObj

func (a *LotusAPI) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error)

func (*LotusAPI) Close

func (a *LotusAPI) Close()

func (*LotusAPI) GasEstimateMessageGas

func (a *LotusAPI) GasEstimateMessageGas(ctx context.Context, m *Message, mss *MessageSendSpec, tsk TipSetKey) (*Message, error)

func (*LotusAPI) MpoolPush

func (a *LotusAPI) MpoolPush(ctx context.Context, sm *SignedMessage) (cid.Cid, error)

func (*LotusAPI) StateAccountKey

func (a *LotusAPI) StateAccountKey(ctx context.Context, addr address.Address, tsk TipSetKey) (address.Address, error)

func (*LotusAPI) StateCall

func (a *LotusAPI) StateCall(ctx context.Context, msg *Message, tsk TipSetKey) (*InvocResult, error)

func (*LotusAPI) StateDealProviderCollateralBounds

func (a *LotusAPI) StateDealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk TipSetKey) (DealCollateralBounds, error)

func (*LotusAPI) StateGetActor

func (a *LotusAPI) StateGetActor(ctx context.Context, addr address.Address, tsk TipSetKey) (*Actor, error)

func (*LotusAPI) StateLookupID

func (a *LotusAPI) StateLookupID(ctx context.Context, addr address.Address, tsk TipSetKey) (address.Address, error)

func (*LotusAPI) StateMarketBalance

func (a *LotusAPI) StateMarketBalance(ctx context.Context, addr address.Address, tsk TipSetKey) (MarketBalance, error)

func (*LotusAPI) StateMinerInfo

func (a *LotusAPI) StateMinerInfo(ctx context.Context, addr address.Address, tsk TipSetKey) (MinerInfo, error)

func (*LotusAPI) StateMinerProvingDeadline

func (a *LotusAPI) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk TipSetKey) (*dline.Info, error)

func (*LotusAPI) StateNetworkVersion

func (a *LotusAPI) StateNetworkVersion(ctx context.Context, tsk TipSetKey) (network.Version, error)

func (*LotusAPI) StateReadState

func (a *LotusAPI) StateReadState(ctx context.Context, addr address.Address, tsk TipSetKey) (*ActorState, error)

func (*LotusAPI) StateSearchMsg

func (a *LotusAPI) StateSearchMsg(ctx context.Context, c cid.Cid) (*MsgLookup, error)

func (*LotusAPI) StateWaitMsg

func (a *LotusAPI) StateWaitMsg(ctx context.Context, c cid.Cid, conf uint64) (*MsgLookup, error)

type MarketBalance

type MarketBalance struct {
	Escrow big2.Int
	Locked big2.Int
}

MarketBalance formats the Escrow and Locked balances of an address in the Storage Market

type Message

type Message struct {
	Version uint64

	To   address.Address
	From address.Address

	Nonce uint64

	Value abi.TokenAmount

	GasLimit   int64
	GasFeeCap  abi.TokenAmount
	GasPremium abi.TokenAmount

	Method abi.MethodNum
	Params []byte
}

func (*Message) Caller

func (m *Message) Caller() address.Address

func (*Message) Cid

func (m *Message) Cid() cid.Cid

func (*Message) MarshalCBOR

func (t *Message) MarshalCBOR(w io.Writer) error

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

func (*Message) Receiver

func (m *Message) Receiver() address.Address

func (*Message) Serialize

func (m *Message) Serialize() ([]byte, error)

func (*Message) ToStorageBlock

func (m *Message) ToStorageBlock() (block.Block, error)

func (*Message) UnmarshalCBOR

func (t *Message) UnmarshalCBOR(r io.Reader) error

func (*Message) ValueReceived

func (m *Message) ValueReceived() abi.TokenAmount

type MessageReceipt

type MessageReceipt struct {
	ExitCode exitcode.ExitCode
	Return   []byte
	GasUsed  int64
}

type MessageSendSpec

type MessageSendSpec struct {
	MaxFee abi.TokenAmount
}

type MinerInfo

type MinerInfo struct {
	Owner                      address.Address   // Must be an ID-address.
	Worker                     address.Address   // Must be an ID-address.
	NewWorker                  address.Address   // Must be an ID-address.
	ControlAddresses           []address.Address // Must be an ID-addresses.
	WorkerChangeEpoch          abi.ChainEpoch
	PeerId                     *peer.ID
	Multiaddrs                 []abi.Multiaddrs
	WindowPoStProofType        abi.RegisteredPoStProof
	SectorSize                 abi.SectorSize
	WindowPoStPartitionSectors uint64
	ConsensusFaultElapsed      abi.ChainEpoch
}

MinerInfo formats information about a Filecoin storage miner we ask a lotus api for

type MockLotusAPI

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

MockLotusAPI is for testing purposes only

func NewMockLotusAPI

func NewMockLotusAPI() *MockLotusAPI

func (*MockLotusAPI) ChainGetMessage

func (m *MockLotusAPI) ChainGetMessage(ctx context.Context, c cid.Cid) (*Message, error)

func (*MockLotusAPI) ChainHead

func (m *MockLotusAPI) ChainHead(context.Context) (*TipSet, error)

func (*MockLotusAPI) ChainReadObj

func (m *MockLotusAPI) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error)

func (*MockLotusAPI) Close

func (m *MockLotusAPI) Close()

func (*MockLotusAPI) GasEstimateMessageGas

func (m *MockLotusAPI) GasEstimateMessageGas(ctx context.Context, msg *Message, spec *MessageSendSpec, tsk TipSetKey) (*Message, error)

func (*MockLotusAPI) MpoolPush

func (m *MockLotusAPI) MpoolPush(ctx context.Context, smsg *SignedMessage) (cid.Cid, error)

func (*MockLotusAPI) SetAccountKey

func (m *MockLotusAPI) SetAccountKey(addr address.Address, key address.Address)

func (*MockLotusAPI) SetActor

func (m *MockLotusAPI) SetActor(act *Actor)

func (*MockLotusAPI) SetActorState

func (m *MockLotusAPI) SetActorState(state *ActorState)

func (*MockLotusAPI) SetInvocResult

func (m *MockLotusAPI) SetInvocResult(i *InvocResult)

func (*MockLotusAPI) SetMsgLookup

func (m *MockLotusAPI) SetMsgLookup(lkp *MsgLookup)

SetMsgLookup to release the StateWaitMsg request

func (*MockLotusAPI) SetObject

func (m *MockLotusAPI) SetObject(obj []byte)

func (*MockLotusAPI) SetObjectReader

func (m *MockLotusAPI) SetObjectReader(r func(cid.Cid) []byte)

func (*MockLotusAPI) StateAccountKey

func (m *MockLotusAPI) StateAccountKey(ctx context.Context, addr address.Address, tsk TipSetKey) (address.Address, error)

func (*MockLotusAPI) StateCall

func (m *MockLotusAPI) StateCall(ctx context.Context, msg *Message, tsk TipSetKey) (*InvocResult, error)

func (*MockLotusAPI) StateDealProviderCollateralBounds

func (m *MockLotusAPI) StateDealProviderCollateralBounds(ctx context.Context, s abi.PaddedPieceSize, b bool, tsk TipSetKey) (DealCollateralBounds, error)

func (*MockLotusAPI) StateGetActor

func (m *MockLotusAPI) StateGetActor(ctx context.Context, addr address.Address, tsk TipSetKey) (*Actor, error)

func (*MockLotusAPI) StateLookupID

func (m *MockLotusAPI) StateLookupID(ctx context.Context, addr address.Address, tsk TipSetKey) (address.Address, error)

func (*MockLotusAPI) StateMarketBalance

func (m *MockLotusAPI) StateMarketBalance(ctx context.Context, addr address.Address, tsk TipSetKey) (MarketBalance, error)

func (*MockLotusAPI) StateMinerInfo

func (m *MockLotusAPI) StateMinerInfo(ctx context.Context, addr address.Address, tsk TipSetKey) (MinerInfo, error)

func (*MockLotusAPI) StateMinerProvingDeadline

func (m *MockLotusAPI) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk TipSetKey) (*dline.Info, error)

func (*MockLotusAPI) StateNetworkVersion

func (m *MockLotusAPI) StateNetworkVersion(ctx context.Context, tsk TipSetKey) (network.Version, error)

func (*MockLotusAPI) StateReadState

func (m *MockLotusAPI) StateReadState(ctx context.Context, addr address.Address, tsk TipSetKey) (*ActorState, error)

func (*MockLotusAPI) StateSearchMsg

func (m *MockLotusAPI) StateSearchMsg(ctx context.Context, c cid.Cid) (*MsgLookup, error)

func (*MockLotusAPI) StateWaitMsg

func (m *MockLotusAPI) StateWaitMsg(ctx context.Context, c cid.Cid, conf uint64) (*MsgLookup, error)

type MsgGasCost

type MsgGasCost struct {
	Message            cid.Cid // Can be different than requested, in case it was replaced, but only gas values changed
	GasUsed            abi.TokenAmount
	BaseFeeBurn        abi.TokenAmount
	OverEstimationBurn abi.TokenAmount
	MinerPenalty       abi.TokenAmount
	MinerTip           abi.TokenAmount
	Refund             abi.TokenAmount
	TotalCost          abi.TokenAmount
}

MsgGasCost is a breakdown of all the fees paid when running a transaction on chain

type MsgLookup

type MsgLookup struct {
	Message   cid.Cid // Can be different than requested, in case it was replaced, but only gas values changed
	Receipt   MessageReceipt
	ReturnDec interface{}
	TipSet    TipSetKey
	Height    abi.ChainEpoch
}

type RawMessage

type RawMessage Message

type RawSignedMessage

type RawSignedMessage SignedMessage

type SignedMessage

type SignedMessage struct {
	Message   Message
	Signature crypto.Signature
}

func (*SignedMessage) Cid

func (sm *SignedMessage) Cid() cid.Cid

func (*SignedMessage) MarshalCBOR

func (t *SignedMessage) MarshalCBOR(w io.Writer) error

func (*SignedMessage) MarshalJSON

func (sm *SignedMessage) MarshalJSON() ([]byte, error)

func (*SignedMessage) Serialize

func (sm *SignedMessage) Serialize() ([]byte, error)

func (*SignedMessage) ToStorageBlock

func (sm *SignedMessage) ToStorageBlock() (block.Block, error)

func (*SignedMessage) UnmarshalCBOR

func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error

type Ticket

type Ticket struct {
	VRFProof []byte
}

func (*Ticket) Equals

func (t *Ticket) Equals(ot *Ticket) bool

func (*Ticket) Less

func (t *Ticket) Less(o *Ticket) bool

func (*Ticket) MarshalCBOR

func (t *Ticket) MarshalCBOR(w io.Writer) error

func (*Ticket) UnmarshalCBOR

func (t *Ticket) UnmarshalCBOR(r io.Reader) error

type TipSet

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

func NewTipSet

func NewTipSet(blks []*BlockHeader) (*TipSet, error)

NewTipSet Checks:

  • A tipset is composed of at least one block. (Because of our variable number of blocks per tipset, determined by randomness, we do not impose an upper limit.)
  • All blocks have the same height.
  • All blocks have the same parents (same number of them and matching CIDs).

func (*TipSet) Height

func (ts *TipSet) Height() abi.ChainEpoch

func (*TipSet) Key

func (ts *TipSet) Key() TipSetKey

func (*TipSet) MarshalJSON

func (ts *TipSet) MarshalJSON() ([]byte, error)

func (*TipSet) UnmarshalJSON

func (ts *TipSet) UnmarshalJSON(b []byte) error

type TipSetKey

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

A TipSetKey is an immutable collection of CIDs forming a unique key for a tipset. The CIDs are assumed to be distinct and in canonical order. Two keys with the same CIDs in a different order are not considered equal. TipSetKey is a lightweight value type, and may be compared for equality with ==.

func NewTipSetKey

func NewTipSetKey(cids ...cid.Cid) TipSetKey

NewTipSetKey builds a new key from a slice of CIDs. The CIDs are assumed to be ordered correctly.

func TipSetKeyFromBytes

func TipSetKeyFromBytes(encoded []byte) (TipSetKey, error)

TipSetKeyFromBytes wraps an encoded key, validating correct decoding.

func (TipSetKey) Bytes

func (k TipSetKey) Bytes() []byte

Bytes returns a binary representation of the key.

func (TipSetKey) Cids

func (k TipSetKey) Cids() []cid.Cid

Cids returns a slice of the CIDs comprising this key.

func (TipSetKey) MarshalJSON

func (k TipSetKey) MarshalJSON() ([]byte, error)

func (*TipSetKey) UnmarshalJSON

func (k *TipSetKey) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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