starknet

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 19 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FeltLength = 32
)

Variables

This section is empty.

Functions

func DecodeFelts

func DecodeFelts(felts []*big.Int) ([]byte, error)

DecodeFelts is the reverse of EncodeFelts

func EncodeFelts

func EncodeFelts(data []byte) (felts []*big.Int)

EncodeFelts takes a byte slice and splits as bunch of felts. First felt indicates the total byte size.

func ExponentialBackoff

func ExponentialBackoff(wait time.Duration) time.Duration

func FeltsToBig

func FeltsToBig(in []*felt.Felt) (out []*big.Int)

func Min

func Min[T cmp.Ordered](a, b T) T

func NewTestFeederServer

func NewTestFeederServer() *httptest.Server

Only responds on valid /get_transaction?transactionHash=<TRANSACTION_HASH> requests. fails otherwise

func NilResultError

func NilResultError(funcName string) error

func NopBackoff

func NopBackoff(d time.Duration) time.Duration

func PadBytes

func PadBytes(a []byte, length int) []byte

padd bytes to specific length

func XXXMustHexDecodeString

func XXXMustHexDecodeString(data string) []byte

Types

type Backoff

type Backoff func(wait time.Duration) time.Duration

type BatchBuilder

type BatchBuilder interface {
	RequestBlockByHash(h *felt.Felt) BatchBuilder
	RequestBlockByNumber(id uint64) BatchBuilder
	RequestChainID() BatchBuilder
	// RequestLatestPendingBlock() (BatchBuilder)
	RequestLatestBlockHashAndNumber() BatchBuilder
	RequestEventsByFilter(f starknetrpc.EventsInput) BatchBuilder
	// RequestTxReceiptByHash(h *felt.Felt) (BatchBuilder)
	Build() []gethrpc.BatchElem
}

used to create batch requests

func NewBatchBuilder

func NewBatchBuilder() BatchBuilder

type CallOps

type CallOps struct {
	ContractAddress *felt.Felt
	Selector        *felt.Felt
	Calldata        []*felt.Felt
}

type ChainClient

type ChainClient interface {
	// only finalized blocks have a block hashes
	BlockByHash(ctx context.Context, h *felt.Felt) (FinalizedBlock, error)
	// only finalized blocks have numbers
	BlockByNumber(ctx context.Context, id uint64) (FinalizedBlock, error)
	ChainID(ctx context.Context) (string, error)
	// only way to get the latest pending block (only 1 pending block exists at a time)
	// LatestPendingBlock(ctx context.Context) (starknetrpc.PendingBlock, error)
	// returns block number and block has of latest finalized block
	LatestBlockHashAndNumber(ctx context.Context) (starknetrpc.BlockHashAndNumberOutput, error)
	// get block logs, event logs, etc.
	EventsByFilter(ctx context.Context, f starknetrpc.EventsInput) (starknetrpc.EventChunk, error)
	// TxReceiptByHash(ctx context.Context, h *felt.Felt) (starknetrpc.TransactionReceipt, error)
	Batch(ctx context.Context, builder BatchBuilder) ([]gethrpc.BatchElem, error)
}

type Client

type Client struct {
	Provider  starknetrpc.RpcProvider
	EthClient *ethrpc.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(chainID string, baseURL string, apiKey string, lggr logger.Logger, timeout *time.Duration) (*Client, error)

pass nil or 0 to timeout to not use built in default timeout

func (*Client) AccountNonce

func (c *Client) AccountNonce(ctx context.Context, accountAddress *felt.Felt) (*felt.Felt, error)

func (*Client) Batch

func (c *Client) Batch(ctx context.Context, builder BatchBuilder) ([]gethrpc.BatchElem, error)

func (*Client) BlockByHash

func (c *Client) BlockByHash(ctx context.Context, h *felt.Felt) (FinalizedBlock, error)

func (*Client) BlockByNumber

func (c *Client) BlockByNumber(ctx context.Context, id uint64) (FinalizedBlock, error)

func (*Client) BlockWithTxHashes

func (c *Client) BlockWithTxHashes(ctx context.Context, blockID starknetrpc.BlockID) (*starknetrpc.Block, error)

func (*Client) Call

func (c *Client) Call(ctx context.Context, calls starknetrpc.FunctionCall, blockHashOrTag starknetrpc.BlockID) ([]*felt.Felt, error)

func (*Client) CallContract

func (c *Client) CallContract(ctx context.Context, ops CallOps) (data []*felt.Felt, err error)

func (*Client) ChainID

func (c *Client) ChainID(ctx context.Context) (string, error)

func (*Client) Events

func (*Client) EventsByFilter

func (*Client) LatestBlockHashAndNumber

func (c *Client) LatestBlockHashAndNumber(ctx context.Context) (starknetrpc.BlockHashAndNumberOutput, error)

func (*Client) LatestBlockHeight

func (c *Client) LatestBlockHeight(ctx context.Context) (uint64, error)

func (*Client) TransactionByHash

func (c *Client) TransactionByHash(ctx context.Context, hash *felt.Felt) (starknetrpc.Transaction, error)

func (*Client) TransactionReceipt

func (c *Client) TransactionReceipt(ctx context.Context, hash *felt.Felt) (starknetrpc.TransactionReceipt, error)

type FeederClient

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

func NewFeederClient

func NewFeederClient(clientURL string) *FeederClient

func NewTestFeederClient

func NewTestFeederClient(t *testing.T) *FeederClient

NewTestFeederClient returns a client and a function to close a test server.

func (*FeederClient) TransactionFailure

func (c *FeederClient) TransactionFailure(ctx context.Context, transactionHash *felt.Felt) (*TransactionFailureReason, error)

func (*FeederClient) WithBackoff

func (c *FeederClient) WithBackoff(b Backoff) *FeederClient

func (*FeederClient) WithLogger

func (c *FeederClient) WithLogger(log utils.SimpleLogger) *FeederClient

func (*FeederClient) WithMaxRetries

func (c *FeederClient) WithMaxRetries(num int) *FeederClient

func (*FeederClient) WithMaxWait

func (c *FeederClient) WithMaxWait(d time.Duration) *FeederClient

func (*FeederClient) WithMinWait

func (c *FeederClient) WithMinWait(d time.Duration) *FeederClient

type FinalizedBlock

type FinalizedBlock = starknetrpc.Block

type alias for readibility

type Reader

type Reader interface {
	CallContract(context.Context, CallOps) ([]*felt.Felt, error)
	LatestBlockHeight(context.Context) (uint64, error)

	// provider interface
	BlockWithTxHashes(ctx context.Context, blockID starknetrpc.BlockID) (*starknetrpc.Block, error)
	Call(context.Context, starknetrpc.FunctionCall, starknetrpc.BlockID) ([]*felt.Felt, error)
	Events(ctx context.Context, input starknetrpc.EventsInput) (*starknetrpc.EventChunk, error)
	TransactionByHash(context.Context, *felt.Felt) (starknetrpc.Transaction, error)
	TransactionReceipt(context.Context, *felt.Felt) (starknetrpc.TransactionReceipt, error)
	AccountNonce(context.Context, *felt.Felt) (*felt.Felt, error)
}

type ReaderWriter

type ReaderWriter interface {
	Reader
	Writer
}

type RejectedTransaction

type RejectedTransaction struct {
	FailureReason string `json:"transaction_failure_reason"`
}

type TransactionFailureReason

type TransactionFailureReason struct {
	Code         string `json:"code"`
	ErrorMessage string `json:"error_message"`
}

type Writer

type Writer interface {
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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