- 工作量证明(PoW):通过
consensus/pow.go实现的挖矿算法,调整难度值控制区块生成速度 - UTXO模型:在
core/utxo.go中实现未花费交易输出模型,确保交易可验证且防双花 - 椭圆曲线加密(ECDSA):
crypto/wallet.go使用 secp256k1 曲线生成密钥对,保障资产安全 - 默克尔树:
core/block.go中实现交易哈希树,快速验证区块完整性
// 区块结构 (core/block.go)
type Block struct {
Timestamp int64
Transactions []*Transaction
PrevHash []byte
Hash []byte
Nonce int
Height int
}
// 交易结构 (core/transaction.go)
type Transaction struct {
ID []byte
Inputs []TxInput
Outputs []TxOutput
}# 1. 克隆仓库
git clone https://github.com/your-repo/aztecs.git
cd aztecs
# 2. 创建新钱包(获取矿工地址)
go run main.go createwallet
# 输出示例:新钱包地址: 1ABC... (复制这个地址)
# 3. 启动节点
go run main.go startnode \
--port=8080 \
"--miner-address=1ABC..." # 粘贴上一步复制的地址cd frontend
npm install # 安装依赖
REACT_APP_API_URL=http://localhost:8080 npm start# 终端1:启动后端
$ cd aztecs
$ go run main.go createwallet
新钱包地址: 1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX
$ go run main.go startnode \
--port=8080 \
"--miner-address=1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX"
# 终端2:启动前端
$ cd aztecs/frontend
$ REACT_APP_API_URL=http://localhost:8080 npm start通过前端界面或API创建:
# API方式
curl -X POST http://localhost:8080/wallet/new
# 返回:{"address":"1ABC...","private_key":"..."}- 在前端 "Transaction Sender" 界面
- 输入接收方地址和金额
- 使用私钥签名交易
- 广播到网络
- 区块浏览器:
http://localhost:3000/blocks - API端点:
GET /blocks
节点自动执行PoW挖矿,可通过API手动触发:
curl -X POST http://localhost:8080/mine| 端点 | 方法 | 功能 |
|---|---|---|
/wallet/new |
POST | 创建新钱包 |
/transaction |
POST | 创建交易 |
/blocks |
GET | 获取区块链 |
/utxo |
GET | 查询UTXO |
/balance/:address |
GET | 查询余额 |
/mine |
POST | 手动挖矿 |
aztecs/
├── api/ # REST API
├── consensus/ # PoW共识算法
├── core/ # 区块链核心
├── crypto/ # 加密模块
├── frontend/ # React前端
└── storage/ # LevelDB存储
欢迎提交PR,请确保:
- 包含单元测试(Go测试或Jest)
- 遵循Go代码规范
gofmt - 更新相关文档
许可证: MIT