简介:

这是一个EOS的Android端实现,本库可以创建EOS的公私钥,查询余额,交易,投票,EOS的account绑定,离线签名等,几乎所有EOS的操作。

项目地址:https://github.com/wypeng2012/EOSForAndroid

欢迎star

support Android sdk >= 14

- 如何使用

  1. 先添加bip44forandroidlibrary的依赖

implementation ‘party.loveit:bip44forandroidlibrary:1.0.7’

  1. 生成 EOS相关的公钥私钥

code:

1
2
3
4
5
6
7
8
9
10
11
12
List<String> words = Bip44Utils.generateMnemonicWords(MainActivity.this);
Log.e("TAG", "words: " + words.toString());


BigInteger pri = Bip44Utils.getPathPrivateKey(words,"m/44'/194'/0'/0/0");
Log.e("TAG", "pri1: " + pri.toString(16));

String eospk = Ecc.seedPrivate(pri);
Log.e("TAG", "EOS privateKey: " + eospk);

String eospuk = Ecc.privateToPublic(eospk);
Log.e("TAG", "EOS publicKey: " + eospuk);

result:

1
2
3
4
2018-12-06 14:41:26.636 976-1101/? E/TAG: words: [cluster, page, museum, protect, bronze, leg, few, guide, sport, resource, luxury, magnet]
2018-12-06 14:41:27.107 976-1101/party.loveit.eosforandroid E/TAG: pri1: b021d8432d5c473b8b9be1b943de3effedff8cf2339bcb5c29b3031cca55316
2018-12-06 14:41:27.114 976-1101/party.loveit.eosforandroid E/TAG: EOS privateKey: 5Hu8mmzA4ud8sJFJy4ha5qqiDB36CVk5rBVc6bAEEHGuhDRfaF6
2018-12-06 14:41:27.187 976-1101/party.loveit.eosforandroid E/TAG: EOS publicKey: EOS6BpNg9SebtbeCFvkt1dZTQr4293gvdvpeRo9ZnDmHAZ3guNvGz
  1. 具体使用代码实例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
System.out.println("============= 自定义数据签名 ===============");
String sign = Ecc.sign(pk,"is京東價as看到可可是是是@#¥%……&*(CVBNM《d ");
System.out.println("sign :" + sign + " \n ");

System.out.println("============= 转账数据序列化 ===============");
String data = Ecc.parseTransferData("fromaccount", "toaccount", "10.0020 SYS", "测试123abcdo./,./!@##$%");
System.out.println("seriz data :" + data);
System.out.println("transfer eq eosjs seriz " + data.equals(eosjs_transfer_seriz)+" \n ");

System.out.println("============= 创建账户数据序列化 ===============");
String data1 = Ecc.parseAccountData("eosio", "espritbloc1.","EOS8eAX54cJtAngV2V22WZhRCW7e4sTAZz1mC5U22vp8mAGuFdMXx","EOS8FPooohZiiCAYXahWCQRxgXXzUbS2gNELAeYCUgGdDMbd2FHQT");
System.out.println("seriz data :" + data1);
System.out.println("account eq eosjs seriz " + data1.equals(eosjs_account_seriz));


System.out.println("\n******************* Ecc End *******************\n\n\n");

System.out.println("******************* Rpc Start *******************\n");

Rpc rpc = new Rpc("http://47.106.221.171:8888");

System.out.println("============= 转账 ===============");
try {
Transaction t1 = rpc.transfer("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3","espritblocke", "inita","initb", "12.2821 MSP", "");
System.out.println("转账成功 = " + t1.getTransactionId()+" \n ");
}catch(Exception ex) {
ex.printStackTrace();
}

System.out.println("============= 创建账户并且抵押 ===============");
try {
Transaction t2 = rpc.createAccount("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3","eosio","ccccc..bbbbb", "EOS8eAX54cJtAngV2V22WZhRCW7e4sTAZz1mC5U22vp8mAGuFdMXx","EOS8eAX54cJtAngV2V22WZhRCW7e4sTAZz1mC5U22vp8mAGuFdMXx", 8192l, "0.01 SYS","0.01 SYS", 0l);
System.out.println("创建成功 = " + t2.getTransactionId()+" \n ");
}catch(Exception ex) {
ex.printStackTrace();
}
System.out.println("============= 创建账户不抵押 ===============");
try {
Transaction t3 = rpc.createAccount("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3","eosio","bbbb..54321", "EOS8eAX54cJtAngV2V22WZhRCW7e4sTAZz1mC5U22vp8mAGuFdMXx","EOS8eAX54cJtAngV2V22WZhRCW7e4sTAZz1mC5U22vp8mAGuFdMXx", 8192l);
System.out.println("创建成功 = " + t3.getTransactionId()+" \n ");
}catch(Exception ex) {
ex.printStackTrace();
}

System.out.println("============= 代理投票 ===============");
try {
List<String> produces = new ArrayList<>();
produces.add("pppppeeeeooo");
produces.add("mdddssssddds");
produces.add("mdjddjddddds");
rpc.voteproducer("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", "epskdkdsddss","iuewjdkslsdc",produces);
} catch (Exception e) {
e.printStackTrace();
}

System.out.println("============= 关闭余额为0的token ===============");
try {
rpc.close("5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", "合约账户", "关闭账户", "0.0000 IPOS");
}catch(ApiException e) {
e.printStackTrace();
}catch(Exception ex) {
ex.printStackTrace();
}
System.out.println("\n******************* Rpc End *******************");
  1. 离线签名
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public static void testOfflineCreate() {
Rpc rpc = new Rpc("http://47.106.221.171:8888");
// 获取离线签名参数
SignParam params = rpc.getOfflineSignParams(60l);
// 离线签名
OfflineSign sign = new OfflineSign();
// 交易信息
String content = "";
try {
content = sign.createAccount(params, "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", "eeeeeeeeeeee",
"555555555551", "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", 8000l);
System.out.println(content);
} catch (Exception e) {
e.printStackTrace();
}
// 广播交易
try {
Transaction tx = rpc.pushTransaction(content);
System.out.println(tx.getTransactionId());
} catch (ApiException ex) {
System.out.println(ex.getError().getCode());
} catch (Exception e) {
e.printStackTrace();
}
}

public static void testOfflineTransfer() {
Rpc rpc = new Rpc("http://47.106.221.171:8888");
// 获取离线签名参数
SignParam params = rpc.getOfflineSignParams(60l);
// 离线签名
OfflineSign sign = new OfflineSign();
// 交易信息
String content = "";
try {
content = sign.transfer(params, "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", "eosio.token",
"eeeeeeeeeeee", "555555555551", "372.0993 EOS", "test");
System.out.println(content);
} catch (Exception e) {
e.printStackTrace();
}
// 广播交易
try {
Transaction tx = rpc.pushTransaction(content);
System.out.println(tx.getTransactionId());
} catch (ApiException ex) {
System.out.println(ex.getError().getCode());
} catch (Exception e) {
e.printStackTrace();
}
}

- 远程依赖

  1. Maven
1
2
3
4
5
6
<dependency>
<groupId>party.loveit</groupId>
<artifactId>eosforandroidlibrary</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
  1. Gradle
1
2
3
4
5
compile 'party.loveit:eosforandroidlibrary:1.0.0'

or

implementation 'party.loveit:eosforandroidlibrary:1.0.0'
  1. Ivy
1
2
3
<dependency org='party.loveit' name='eosforandroidlibrary' rev='1.0.0'>
<artifact name='eosforandroidlibrary' ext='pom' ></artifact>
</dependency>