forked from cerc-io/laconicd-deprecated
docs: vuepress setup and section titles (#311)
* vuepress * docs: vuepress setup and TODOs * doc scripts * update Makefile and gitignore * more docs updates * gitignore * metamask instructions * update image * updates * updates from call * docs: vuepress config and home.vue (#350) * update uncles return (#337) * x/evm: fix EndBlock consensus failure (#334) * add test for sending tx w/ 21000 gas * improve rpc transfer test * use ctx in EndBlock * UpdateAccounts and ClearStateObjects with passed in context * log ethereum address on error Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze <federico.kunze94@gmail.com> * update Ethermint color variables * add header and footer logo * tweak config.js * WIP custom homepage.vue * add layout to docs/README * update color variables * add eth logo black and white * tweak docs/README * update logo and logo-bw svg * bump 1.0.167 * homepage → home * add icon-code, icon-rocket * layout: home, remove configurable frontmatter: label, read, use * clean up config.js * bump 1.0.168 * fix missing comma from resolving conflicts * update sidebar, config nav, path * remove left whitespace on the header and footer logos * clean up home.vue, docs/README * update ethermint forum url in footer.links * comment out custom true to enable searchbar in subpages * remove external link icon for Guides * comments, revert custom true * clean up config.js, add specifications icon Co-authored-by: noot <36753753+noot@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze <federico.kunze94@gmail.com> * final touches Co-authored-by: Cyrus Goh <hello@lovincyrus.com> Co-authored-by: noot <36753753+noot@users.noreply.github.com>
This commit is contained in:
co-authored by
Federico Kunze
noot
Cyrus Goh
parent
edf4357176
commit
d4fe9b234c
@@ -0,0 +1,14 @@
|
||||
<!--
|
||||
order: false
|
||||
parent:
|
||||
order: 4
|
||||
-->
|
||||
|
||||
# Core Concepts
|
||||
|
||||
This repository contains reference documentation on the core concepts of Ethermint.
|
||||
|
||||
1. [Encoding](./encoding.md)
|
||||
2. [Events](./events.md)
|
||||
|
||||
After reading the core concepts, head on to the [guides](../guides/README.md) to learn how to use Ethereum tooling with Ethermint.
|
||||
@@ -0,0 +1,73 @@
|
||||
<!--
|
||||
order: 1
|
||||
-->
|
||||
|
||||
# Encoding
|
||||
|
||||
The `codec` is used everywhere in the Cosmos SDK to encode and decode structs and interfaces. The specific codec used in the Cosmos SDK is called `go-amino`. {synopsis}
|
||||
|
||||
## Pre-requisite Readings
|
||||
|
||||
- [Anatomy of an SDK application](../basics/app-anatomy.md) {prereq}
|
||||
|
||||
## Encoding Formats
|
||||
|
||||
The Cosmos SDK utilizes two binary wire encoding protocols, [Amino](https://github.com/tendermint/go-amino/)
|
||||
and [Protocol Buffers](https://developers.google.com/protocol-buffers), where Amino
|
||||
is an object encoding specification. It is a subset of Proto3 with an extension for
|
||||
interface support. See the [Proto3 spec](https://developers.google.com/protocol-buffers/docs/proto3)
|
||||
for more information on Proto3, which Amino is largely compatible with (but not with Proto2).
|
||||
|
||||
Due to Amino having significant performance drawbacks, being reflection-based, and
|
||||
not having any meaningful cross-language/client support, Protocol Buffers, specifically
|
||||
[gogoprotobuf](https://github.com/gogo/protobuf/), is being used in place of Amino.
|
||||
Note, this process of using Protocol Buffers over Amino is still an ongoing process.
|
||||
|
||||
Binary wire encoding of types in the Cosmos SDK can be broken down into two main
|
||||
categories, client encoding and store encoding. Client encoding mainly revolves
|
||||
around transaction processing and signing, whereas store encoding revolves around
|
||||
types used in state-machine transitions and what is ultimately stored in the Merkle
|
||||
tree.
|
||||
|
||||
For store encoding, protobuf definitions can exist for any type and will typically
|
||||
have an Amino-based "intermediary" type. Specifically, the protobuf-based type
|
||||
definition is used for serialization and persistence, whereas the Amino-based type
|
||||
is used for business logic in the state-machine where they may converted back-n-forth.
|
||||
Note, the Amino-based types may slowly be phased-out in the future so developers
|
||||
should take note to use the protobuf message definitions where possible.
|
||||
|
||||
In the `codec` package, there exists two core interfaces, `Marshaler` and `ProtoMarshaler`,
|
||||
where the former encapsulates the current Amino interface except it operates on
|
||||
types implementing the latter instead of generic `interface{}` types.
|
||||
|
||||
In addition, there exists three implementations of `Marshaler`. The first being
|
||||
`AminoCodec`, where both binary and JSON serialization is handled via Amino. The
|
||||
second being `ProtoCodec`, where both binary and JSON serialization is handled
|
||||
via Protobuf. Finally, `HybridCodec`, a codec that utilizes Protobuf for binary
|
||||
serialization and Amino for JSON serialization. The `HybridCodec` is typically
|
||||
the codec that used in majority in situations as it's easier to use for client
|
||||
and state serialization.
|
||||
|
||||
This means that modules may use Amino or Protobuf encoding but the types must
|
||||
implement `ProtoMarshaler`. If modules wish to avoid implementing this interface
|
||||
for their types, they may use an Amino codec directly.
|
||||
|
||||
### Amino
|
||||
|
||||
Every module uses an Amino codec to serialize types and interfaces. This codec typically
|
||||
has types and interfaces registered in that module's domain only (e.g. messages),
|
||||
but there are exceptions like `x/gov`. Each module exposes a `RegisterCodec` function
|
||||
that allows a user to provide a codec and have all the types registered. An application
|
||||
will call this method for each necessary module.
|
||||
|
||||
### Protobuf
|
||||
|
||||
<!-- TODO: -->
|
||||
|
||||
## RLP
|
||||
|
||||
<!-- TODO: -->
|
||||
|
||||
## Next {hide}
|
||||
|
||||
Learn about [events](./events.md) {hide}
|
||||
@@ -0,0 +1,116 @@
|
||||
<!--
|
||||
order: 2
|
||||
-->
|
||||
|
||||
# Events
|
||||
|
||||
`Event`s are objects that contain information about the execution of the application. They are mainly used by service providers like block explorers and wallet to track the execution of various messages and index transactions. {synopsis}
|
||||
|
||||
## Pre-requisite Readings
|
||||
|
||||
- [Anatomy of an SDK application](../basics/app-anatomy.md) {prereq}
|
||||
|
||||
## Events
|
||||
|
||||
Events are implemented in the Cosmos SDK as an alias of the ABCI `Event` type and
|
||||
take the form of: `{eventType}.{eventAttribute}={value}`.
|
||||
|
||||
+++ https://github.com/tendermint/tendermint/blob/bc572217c07b90ad9cee851f193aaa8e9557cbc7/abci/types/types.pb.go#L2187-L2193
|
||||
|
||||
Events contain:
|
||||
|
||||
- A `type`, which is meant to categorize an event at a high-level (e.g. by module or action).
|
||||
- A list of `attributes`, which are key-value pairs that give more information about
|
||||
the categorized `event`.
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/events.go#L51-L56
|
||||
|
||||
Events are returned to the underlying consensus engine in the response of the following ABCI messages:
|
||||
|
||||
- [`BeginBlock`](./baseapp.md#beginblock)
|
||||
- [`EndBlock`](./baseapp.md#endblock)
|
||||
- [`CheckTx`](./baseapp.md#checktx)
|
||||
- [`DeliverTx`](./baseapp.md#delivertx)
|
||||
|
||||
Events, the `type` and `attributes`, are defined on a **per-module basis** in the module's
|
||||
`/types/events.go` file, and triggered from the module's [`handler`](../building-modules/handler.md)
|
||||
via the [`EventManager`](#eventmanager). In addition, each module documents its events under
|
||||
`spec/xx_events.md`.
|
||||
|
||||
## EventManager
|
||||
|
||||
In Cosmos SDK applications, events are managed by an abstraction called the `EventManager`.
|
||||
Internally, the `EventManager` tracks a list of `Events` for the entire execution flow of a
|
||||
transaction or `BeginBlock`/`EndBlock`.
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/events.go#L16-L20
|
||||
|
||||
The `EventManager` comes with a set of useful methods to manage events. Among them, the one that is
|
||||
used the most by module and application developers is the `EmitEvent` method, which tracks
|
||||
an `event` in the `EventManager`.
|
||||
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/events.go#L29-L31
|
||||
|
||||
Module developers should handle event emission via the `EventManager#EmitEvent` in each message
|
||||
`Handler` and in each `BeginBlock`/`EndBlock` handler. The `EventManager` is accessed via
|
||||
the [`Context`](./context.md), where event emission generally follows this pattern:
|
||||
|
||||
```go
|
||||
ctx.EventManager().EmitEvent(
|
||||
sdk.NewEvent(eventType, sdk.NewAttribute(attributeKey, attributeValue)),
|
||||
)
|
||||
```
|
||||
|
||||
Module's `handler` function should also set a new `EventManager` to the `context` to isolate emitted events per `message`:
|
||||
```go
|
||||
func NewHandler(keeper Keeper) sdk.Handler {
|
||||
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
||||
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
||||
switch msg := msg.(type) {
|
||||
```
|
||||
|
||||
See the [`Handler`](../building-modules/handler.md) concept doc for a more detailed
|
||||
view on how to typically implement `Events` and use the `EventManager` in modules.
|
||||
|
||||
## Subscribing to Events
|
||||
|
||||
It is possible to subscribe to `Events` via Tendermint's [Websocket](https://tendermint.com/docs/app-dev/subscribing-to-events-via-websocket.html#subscribing-to-events-via-websocket).
|
||||
This is done by calling the `subscribe` RPC method via Websocket:
|
||||
|
||||
```json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "subscribe",
|
||||
"id": "0",
|
||||
"params": {
|
||||
"query": "tm.event='eventCategory' AND eventType.eventAttribute='attributeValue'"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The main `eventCategory` you can subscribe to are:
|
||||
|
||||
- `NewBlock`: Contains `events` triggered during `BeginBlock` and `EndBlock`.
|
||||
- `Tx`: Contains `events` triggered during `DeliverTx` (i.e. transaction processing).
|
||||
- `ValidatorSetUpdates`: Contains validator set updates for the block.
|
||||
|
||||
These events are triggered from the `state` package after a block is committed. You can get the
|
||||
full list of `event` categories [here](https://godoc.org/github.com/tendermint/tendermint/types#pkg-constants).
|
||||
|
||||
The `type` and `attribute` value of the `query` allow you to filter the specific `event` you are looking for. For example, a `transfer` transaction triggers an `event` of type `Transfer` and has `Recipient` and `Sender` as `attributes` (as defined in the [`events` file of the `bank` module](https://github.com/cosmos/cosmos-sdk/blob/master/x/bank/types/events.go)). Subscribing to this `event` would be done like so:
|
||||
|
||||
```json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "subscribe",
|
||||
"id": "0",
|
||||
"params": {
|
||||
"query": "tm.event='Tx' AND transfer.sender='senderAddress'"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
where `senderAddress` is an address following the [`AccAddress`](../basics/accounts.md#addresses) format.
|
||||
|
||||
## Next {hide}
|
||||
|
||||
Learn how to connect Ethermint to [Metamask](./../guides/metamask.md) {hide}
|
||||
Reference in New Issue
Block a user