filecoin

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthorizationKey is the header key used for authorization
	AuthorizationKey = "Authorization"

	// DefaultClientRPCURL is the RPC URL used by default, to interact with the
	// filecoin lotus node.
	DefaultClientRPCURL = "http://127.0.0.1:1234/rpc/v0"

	// DefaultClientAuthToken is the auth token used to instantiate the lotus
	// client. A valid lotus auth token is required to write messages to the
	// filecoin storage. To do read-only queries, auth token is not required.
	DefaultClientAuthToken = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressDecoder

type AddressDecoder struct{}

AddressDecoder implements the address.Decoder interface.

func (AddressDecoder) DecodeAddress

func (addrDecoder AddressDecoder) DecodeAddress(addr address.Address) (address.RawAddress, error)

DecodeAddress implements the address.Decoder interface. It receives a human readable address and decodes it to an address represented by raw bytes.

type AddressEncodeDecoder

type AddressEncodeDecoder struct {
	AddressEncoder
	AddressDecoder
}

AddressEncodeDecoder implements the address.EncodeDecoder interface

func NewAddressEncodeDecoder

func NewAddressEncodeDecoder() AddressEncodeDecoder

NewAddressEncodeDecoder constructs a new AddressEncodeDecoder.

type AddressEncoder

type AddressEncoder struct{}

AddressEncoder implements the address.Encoder interface.

func (AddressEncoder) EncodeAddress

func (encoder AddressEncoder) EncodeAddress(raw address.RawAddress) (address.Address, error)

EncodeAddress implements the address.Encoder interface. It receives a raw address and encodes it to a human-readable stringified address.

type Client

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

Client holds options to connect to a filecoin lotus node, and the underlying RPC client instance.

func NewClient

func NewClient(opts ClientOptions) (*Client, error)

NewClient creates and returns a new JSON-RPC client to the Filecoin node

func (*Client) AccountBalance

func (client *Client) AccountBalance(ctx context.Context, addr address.Address) (pack.U256, error)

AccountBalance returns the account balancee for a given address.

func (*Client) AccountNonce

func (client *Client) AccountNonce(ctx context.Context, addr address.Address) (pack.U256, error)

AccountNonce returns the current nonce of the account. This is the nonce to be used while building a new transaction.

func (*Client) LatestBlock

func (client *Client) LatestBlock(ctx context.Context) (pack.U64, error)

LatestBlock returns the block number at the current chain head.

func (*Client) SubmitTx

func (client *Client) SubmitTx(ctx context.Context, tx account.Tx) error

SubmitTx to the underlying blockchain network.

func (*Client) Tx

func (client *Client) Tx(ctx context.Context, txID pack.Bytes) (account.Tx, pack.U64, error)

Tx returns the transaction uniquely identified by the given transaction hash. It also returns the number of confirmations for the transaction.

type ClientOptions

type ClientOptions struct {
	RPCURL    string
	AuthToken string
}

ClientOptions are used to parameterise the behaviour of the Client.

func DefaultClientOptions

func DefaultClientOptions() ClientOptions

DefaultClientOptions returns ClientOptions with the default settings. These settings are valid for use with the default local deployment of the multichain. In production, the rpc-url and authentication token should be changed.

func (ClientOptions) WithAuthToken

func (opts ClientOptions) WithAuthToken(authToken pack.String) ClientOptions

WithAuthToken returns a modified version of the options with the given authentication token.

func (ClientOptions) WithRPCURL

func (opts ClientOptions) WithRPCURL(rpcURL pack.String) ClientOptions

WithRPCURL returns a modified version of the options with the given API rpc-url

type GasEstimator

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

A GasEstimator returns the gas fee cap and gas premium that is needed in order to confirm transactions with an estimated maximum delay of one block. In distributed networks that collectively build, sign, and submit transactions, it is important that all nodes in the network have reached consensus on these values.

func NewGasEstimator

func NewGasEstimator(client *Client, gasLimit int64) *GasEstimator

NewGasEstimator returns a simple gas estimator that fetches the ideal gas fee cap and gas premium for a filecoin transaction to be included in a block with minimal delay.

func (*GasEstimator) EstimateGas

func (gasEstimator *GasEstimator) EstimateGas(ctx context.Context) (pack.U256, pack.U256, error)

EstimateGas returns an estimate of the current gas price (also known as gas premium) and gas cap. These numbers change with congestion. These estimates are often a little bit off, and this should be considered when using them.

type Tx

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

Tx represents a filecoin transaction, encapsulating a message and its signature.

func (Tx) From

func (tx Tx) From() address.Address

From returns the address that is sending the transaction. Generally, this is also the address that must sign the transaction.

func (Tx) Hash

func (tx Tx) Hash() pack.Bytes

Hash returns the hash that uniquely identifies the transaction. Generally, hashes are irreversible hash functions that consume the content of the transaction.

func (Tx) Nonce

func (tx Tx) Nonce() pack.U256

Nonce returns the nonce used to order the transaction with respect to all other transactions signed and submitted by the sender.

func (Tx) Payload

func (tx Tx) Payload() contract.CallData

Payload returns arbitrary data that is associated with the transaction. Generally, this payload is used to send notes between external accounts, or invoke business logic on a contract.

func (Tx) Serialize

func (tx Tx) Serialize() (pack.Bytes, error)

Serialize the transaction into bytes. Generally, this is the format in which the transaction will be submitted by the client.

func (Tx) Sighashes

func (tx Tx) Sighashes() ([]pack.Bytes32, error)

Sighashes returns the digests that must be signed before the transaction can be submitted by the client.

func (*Tx) Sign

func (tx *Tx) Sign(signatures []pack.Bytes65, pubkey pack.Bytes) error

Sign the transaction by injecting signatures for the required sighashes. The serialized public key used to sign the sighashes must also be specified.

func (Tx) To

func (tx Tx) To() address.Address

To returns the address that is receiving the transaction. This can be the address of an external account, controlled by a private key, or it can be the address of a contract.

func (Tx) Value

func (tx Tx) Value() pack.U256

Value being sent from the sender to the receiver.

type TxBuilder

type TxBuilder struct {
}

TxBuilder represents a transaction builder that builds transactions to be broadcasted to the filecoin network. The TxBuilder is configured using a gas price and gas limit.

func NewTxBuilder

func NewTxBuilder() TxBuilder

NewTxBuilder creates a new transaction builder.

func (TxBuilder) BuildTx

func (txBuilder TxBuilder) BuildTx(ctx context.Context, fromPubKey *id.PubKey, to address.Address, value, nonce, gasLimit, gasPrice, gasCap pack.U256, payload pack.Bytes) (account.Tx, error)

BuildTx receives transaction fields and constructs a new transaction.

Jump to

Keyboard shortcuts

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