Skip to content
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

Merged
merged 5 commits into from
Jan 17, 2020

Conversation

tomatoishealthy
Copy link
Contributor

What does this PR do?

add docs: modularization intro & implement a Actuator

@@ -0,0 +1,301 @@
# 自定义 SumActuator

actuator 模块抽象出4个方法并定义在 Actuator 接口中:
Copy link
Contributor

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: 负责交易执行的逻辑,如状态修改、流程跳转、逻辑判断...
Copy link
Contributor

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()`

Copy link
Contributor

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 的逻辑是将两个数值相加求和:
Copy link
Contributor

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`

Copy link
Contributor

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;
}
```
Copy link
Contributor

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 文件中:
Copy link
Contributor

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 不是本文讨论内容,相关文章后续发布,敬请期待*
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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 中执行,得到如下输出:
Copy link
Contributor

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 存储等。
Copy link
Contributor

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.

@andelf
Copy link
Contributor

andelf commented Jan 16, 2020

Code blocks, normal paragraphs, list items, headings should be joined with 1 empty line.

@tomatoishealthy
Copy link
Contributor Author

all fixed, please review again, thanks

@jiangyy0824 jiangyy0824 self-assigned this Jan 17, 2020
Copy link
Contributor

@andelf andelf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jiangyy0824 jiangyy0824 merged commit 46f1d57 into tronprotocol:develop Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants