> For the complete documentation index, see [llms.txt](https://yeasy.gitbook.io/blockchain_guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yeasy.gitbook.io/blockchain_guide/11_app_dev/chaincode_example05.md).

# 社区能源共享

[chaincode\_example05.go](https://github.com/yeasy/blockchain_guide/blob/master/11_app_dev/chaincode_example05.go) 演示社区能源微网中的家庭账户和电力交易。

## 数据结构

* `Home`：家庭地址、可售电量、余额、状态和模拟密钥；
* `EnergyTransaction`：买方、卖方、交易电量、金额和时间。

## 主要交易函数

* `CreateUser`：创建家庭账户；
* `BuyByAddress`：买方向卖方购买指定电量；
* `ChangeStatus`：账户所有者修改是否可交易；
* `GetHomeByAddress`、`GetHomes`、`GetTransactionByID`、`GetTransactions`：读取状态。

交易逻辑会检查买方签名、卖方交易状态、卖方电量和买方余额。交易时间使用 Fabric 交易时间戳。

> 与 [学历认证示例](/blockchain_guide/11_app_dev/chaincode_example04.md) 一样，本例使用派生字符串模拟签名验证，仅保留业务流程骨架。真实系统中应由客户端身份、证书和密码学库完成签名与验签。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://yeasy.gitbook.io/blockchain_guide/11_app_dev/chaincode_example05.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
