diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java index 2a54f3a..7e73bbc 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/BitsharesFaucetApiGenerator.java @@ -1,5 +1,7 @@ package cy.agorise.crystalwallet.apigenerator; +import com.google.gson.Gson; + /** * Created by henry on 15/10/2017. */ @@ -16,7 +18,30 @@ public abstract class BitsharesFaucetApiGenerator { * @return The bitshares id of the registered account, or null */ public static String registerBitsharesAccount(String accountName, String ownerKey, String activeKey, String memoKey){ + CreateAccountPetition petition = new CreateAccountPetition(); + Account account = new Account(); + account.name=accountName; + account.owner_key=ownerKey; + account.active_key=activeKey; + account.memo_key=memoKey; + petition.account=account; + Gson gson = new Gson(); + String jsonPetition = gson.toJson(petition); + System.out.println("create account petition :" + jsonPetition); + //TODO faucet function return null; } + + + private static class CreateAccountPetition{ + Account account; + } + + private static class Account{ + String name; + String owner_key; + String active_key; + String memo_key; + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 44f4c72..c77246c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -60,19 +60,23 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI GrapheneAccount grapheneAccount = (GrapheneAccount) account; - BitsharesFaucetApiGenerator.registerBitsharesAccount(grapheneAccount.getName(), + String btsIdAccount = BitsharesFaucetApiGenerator.registerBitsharesAccount(grapheneAccount.getName(), new Address(grapheneAccount.getOwnerKey(),"BTS").toString(), new Address(grapheneAccount.getActiveKey(),"BTS").toString(), new Address(grapheneAccount.getMemoKey(),"BTS").toString()); + if(btsIdAccount !=null) { + grapheneAccount.setAccountId(btsIdAccount); - CrystalDatabase db = CrystalDatabase.getAppDatabase(context); - db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount); - db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount)); + CrystalDatabase db = CrystalDatabase.getAppDatabase(context); + long idAccount = db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount)[0]; + grapheneAccount.setId(idAccount); + db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount)); - GrapheneApiGenerator.subscribeBitsharesAccount(grapheneAccount.getId(), grapheneAccount.getAccountId(), context); - this.refreshAccountTransactions(account.getId(), context); - GrapheneApiGenerator.getAccountBalance(grapheneAccount.getId(), grapheneAccount.getAccountId(), context); - return grapheneAccount; + GrapheneApiGenerator.subscribeBitsharesAccount(grapheneAccount.getId(), grapheneAccount.getAccountId(), context); + this.refreshAccountTransactions(grapheneAccount.getId(), context); + GrapheneApiGenerator.getAccountBalance(grapheneAccount.getId(), grapheneAccount.getAccountId(), context); + return grapheneAccount; + } } return null; }