calculate-mining-difficulty
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCalculate Mining Difficulty
计算挖矿难度
Calculate and analyze BSV mining difficulty from targets, bits, and network data.
计算并分析基于目标值、压缩位(bits)和网络数据的BSV挖矿难度。
When to Use
使用场景
- Get current network difficulty from WhatsOnChain
- Convert between target and difficulty
- Decode compact bits representation
- Understand expected hash calculations for mining
- 从WhatsOnChain获取当前网络难度
- 在目标值与难度值之间进行转换
- 解码压缩位表示形式
- 了解挖矿所需的预期哈希计算量
Usage
使用方法
bash
undefinedbash
undefinedGet current network difficulty
获取当前网络难度
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --current
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --current
Calculate from compact bits (e.g., genesis block)
通过压缩位计算(例如创世区块)
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --bits 0x1d00ffff
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --bits 0x1d00ffff
Calculate from target hex (64 characters)
通过目标值十六进制字符串计算(64个字符)
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --target 00000000ffff0000000000000000000000000000000000000000000000000000
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --target 00000000ffff0000000000000000000000000000000000000000000000000000
JSON output for scripting
以JSON格式输出用于脚本开发
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --bits 0x1d00ffff --json
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --bits 0x1d00ffff --json
Show help
显示帮助信息
bun run skills/calculate-mining-difficulty/scripts/difficulty.ts --help
undefinedbun run skills/calculate-mining-difficulty/scripts/difficulty.ts --help
undefinedOutput
输出示例
Default output:
Mining Difficulty Analysis
==========================
Difficulty: 1
Target: 0x00000000ffff0000000000000000000000000000000000000000000000000000
Bits: 0x1d00ffff
Expected hashes: 4.29e+9JSON output (--json):
json
{
"difficulty": 1,
"target": "00000000ffff0000000000000000000000000000000000000000000000000000",
"bits": "1d00ffff",
"expectedHashes": "4.29e+9"
}默认输出:
挖矿难度分析
==========================
难度值: 1
目标值: 0x00000000ffff0000000000000000000000000000000000000000000000000000
压缩位: 0x1d00ffff
预期哈希量: 4.29e+9JSON格式输出(--json参数):
json
{
"difficulty": 1,
"target": "00000000ffff00000000000000000000000000000000000000000000000000000",
"bits": "1d00ffff",
"expectedHashes": "4.29e+9"
}Difficulty Math
难度计算原理
The script uses the standard Bitcoin difficulty formula:
- Max target: (difficulty 1)
0x00000000FFFF0000000000000000000000000000000000000000000000000000 - Difficulty:
max_target / current_target - Compact bits format: First byte = exponent, next 3 bytes = mantissa
target = mantissa * 2^(8*(exponent-3))
- Expected hashes:
difficulty * 2^32
该脚本使用标准的比特币难度计算公式:
- 最大目标值:(难度值为1)
0x00000000FFFF0000000000000000000000000000000000000000000000000000 - 难度值:
最大目标值 / 当前目标值 - 压缩位格式:第一个字节=指数,后3个字节=尾数
目标值 = 尾数 * 2^(8*(指数-3))
- 预期哈希量:
难度值 * 2^32
API Integration
API集成
Uses WhatsOnChain API for current network data:
- Chain info endpoint:
GET https://api.whatsonchain.com/v1/bsv/main/chain/info
使用WhatsOnChain API获取当前网络数据:
- 链信息端点:
GET https://api.whatsonchain.com/v1/bsv/main/chain/info
Status
状态
Complete - All functionality implemented and tested.
已完成 - 所有功能均已实现并通过测试。