abci-cli,用于从命令行发送 ABCI 消息。
安装
请确保你已经安装 Go。 接下来,安装abci-cli 工具和示例应用:
abci-cli 以查看命令列表:
KVStore - 第一个示例
abci-cli 工具让我们能够向应用发送 ABCI 消息,从而帮助构建和调试应用。
最重要的消息是 deliver_tx、check_tx 和 commit,此外还有一些消息用于便捷操作、配置和信息查询。
我们先启动一个 kvstore 应用,它与上面的 abci-cli 一起安装。kvstore 只是将交易存储在一棵 Merkle 树中。它的代码可在这里查看。
运行以下命令启动应用:
- 一个 socket 服务器
- 一个 ABCI 消息处理器
abci-cli 工具时,会打开一个到应用 socket 服务器的新连接,发送给定的 ABCI 消息,然后等待响应。
服务器对于某种特定语言来说可以是通用的,我们提供了一个 Golang 参考实现。关于其他语言的服务器,请参阅其他 ABCI 实现列表。
处理器则是应用特定的,可以采用任意实现方式,只要它是确定性的并符合 ABCI 接口规范即可。
因此,当我们运行 abci-cli info 时,会打开一个到 ABCI 服务器的新连接,服务器会调用应用上的 Info() 方法,并告诉我们 Merkle 树中有多少笔交易。
由于每条命令都会打开一个新连接,我们提供了 abci-cli console 和 abci-cli batch 命令,以便通过单个连接发送多条 ABCI 消息。
运行 abci-cli console 后,你应该会进入一个交互式控制台,用来向应用发送 ABCI 消息。
尝试运行以下命令:
finalize_block "abc" ...,它会存储 (abc, abc);但如果执行 finalize_block "abc=efg" ...,它会存储 (abc, efg)。
你也可以把这些命令放进一个文件中,然后运行 abci-cli --verbose batch < myfile。
请注意,abci-cli 严格来说只是为测试和调试而设计的。在真实部署中,发送消息这一角色由 CometBFT 承担,它会通过四条独立连接接入应用,并且每条连接都有各自的消息模式。
有关将 ABCI 应用与 CometBFT 一起运行的示例,请参阅入门指南。
悬赏
想用你最喜欢的语言编写一个应用吗?我们很乐意将你加入我们的生态系统! 请查看 Interchain Foundation 提供的资助机会,以支持新语言实现及更多相关工作。To facilitate testing and debugging of ABCI servers and simple apps, we built a CLI, the
abci-cli, for sending ABCI messages from the command
line.
Install
Make sure you have Go installed. Next, install theabci-cli tool and example applications:
abci-cli to see the list of commands:
KVStore - First Example
Theabci-cli tool lets us send ABCI messages to our application to
help build and debug them.
The most important messages are deliver_tx, check_tx, and commit,
but there are others for convenience, configuration, and information
purposes.
We’ll start a kvstore application, which was installed at the same time as
abci-cli above. The kvstore just stores transactions in a Merkle tree. Its
code can be found
here.
Start the application by running:
- a socket server
- a handler for ABCI messages
abci-cli tool, we open a new connection to the
application’s socket server, send the given ABCI message, and wait for a
response.
The server may be generic for a particular language, and we provide a
reference implementation in
Golang. See the
list of other ABCI implementations for servers in
other languages.
The handler is specific to the application, and may be arbitrary, so
long as it is deterministic and conforms to the ABCI interface
specification.
So when we run abci-cli info, we open a new connection to the ABCI
server, which calls the Info() method on the application, which tells
us the number of transactions in our Merkle tree.
Now, since every command opens a new connection, we provide the
abci-cli console and abci-cli batch commands to allow multiple ABCI
messages to be sent over a single connection.
Running abci-cli console should drop you into an interactive console for
speaking ABCI messages to your application.
Try running these commands:
finalize_block "abc" ... it will store (abc, abc), but if
we do finalize_block "abc=efg" ... it will store (abc, efg).
You could put the commands in a file and run
abci-cli --verbose batch < myfile.
Note that the abci-cli is designed strictly for testing and debugging. In a real
deployment, the role of sending messages is taken by CometBFT, which
connects to the app using four separate connections, each with its own
pattern of messages.
For examples of running an ABCI app with CometBFT, see the
getting started guide.