-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add docs: modularization intro & implement a Actuator #2882
add docs: modularization intro & implement a Actuator #2882
Conversation
ef4ff27
to
8eee6f9
Compare
@@ -0,0 +1,301 @@ | |||
# 自定义 SumActuator | |||
|
|||
actuator 模块抽象出4个方法并定义在 Actuator 接口中: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize.
# 自定义 SumActuator | ||
|
||
actuator 模块抽象出4个方法并定义在 Actuator 接口中: | ||
1. execute: 负责交易执行的逻辑,如状态修改、流程跳转、逻辑判断... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function name should be in
`foo()`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/.../等/
|
||
## 定义并注册合约 | ||
|
||
目前 java-tron 支持的合约定义在 protocol 模块的 src/main/protos/core/contract 目录中,在这个目录下新建一个 math_contract.proto 文件并声明 SumContract,SumContract 的逻辑是将两个数值相加求和: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use inline code style
`code here`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change the last ,
to 。
.
int64 param2 = 2; | ||
bytes owner_address = 3; | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use code highlight:
message SumContract {
int64 param1 = 1;
int64 param2 = 2;
bytes owner_address = 3;
}
```protobuf
message SumContract {
int64 param1 = 1;
int64 param2 = 2;
bytes owner_address = 3;
}
```
bytes owner_address = 3; | ||
} | ||
``` | ||
同时将新的合约类型注册在 src/main/protos/core/Tron.proto 文件的 Transaction 对象中,交易、账号、区块等重要的数据结构都定义在 Tron.proto 文件中: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transaction.Contract.ContractType
枚举中
} | ||
} | ||
``` | ||
为了简单起见 SumActuator 的执行结果直接输出至 log 文件中,对于有存储需求的情况,可以考虑创建一个新的 chainbase 来存储相应的数据。*具体如何创建 chainbase 不是本文讨论内容,相关文章后续发布,敬请期待* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*italic* style is seldom used in Chineses environment.
*具体如何创建 chainbase 不是本文讨论内容,相关文章后续发布,敬请期待* =>
(创建 chainbase 的方法将在后续相关文章中发布)
|
||
@Test | ||
public void sumActuatorTest() { | ||
// this key define in config-localtest.conf as accountName=Sun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/define/is defined/
builder.setOwnerAddress(ByteString.copyFrom(address)); | ||
MathContract.SumContract contract = builder.build(); | ||
|
||
// send contract and return trx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trx
misleading. use Transaction
} | ||
} | ||
``` | ||
运行 SumActuatorTest 测试类即可在log文件中看到 `SumActuator: param1 = 1, param2 = 2, sum = 3` 类似的输出字样,为了方便起见,本 demo 直接在 IDE 中执行,得到如下输出: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为了方便起见,本 demo 直接在 IDE 中执行
then remove the timestamps of your logs.
------------------------------------------------- | ||
``` | ||
|
||
至此,SumActuator 已基本实现完毕,这只是一个最简单的例子,真正的业务场景还需要做一些额外的工作,比如在 Wallet-Cli 中提供对应的合约支持、定制合适的 chainbase 存储等。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wallet-cli
for the repo name, use wallet-cli
.
Code blocks, normal paragraphs, list items, headings should be joined with 1 empty line. |
8eee6f9
to
295d418
Compare
295d418
to
8aeab1a
Compare
all fixed, please review again, thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What does this PR do?
add docs: modularization intro & implement a Actuator