Documentation ¶
Overview ¶
Package soltools provides a Go-to-JavaScript bridge to use 0x's suite of sol-X tools from Go.
0x has a suite of tools for Solidity development:
https://sol-coverage.com/ https://sol-compiler.com/ https://sol-trace.com/ https://sol-profiler.com/
The tools are designed to be used from JavaScript. This package provides a bridge so they can be used from Go. The primary interface is Backend, which is a replacement for an *ethclient.Client that sends transactions and calls through a 0x library that adds tracing.
Index ¶
- type Backend
- func (b *Backend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
- func (b *Backend) Close() error
- func (b *Backend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
- func (b *Backend) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (b *Backend) WriteCoverage() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
Backend is a replacement for an *ethclient.Client that sends transactions through 0x's tracing library in JavaScript.
func NewBackend ¶
NewBackend dials an ethereum node at nodeAddress and returns a *Backend client for that node.
NewBackend also starts a Node.js process, which the caller is responsible for closing by calling Backend.Close(). Example:
backend, err := NewBackend("http://localhost:8545", "project/artifacts", "project/contracts") // handle err defer backend.Close()
The client will add tracing to the Ethereum transactions and calls that are made through it. It can also write a coverage report, which requires passing paths to artifacts and contracts directories for the corresponding Solidity code.
func (*Backend) CallContract ¶
func (b *Backend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
CallContract overrides the same method in *ethclient.Client (and satisfies CallContract from go-ethereum's bind.ContractCaller interface). Instead of sending the call through the underlying client, it sends it through 0x's library.
func (*Backend) Close ¶
Close frees resources associated with this Backend.
In particular, it closes the backing JavaScript process and a network connection to the Ethereum node.
func (*Backend) EstimateGas ¶
EstimateGas overrides the same method in *ethclient.Client (and satisfies EstimateGas from go-ethereum's bind.ContractTransactor interface). Instead of sending the call through the underlying client, it returns a hard-coded result.
The hard-coded result is used so that transactions never fail in the gas estimation stage. Instead they will fail when the transaction is mined. This is assumed to be desirable behavior because it causes the transaction to actually run, rather than not, which causes the corresponding code to get traced for code coverage, rather than not.
func (*Backend) SendTransaction ¶
SendTransaction overrides the same method in *ethclient.Client (and satisfies SendTransaction from go-ethereum's bind.ContractTransactor interface). Instead of sending the call through the underlying client, it sends it through 0x's library.
func (*Backend) WriteCoverage ¶
WriteCoverage writes a coverage report in Istanbul format to $PWD/coverage/coverage.json.