public static Protos.WalletPocket toProtobuf(NxtFamilyWallet account) { Protos.WalletPocket.Builder walletBuilder = Protos.WalletPocket.newBuilder(); walletBuilder.setNetworkIdentifier(account.getCoinType().getId()); if (account.getDescription() != null) { walletBuilder.setDescription(account.getDescription()); } if (account.getId() != null) { walletBuilder.setId(account.getId()); } // for (WalletTransaction wtx : account.getWalletTransactions()) { // Protos.Transaction txProto = makeTxProto(wtx); // walletBuilder.addTransaction(txProto); // } walletBuilder.addAllKey(account.serializeKeychainToProtobuf()); // Populate the lastSeenBlockHash field. // if (account.getLastBlockSeenHash() != null) { // walletBuilder.setLastSeenBlockHash(hashToByteString(account.getLastBlockSeenHash())); // walletBuilder.setLastSeenBlockHeight(account.getLastBlockSeenHeight()); // } // if (account.getLastBlockSeenTimeSecs() > 0) { // walletBuilder.setLastSeenBlockTimeSecs(account.getLastBlockSeenTimeSecs()); // } return walletBuilder.build(); }
@Test public void testSerializeKeychainToProtobuf() throws UnreadableWalletException { List<Protos.Key> keys = nxtAccount.serializeKeychainToProtobuf(); NxtFamilyKey newKey = NxtFamilyKey.fromProtobuf(keys); NxtFamilyWallet newWallet = new NxtFamilyWallet(newKey, NXT); assertEquals(Convert.toHexString(nxtAccount.getPublicKey()), Convert.toHexString(newWallet.getPublicKey())); assertEquals(nxtAccount.getPublicKeyMnemonic(), newWallet.getPublicKeyMnemonic()); assertEquals(nxtAccount.getId(), newWallet.getId()); }
@Test public void testEncryptedNxtFamilyKey() throws UnreadableWalletException { nxtAccount.encrypt(crypter, aesKey); List<Protos.Key> keys = nxtAccount.serializeKeychainToProtobuf(); NxtFamilyKey newKey = NxtFamilyKey.fromProtobuf(keys, crypter); NxtFamilyWallet newWallet = new NxtFamilyWallet(newKey, NXT); assertEquals(Convert.toHexString(nxtAccount.getPublicKey()), Convert.toHexString(newWallet.getPublicKey())); assertEquals(nxtAccount.getPublicKeyMnemonic(), newWallet.getPublicKeyMnemonic()); assertEquals(nxtAccount.getId(), newWallet.getId()); } }