jsonrpc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MPL-2.0 Imports: 14 Imported by: ? modules, 0 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.

README

Eth-jsonrpc-server

Usage

package main

import (
    ethjsonrpc "github.com/umbracle/eth-jsonrpc-server"
    "github.com/umbracle/eth-jsonrpc-server/jsonrpc"
)

func main() {
    // Create the jsonrpc server
    srv := jsonrpc.NewServer(
        jsonrpc.WithBindAddr("0.0.0.0:8545"),
        jsonrpc.WithIPC("ipc.path"),
    )

    // bind the ethereum endpoints
    srv.Register(ethjsonrpc.NewEth(&backend{}))
}

type backend struct {
    // ...
}

Documentation

Index

Constants

View Source
const (
	PendingBlockNumber  = BlockNumber(-3)
	LatestBlockNumber   = BlockNumber(-2)
	EarliestBlockNumber = BlockNumber(-1)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Nonce    uint64
	Balance  *big.Int
	Root     ethgo.Hash
	CodeHash []byte
}

type BlockNumber

type BlockNumber int64

func (*BlockNumber) UnmarshalJSON

func (b *BlockNumber) UnmarshalJSON(buffer []byte) error

UnmarshalJSON automatically decodes the user input for the block number, when a JSON RPC method is called

type Eth

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

Eth is the eth jsonrpc endpoint

func NewEth

func NewEth(b EthBackend) *Eth

func (*Eth) BlockNumber

func (e *Eth) BlockNumber() (argUint64, error)

BlockNumber returns current block number

func (*Eth) Call

func (e *Eth) Call(arg *txnArgs, number BlockNumber) (interface{}, error)

Call executes a smart contract call using the transaction object data

func (*Eth) ChainId

func (e *Eth) ChainId() (interface{}, error)

ChainId returns the chain id of the client

func (*Eth) EstimateGas

func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error)

EstimateGas estimates the gas needed to execute a transaction

func (*Eth) GasPrice

func (e *Eth) GasPrice() (interface{}, error)

GasPrice returns the average gas price based on the last x blocks

func (*Eth) GetBalance

func (e *Eth) GetBalance(address ethgo.Address, number BlockNumber) (*argBig, error)

GetBalance returns the account's balance at the referenced block

func (*Eth) GetBlockByHash

func (e *Eth) GetBlockByHash(hash ethgo.Hash, full bool) (*ethgo.Block, error)

GetBlockByHash returns information about a block by hash

func (*Eth) GetBlockByNumber

func (e *Eth) GetBlockByNumber(number BlockNumber, full bool) (*ethgo.Block, error)

GetBlockByNumber returns information about a block by block number

func (*Eth) GetCode

func (e *Eth) GetCode(address ethgo.Address, number BlockNumber) (argBytes, error)

GetCode returns account code at given block number

func (*Eth) GetFilterChanges

func (e *Eth) GetFilterChanges(id string) (interface{}, error)

GetFilterChanges is a polling method for a filter, which returns an array of logs which occurred since last poll.

func (*Eth) GetLogs

func (e *Eth) GetLogs(filterOptions *LogFilter) ([]*ethgo.Log, error)

GetLogs returns an array of logs matching the filter options

func (*Eth) GetStorageAt

func (e *Eth) GetStorageAt(address ethgo.Address, index ethgo.Hash, number BlockNumber) (interface{}, error)

GetStorageAt returns the contract storage at the index position

func (*Eth) GetTransactionByHash

func (e *Eth) GetTransactionByHash(hash ethgo.Hash) (interface{}, error)

GetTransactionByHash returns a transaction by his hash

func (*Eth) GetTransactionCount

func (e *Eth) GetTransactionCount(address ethgo.Address, number BlockNumber) (interface{}, error)

GetTransactionCount returns account nonce

func (*Eth) GetTransactionReceipt

func (e *Eth) GetTransactionReceipt(hash ethgo.Hash) (interface{}, error)

GetTransactionReceipt returns a transaction receipt by his hash

func (*Eth) NewBlockFilter

func (e *Eth) NewBlockFilter() (interface{}, error)

NewBlockFilter creates a filter in the node, to notify when a new block arrives

func (*Eth) NewFilter

func (e *Eth) NewFilter(filter *LogFilter) (interface{}, error)

NewFilter creates a filter object, based on filter options, to notify when the state changes (logs).

func (*Eth) SendRawTransaction

func (e *Eth) SendRawTransaction(input argBytes) (argBytes, error)

SendRawTransaction sends a raw transaction

func (*Eth) UninstallFilter

func (e *Eth) UninstallFilter(id string) (bool, error)

UninstallFilter uninstalls a filter with given ID

func (*Eth) Unsubscribe

func (e *Eth) Unsubscribe(id string) (bool, error)

Unsubscribe uninstalls a filter in a websocket

type EthBackend

type EthBackend interface {
	// contains filtered or unexported methods
}

type Event

type Event struct {
	// Old chain (removed headers) if there was a reorg
	OldChain []*ethgo.Block

	// New part of the chain (or a fork)
	NewChain []*ethgo.Block

	// Type is the type of event
	Type EventType
}

Event is the blockchain event that gets passed to the listeners

type EventType

type EventType int
const (
	// New head event
	EventHead EventType = iota

	// Chain reorganization event
	EventReorg

	// Chain fork event
	EventFork
)

type Filter

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

type FilterManager

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

func NewFilterManager

func NewFilterManager(logger *log.Logger, store blockchainInterface) *FilterManager

func (*FilterManager) Close

func (f *FilterManager) Close()

func (*FilterManager) Exists

func (f *FilterManager) Exists(id string) bool

func (*FilterManager) GetFilterChanges

func (f *FilterManager) GetFilterChanges(id string) (string, error)

func (*FilterManager) NewBlockFilter

func (f *FilterManager) NewBlockFilter(stream jsonrpc.Stream) string

func (*FilterManager) NewLogFilter

func (f *FilterManager) NewLogFilter(logFilter *LogFilter, stream jsonrpc.Stream) string

func (*FilterManager) Run

func (f *FilterManager) Run()

func (*FilterManager) Uninstall

func (f *FilterManager) Uninstall(id string) bool

type GetLogsInput

type GetLogsInput struct {
	From      uint64
	To        uint64
	Addresses []ethgo.Address
	Topics    [][]ethgo.Hash
}

type LogFilter

type LogFilter struct {
	BlockHash *ethgo.Hash

	Addresses []ethgo.Address
	Topics    [][]ethgo.Hash
	// contains filtered or unexported fields
}

LogFilter is a filter for logs

func (*LogFilter) Match

func (l *LogFilter) Match(log *ethgo.Log) bool

Match returns whether the receipt includes topics for this filter

func (*LogFilter) UnmarshalJSON

func (l *LogFilter) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a json object

type MockSubscription

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

func NewMockSubscription

func NewMockSubscription() *MockSubscription

func (*MockSubscription) Close

func (m *MockSubscription) Close()

func (*MockSubscription) GetEvent

func (m *MockSubscription) GetEvent() *Event

func (*MockSubscription) GetEventCh

func (m *MockSubscription) GetEventCh() chan *Event

func (*MockSubscription) Push

func (m *MockSubscription) Push(e *Event)

type Subscription

type Subscription interface {
	GetEvent() *Event
	Close()
}

Subscription is the blockchain subscription interface

type TransactionResult

type TransactionResult struct {
	Transaction *ethgo.Transaction
	Receipt     *ethgo.Receipt
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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