/** Returns a list of key protobufs obtained by merging the chains. */ public List<Protos.Key> serializeToProtobuf() { List<Protos.Key> result; if (basic != null) result = basic.serializeToProtobuf(); else result = Lists.newArrayList(); for (DeterministicKeyChain chain : chains) { List<Protos.Key> protos = chain.serializeToProtobuf(); result.addAll(protos); } return result; }
/** Returns a list of key protobufs obtained by merging the chains. */ public List<Protos.Key> serializeToProtobuf() { List<Protos.Key> result; if (basic != null) result = basic.serializeToProtobuf(); else result = Lists.newArrayList(); for (DeterministicKeyChain chain : chains) { List<Protos.Key> protos = chain.serializeToProtobuf(); result.addAll(protos); } return result; }
/** Returns a list of key protobufs obtained by merging the chains. */ public List<Protos.Key> serializeToProtobuf() { List<Protos.Key> result; if (basic != null) result = basic.serializeToProtobuf(); else result = Lists.newArrayList(); for (DeterministicKeyChain chain : chains) { List<Protos.Key> protos = chain.serializeToProtobuf(); result.addAll(protos); } return result; }
/** Returns a list of key protobufs obtained by merging the chains. */ public List<Protos.Key> serializeToProtobuf() { List<Protos.Key> result; if (basic != null) result = basic.serializeToProtobuf(); else result = Lists.newArrayList(); for (DeterministicKeyChain chain : chains) { List<Protos.Key> protos = chain.serializeToProtobuf(); result.addAll(protos); } return result; }
List<Protos.Key> serialized = encChain.serializeToProtobuf(); List<Protos.Key> doubled = Lists.newArrayListWithExpectedSize(serialized.size() * 2); doubled.addAll(serialized);
DeterministicKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); DeterministicKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE); List<Protos.Key> keys = chain.serializeToProtobuf(); assertEquals(EXPECTED_SERIALIZATION, protoToString(chain.serializeToProtobuf())); assertEquals(key1, chain.findKeyFromPubHash(key1.getPubKeyHash())); assertEquals(key2, chain.findKeyFromPubHash(key2.getPubKeyHash()));
@Test public void serializeAccountOne() throws Exception { long secs = 1389353062L; DeterministicKeyChain chain1 = new AccountOneChain(ENTROPY, "", secs); ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); final Address address = Address.fromBase58(UnitTestParams.get(), "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X"); assertEquals(address, key1.toAddress(UnitTestParams.get())); DeterministicKey watching = chain1.getWatchingKey(); List<Protos.Key> keys = chain1.serializeToProtobuf(); KeyChainFactory factory = new KeyChainFactory() { @Override public DeterministicKeyChain makeKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicSeed seed, KeyCrypter crypter, boolean isMarried) { return new AccountOneChain(crypter, seed); } @Override public DeterministicKeyChain makeWatchingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey, boolean isFollowingKey, boolean isMarried) { throw new UnsupportedOperationException(); } }; chain1 = DeterministicKeyChain.fromProtobuf(keys, null, factory).get(0); ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", key2.toAddress(UnitTestParams.get()).toString()); assertEquals(key1, chain1.findKeyFromPubHash(address.getHash160())); assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey())); key1.sign(Sha256Hash.ZERO_HASH); ECKey key3 = chain1.getKey(KeyChain.KeyPurpose.CHANGE); assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", key3.toAddress(UnitTestParams.get()).toString()); key3.sign(Sha256Hash.ZERO_HASH); assertEquals(watching, chain1.getWatchingKey()); }
List<Protos.Key> serialization = chain.serializeToProtobuf(); checkSerialization(serialization, "watching-wallet-serialization.txt"); chain = DeterministicKeyChain.fromProtobuf(serialization, null).get(0);