klaytn

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

README

CircleCI codecov GoDoc

Klaytn

Official golang implementation of the Klaytn protocol. Please visit KlaytnDocs for more details on Klaytn design, node operation guides and application development resources.

Building from Sources

Building the Klaytn node binaries as well as utility tools, such as kcn, kpn, ken, kbn, kscn, kspn, ksen, kgen, homi and abigen requires both a Go (version 1.11.2 or later) and a C compiler. You can install them using your favorite package manager. Once the dependencies are installed, run

make all (or make {kcn, kpn, ken, kbn, kscn, kspn, ksen, kgen, homi, abigen})

Executables

After successful build, executable binaries are installed at build/bin/.

Command Description
kcn The CLI client for Klaytn Consensus Node. Run kcn --help for command-line flags.
kpn The CLI client for Klaytn Proxy Node. Run kpn --help for command-line flags.
ken The CLI client for Klaytn Endpoint Node, which is the entry point into the Klaytn network (main-, test- or private net). It can be used by other processes as a gateway into the Klaytn network via JSON RPC endpoints exposed on top of HTTP, WebSocket, gRPC, and/or IPC transports. Run ken --help for command-line flags.
kscn The CLI client for Klaytn ServiceChain Consensus Node. Run kscn --help for command-line flags.
kspn The CLI client for Klaytn ServiceChain Proxy Node. Run kspn --help for command-line flags.
ksen The CLI client for Klaytn ServiceChain Endopoint Node. Run ksen --help for command-line flags.
kbn The CLI client for Klaytn Bootnode. Run kbn --help for command-line flags.
kgen The CLI client for Klaytn Nodekey Generation Tool. Run kgen --help for command-line flags.
homi The CLI client for Klaytn Helper Tool to generate initialization files. Run homi --help for command-line flags.
abigen Source code generator to convert Klaytn contract definitions into easy to use, compile-time type-safe Go packages.

Both kcn and ken are capable of running as a full node (default) or an archive node (retaining all historical state).

Running a Core Cell

Core Cell (CC) is a set of one consensus node (CN) and one or more proxy nodes (PNs). Core Cell plays a role of generating blocks in the Klaytn network. We recommend to visit the CC Operation Guide for the details of CC bootstrapping process.

Running an Endpoint Node

Endpoint Node (EN) is an entry point from the outside of the network in order to interact with the Klaytn network. Currently, two official networks are available: Baobab (testnet) and Cypress (mainnet). Please visit the official EN Operation Guide.

Running a Service Chain Node

Service chain node is a node for Service Chain which is an auxiliary blockchain independent from the main chain tailored for individual service requiring special node configurations, customized security levels, and scalability for high throughput services. Service Chain expands and augments Klaytn by providing a data integrity mechanism and supporting token transfers between different chains. Although the service chain feature is under development, we provide the operation guide for testing purposes. Please visit the official document Service Chain Operation Guide. Furthermore, for those who are interested in the Klaytn Service Chain, please check out Klaytn - Service Chain.

License

The Klaytn library (i.e. all code outside of the cmd directory) is licensed under the GNU Lesser General Public License v3.0, also included in our repository in the COPYING.LESSER file.

The Klaytn binaries (i.e. all code inside of the cmd directory) is licensed under the GNU General Public License v3.0, also included in our repository in the COPYING file.

Contributing

As an open source project, Klaytn always welcomes your contribution. Please read our CONTRIBUTING.md for a walk-through of the contribution process.

Documentation

Overview

Package klaytn defines interfaces for interacting with Klaytn.

Index

Constants

This section is empty.

Variables

View Source
var NotFound = errors.New("not found")

NotFound is returned by API methods if the requested item does not exist.

Functions

This section is empty.

Types

type CallMsg

type CallMsg struct {
	From     common.Address  // the sender of the 'transaction'
	To       *common.Address // the destination contract (nil for contract creation)
	Gas      uint64          // if 0, the call executes with near-infinite gas
	GasPrice *big.Int        // peb <-> gas exchange ratio
	Value    *big.Int        // amount of peb sent along with the call
	Data     []byte          // input data, usually an ABI-encoded contract method invocation
}

CallMsg contains parameters for contract calls.

type ChainReader

type ChainReader interface {
	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
	TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
	TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)

	// This method subscribes to notifications about changes of the head block of
	// the canonical chain.
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (Subscription, error)
}

ChainReader provides access to the blockchain. The methods in this interface access raw data from either the canonical chain (when requesting by block number) or any blockchain fork that was previously downloaded and processed by the node. The block number argument can be nil to select the latest canonical block. Reading block headers should be preferred over full blocks whenever possible.

The returned error is NotFound if the requested item does not exist.

type ChainStateReader

type ChainStateReader interface {
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
}

ChainStateReader wraps access to the state trie of the canonical blockchain. Note that implementations of the interface may be unable to return state values for old blocks. In many cases, using CallContract can be preferable to reading raw contract storage.

type ChainSyncReader

type ChainSyncReader interface {
	SyncProgress(ctx context.Context) (*SyncProgress, error)
}

ChainSyncReader wraps access to the node's current sync status. If there's no sync currently running, it returns nil.

type ContractCaller

type ContractCaller interface {
	CallContract(ctx context.Context, call CallMsg, blockNumber *big.Int) ([]byte, error)
}

A ContractCaller provides contract calls, essentially transactions that are executed by the EVM but not mined into the blockchain. ContractCall is a low-level method to execute such calls. For applications which are structured around specific contracts, the abigen tool provides a nicer, properly typed way to perform calls.

type FilterQuery

type FilterQuery struct {
	FromBlock *big.Int         // beginning of the queried range, nil means genesis block
	ToBlock   *big.Int         // end of the range, nil means latest block
	Addresses []common.Address // restricts matches to events created by specific contracts

	// The Topic list restricts matches to particular event topics. Each event has a list
	// of topics. Topics matches a prefix of that list. An empty element slice matches any
	// topic. Non-empty elements represent an alternative that matches any of the
	// contained topics.
	//
	// Examples:
	// {} or nil          matches any topic list
	// {{A}}              matches topic A in first position
	// {{}, {B}}          matches any topic in first position, B in second position
	// {{A}}, {B}}        matches topic A in first position, B in second position
	// {{A, B}}, {C, D}}  matches topic (A OR B) in first position, (C OR D) in second position
	Topics [][]common.Hash
}

FilterQuery contains options for contract log filtering.

type GasEstimator

type GasEstimator interface {
	EstimateGas(ctx context.Context, call CallMsg) (uint64, error)
}

GasEstimator wraps EstimateGas, which tries to estimate the gas needed to execute a specific transaction based on the pending state. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.

type GasPricer

type GasPricer interface {
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
}

GasPricer wraps the gas price oracle, which monitors the blockchain to determine the optimal gas price given current fee market conditions.

type LogFilterer

type LogFilterer interface {
	FilterLogs(ctx context.Context, q FilterQuery) ([]types.Log, error)
	SubscribeFilterLogs(ctx context.Context, q FilterQuery, ch chan<- types.Log) (Subscription, error)
}

LogFilterer provides access to contract log events using a one-off query or continuous event subscription.

Logs received through a streaming query subscription may have Removed set to true, indicating that the log was reverted due to a chain reorganisation.

type PendingContractCaller

type PendingContractCaller interface {
	PendingCallContract(ctx context.Context, call CallMsg) ([]byte, error)
}

PendingContractCaller can be used to perform calls against the pending state.

type PendingStateEventer

type PendingStateEventer interface {
	SubscribePendingTransactions(ctx context.Context, ch chan<- *types.Transaction) (Subscription, error)
}

A PendingStateEventer provides access to real time notifications about changes to the pending state.

type PendingStateReader

type PendingStateReader interface {
	PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
	PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	PendingTransactionCount(ctx context.Context) (uint, error)
}

A PendingStateReader provides access to the pending state, which is the result of all known executable transactions which have not yet been included in the blockchain. It is commonly used to display the result of ’unconfirmed’ actions (e.g. wallet value transfers) initiated by the user. The PendingNonceAt operation is a good way to retrieve the next available transaction nonce for a specific account.

type Subscription

type Subscription interface {
	// Unsubscribe cancels the sending of events to the data channel
	// and closes the error channel.
	Unsubscribe()
	// Err returns the subscription error channel. The error channel receives
	// a value if there is an issue with the subscription (e.g. the network connection
	// delivering the events has been closed). Only one value will ever be sent.
	// The error channel is closed by Unsubscribe.
	Err() <-chan error
}

Subscription represents an event subscription where events are delivered on a data channel.

type SyncProgress

type SyncProgress struct {
	StartingBlock uint64 // Block number where sync began
	CurrentBlock  uint64 // Current block number where sync is at
	HighestBlock  uint64 // Highest alleged block number in the chain
	PulledStates  uint64 // Number of state trie entries already downloaded
	KnownStates   uint64 // Total number of state trie entries known about
}

SyncProgress gives progress indications when the node is synchronising with the Klaytn network.

type TransactionReader

type TransactionReader interface {
	// TransactionByHash checks the pool of pending transactions in addition to the
	// blockchain. The isPending return value indicates whether the transaction has been
	// mined yet. Note that the transaction may not be part of the canonical chain even if
	// it's not pending.
	TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error)
	// TransactionReceipt returns the receipt of a mined transaction. Note that the
	// transaction may not be included in the current canonical chain even if a receipt
	// exists.
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
}

TransactionReader provides access to past transactions and their receipts. Implementations may impose arbitrary restrictions on the transactions and receipts that can be retrieved. Historic transactions may not be available.

Avoid relying on this interface if possible. Contract logs (through the LogFilterer interface) are more reliable and usually safer in the presence of chain reorganisations.

The returned error is NotFound if the requested item does not exist.

type TransactionSender

type TransactionSender interface {
	SendTransaction(ctx context.Context, tx *types.Transaction) error
}

TransactionSender wraps transaction sending. The SendTransaction method injects a signed transaction into the pending transaction pool for execution. If the transaction was a contract creation, the TransactionReceipt method can be used to retrieve the contract address after the transaction has been mined.

The transaction must be signed and have a valid nonce to be included. Consumers of the API can use package accounts to maintain local private keys and need can retrieve the next available nonce using PendingNonceAt.

Directories

Path Synopsis
Package accounts implements high level Klaytn account management.
Package accounts implements high level Klaytn account management.
abi
Package abi implements the Klaytn ABI (Application Binary Interface).
Package abi implements the Klaytn ABI (Application Binary Interface).
abi/bind
Package bind generates Klaytn contract Go bindings.
Package bind generates Klaytn contract Go bindings.
abi/bind/backends
Package backends implements simulated bind contract backend for testing contract bindings.
Package backends implements simulated bind contract backend for testing contract bindings.
keystore
Package keystore implements encrypted storage of secp256k1 private keys.
Package keystore implements encrypted storage of secp256k1 private keys.
api
Package api implements the general Klaytn API functions.
Package api implements the general Klaytn API functions.
debug
Package debug interfaces Go runtime debugging facilities.
Package debug interfaces Go runtime debugging facilities.
Package blockchain implements the Klaytn consensus protocol.
Package blockchain implements the Klaytn consensus protocol.
asm
Package asm provides support for dealing with EVM assembly instructions (e.g., disassembling them).
Package asm provides support for dealing with EVM assembly instructions (e.g., disassembling them).
bloombits
Package bloombits implements bloom filtering on batches of data.
Package bloombits implements bloom filtering on batches of data.
state
Package state provides an uppermost caching layer of the Klaytn state trie.
Package state provides an uppermost caching layer of the Klaytn state trie.
types
Package types contains data types related to Klatyn consensus.
Package types contains data types related to Klatyn consensus.
types/account
Package account implements Account used in Klaytn.
Package account implements Account used in Klaytn.
types/accountkey
Package accountkey implements the AccountKey used in Klaytn.
Package accountkey implements the AccountKey used in Klaytn.
vm
Package vm implements the Ethereum Virtual Machine.
Package vm implements the Ethereum Virtual Machine.
vm/runtime
Package runtime provides a basic execution model for executing EVM code.
Package runtime provides a basic execution model for executing EVM code.
build
rpm
Package client provides a client for the Klaytn RPC API.
Package client provides a client for the Klaytn RPC API.
cmd
abigen
abigen implements command line interface for ABI.
abigen implements command line interface for ABI.
kbn
kbn runs a bootstrap node for the Klaytn Node Discovery Protocol.
kbn runs a bootstrap node for the Klaytn Node Discovery Protocol.
kcn
kcn is the command-line client for Klaytn Consensus Node.
kcn is the command-line client for Klaytn Consensus Node.
ken
ken is the command-line client for Klaytn Endpoint Node.
ken is the command-line client for Klaytn Endpoint Node.
kgen
kgen can be used to generate the associated nodekey information.
kgen can be used to generate the associated nodekey information.
kpn
kpn is the command-line client for Klaytn Proxy Node.
kpn is the command-line client for Klaytn Proxy Node.
kscn
kscn is the command-line client for Klaytn ServiceChain Node.
kscn is the command-line client for Klaytn ServiceChain Node.
ksen
ksen is the command-line client for Klaytn ServiceChain Endpoint Node.
ksen is the command-line client for Klaytn ServiceChain Endpoint Node.
kspn
kspn is the command-line client for Klaytn ServiceChain Proxy Node.
kspn is the command-line client for Klaytn ServiceChain Proxy Node.
utils
Package utils contains internal helper functions for klaytn commands.
Package utils contains internal helper functions for klaytn commands.
utils/nodecmd
Package nodecmd contains command definitions and related functions used for node cmds, such as kcn, kpn, and ken.
Package nodecmd contains command definitions and related functions used for node cmds, such as kcn, kpn, and ken.
Package common contains various helper functions, commonly used data types and constants.
Package common contains various helper functions, commonly used data types and constants.
bitutil
Package bitutil implements fast bitwise operations and compression/decompressions.
Package bitutil implements fast bitwise operations and compression/decompressions.
compiler
Package compiler wraps the Solidity compiler executable (solc).
Package compiler wraps the Solidity compiler executable (solc).
fdlimit
Package fdlimit handles file descriptors based on the operating system.
Package fdlimit handles file descriptors based on the operating system.
hexutil
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.
math
Package math provides convenience functions to use big.Int and to parse a string into an integer.
Package math provides convenience functions to use big.Int and to parse a string into an integer.
mclock
Package mclock is a wrapper for a monotonic clock source.
Package mclock is a wrapper for a monotonic clock source.
profile
Package profile provides a profiler which can store a key and related TimeRecord.
Package profile provides a profiler which can store a key and related TimeRecord.
Package consensus defines interfaces for consensus engines and ChainReader.
Package consensus defines interfaces for consensus engines and ChainReader.
clique
Package clique implements PoA (Proof of Authority) consensus engine which is mainly for private chains.
Package clique implements PoA (Proof of Authority) consensus engine which is mainly for private chains.
gxhash
Package gxhash implements the gxhash proof-of-work consensus engine.
Package gxhash implements the gxhash proof-of-work consensus engine.
istanbul
Package istanbul implements the istanbul consensus engine.
Package istanbul implements the istanbul consensus engine.
istanbul/backend
Package backend implements backend for istanbul consensus engine.
Package backend implements backend for istanbul consensus engine.
istanbul/core
Package core implements core functionality of istanbul consensus engine.
Package core implements core functionality of istanbul consensus engine.
istanbul/validator
Package validator implements the types related to the validators participating in consensus.
Package validator implements the types related to the validators participating in consensus.
Package console implements JavaScript console.
Package console implements JavaScript console.
jsre
Package jsre provides an execution environment for JavaScript.
Package jsre provides an execution environment for JavaScript.
jsre/deps
Package deps contains the console's dependencies of Javascript libraries to be embedded in Go source code.
Package deps contains the console's dependencies of Javascript libraries to be embedded in Go source code.
web3ext
Package web3ext contains the Klaytn specific web3.js extensions.
Package web3ext contains the Klaytn specific web3.js extensions.
reward/contract
Package contract contains predefined Klaytn reward contracts.
Package contract contains predefined Klaytn reward contracts.
Package crypto contains several cryptography modules used in Klaytn.
Package crypto contains several cryptography modules used in Klaytn.
bn256
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
bn256/cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
bn256/google
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
ecies
Package ecies implements the Elliptic Curve Integrated Encryption Scheme.
Package ecies implements the Elliptic Curve Integrated Encryption Scheme.
secp256k1
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package secp256k1 wraps the bitcoin secp256k1 C library.
sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
datasync
downloader
Package downloader contains the manual full chain synchronisation.
Package downloader contains the manual full chain synchronisation.
fetcher
Package fetcher contains the block announcement based synchronisation.
Package fetcher contains the block announcement based synchronisation.
Package event deals with subscriptions to real-time events.
Package event deals with subscriptions to real-time events.
filter
Package filter implements event filters.
Package filter implements event filters.
Package fork has information related to hard forks.
Package fork has information related to hard forks.
Package governance contains functions and variables used for voting and reflecting vote results in Klaytn.
Package governance contains functions and variables used for voting and reflecting vote results in Klaytn.
Package kerrors contains common error variables used in Klaytn.
Package kerrors contains common error variables used in Klaytn.
log
Package log provides an opinionated, simple toolkit for best-practice logging.
Package log provides an opinionated, simple toolkit for best-practice logging.
term
Package term contains checking specific operating system terminals.
Package term contains checking specific operating system terminals.
Go port of Coda Hale's Metrics library: <https://github.com/rcrowley/go-metrics> Coda Hale's original work: <https://github.com/codahale/metrics> Package metrics provides various kinds of metrics which can be used to collect system statistics.
Go port of Coda Hale's Metrics library: <https://github.com/rcrowley/go-metrics> Coda Hale's original work: <https://github.com/codahale/metrics> Package metrics provides various kinds of metrics which can be used to collect system statistics.
exp
Package exp hooks go-metrics into expvar on any metrics request, loads all vars from the registry into expvar, and executes regular expvar handler.
Package exp hooks go-metrics into expvar on any metrics request, loads all vars from the registry into expvar, and executes regular expvar handler.
influxdb
Package influxdb implements go-metrics library which will post to the influxDB.
Package influxdb implements go-metrics library which will post to the influxDB.
librato
Package librato implements go-metrics library which will post to the Librato.
Package librato implements go-metrics library which will post to the Librato.
prometheus
Package prometheusmetrics implements go-metrics library which will post to the prometheus client registry.
Package prometheusmetrics implements go-metrics library which will post to the prometheus client registry.
networks
grpc
Package grpc implements the gRPC protocol for Klaytn.
Package grpc implements the gRPC protocol for Klaytn.
p2p
Package p2p implements the Klaytn p2p network protocols.
Package p2p implements the Klaytn p2p network protocols.
p2p/discover
Package discover implements the Node Discovery Protocol.
Package discover implements the Node Discovery Protocol.
p2p/nat
Package nat provides access to common network port mapping protocols.
Package nat provides access to common network port mapping protocols.
p2p/netutil
Package netutil contains extensions to the net package.
Package netutil contains extensions to the net package.
p2p/simulations
Package simulations simulates p2p networks.
Package simulations simulates p2p networks.
p2p/simulations/adapters
Package adapters implements simulation network adapters in several ways.
Package adapters implements simulation network adapters in several ways.
p2p/simulations/pipes
Package pipes implements in process pipes on a localhost TCP socket.
Package pipes implements in process pipes on a localhost TCP socket.
rpc
Package rpc provides access to the exported methods of an object across a network or other I/O connection.
Package rpc provides access to the exported methods of an object across a network or other I/O connection.
Package node sets up multi-protocol Klaytn nodes.
Package node sets up multi-protocol Klaytn nodes.
cn
Package cn implements components related to Klaytn Node.
Package cn implements components related to Klaytn Node.
cn/filters
Package filters implements an ethereum filtering system for block, transactions and log events.
Package filters implements an ethereum filtering system for block, transactions and log events.
cn/gasprice
Package gasprice contains Oracle type which recommends gas prices based on recent blocks.
Package gasprice contains Oracle type which recommends gas prices based on recent blocks.
cn/tracers
Package tracers is a collection of JavaScript transaction tracers.
Package tracers is a collection of JavaScript transaction tracers.
cn/tracers/internal/tracers
Package tracers contains the actual JavaScript tracer assets.
Package tracers contains the actual JavaScript tracer assets.
sc
Package params contains configuration parameters for Klaytn.
Package params contains configuration parameters for Klaytn.
Package reward implements the Klaytn Reward System.
Package reward implements the Klaytn Reward System.
ser
rlp
Package rlp implements the RLP serialization format.
Package rlp implements the RLP serialization format.
storage
database
Package database implements various types of databases used in Klaytn.
Package database implements various types of databases used in Klaytn.
statedb
Package statedb implements the Merkle Patricia Trie structure used for state object trie.
Package statedb implements the Merkle Patricia Trie structure used for state object trie.
Package tests implements execution of Klaytn JSON tests.
Package tests implements execution of Klaytn JSON tests.
benchmarks
Package benchmarks contains go-benchmark tests for Klaytn performance.
Package benchmarks contains go-benchmark tests for Klaytn performance.
utils
build
Package build contains the utility functions for build environment.
Package build contains the utility functions for build environment.
Package work implements Klaytn block creation and mining.
Package work implements Klaytn block creation and mining.

Jump to

Keyboard shortcuts

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