一個EOS的Android端實現庫
阿新 • • 發佈:2018-12-13
簡介:
這是一個EOS的Android端實現,本庫可以建立EOS的公私鑰,查詢餘額,交易,投票,EOS的account繫結,離線簽名等,幾乎所有EOS的操作。
專案地址:
https://github.com/wypeng2012/EOSForAndroid
歡迎star
support Android sdk >= 14
- 如何使用
- 先新增bip44forandroidlibrary的依賴
implementation ‘party.loveit:bip44forandroidlibrary:1.0.7’
- 生成 EOS相關的公鑰私鑰
code:
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:
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
- 具體使用程式碼例項
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./,./[email protected]##$%");
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 *******************");
- 離線簽名
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();
}
}
- 遠端依賴
- Maven
<dependency>
<groupId>party.loveit</groupId>
<artifactId>eosforandroidlibrary</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
- Gradle
compile 'party.loveit:eosforandroidlibrary:1.0.0'
or
implementation 'party.loveit:eosforandroidlibrary:1.0.0'
- Ivy
<dependency org='party.loveit' name='eosforandroidlibrary' rev='1.0.0'>
<artifact name='eosforandroidlibrary' ext='pom' ></artifact>
</dependency>