WalletPocketHD extends BitWalletBase { @Override public BitAddress getReceiveAddress() { return currentAddress(RECEIVE_FUNDS); } WalletPocketHD(DeterministicKey rootKey, CoinType coinType,
                          @Nullable KeyCrypter keyCrypter, @Nullable KeyParameter key);   WalletPocketHD(SimpleHDKeyChain keys, CoinType coinType);   WalletPocketHD(String id, SimpleHDKeyChain keys, CoinType coinType); int getAccountIndex(); @Override boolean isEncryptable(); @Override boolean isEncrypted(); @Nullable @Override KeyCrypter getKeyCrypter(); @Override void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey); @Override void decrypt(KeyParameter aesKey); @Override String getPublicKeySerialized(); @Override boolean isWatchedScript(Script script); @Override boolean isPayToScriptHashMine(byte[] payToScriptHash); @Nullable @Override ECKey findKeyFromPubHash(byte[] pubkeyHash); @Nullable @Override ECKey findKeyFromPubKey(byte[] pubkey); @Nullable @Override RedeemData findRedeemDataFromScriptHash(byte[] bytes); @Override byte[] getPublicKey(); @Override BitAddress getChangeAddress(); @Override BitAddress getReceiveAddress(); BitAddress getRefundAddress(); @Override boolean hasUsedAddresses(); @Override boolean canCreateNewAddresses(); @Override BitAddress getReceiveAddress(boolean isManualAddressManagement); @Override BitAddress getRefundAddress(boolean isManualAddressManagement); @Nullable BitAddress getLastUsedAddress(SimpleHDKeyChain.KeyPurpose purpose); boolean canCreateFreshReceiveAddress(); BitAddress getFreshReceiveAddress(); BitAddress getFreshReceiveAddress(boolean isManualAddressManagement); int getNumberIssuedReceiveAddresses(); List<AbstractAddress> getIssuedReceiveAddresses(); Set<AbstractAddress> getUsedAddresses(); BitAddress getAddress(SimpleHDKeyChain.KeyPurpose purpose,
                              boolean isManualAddressManagement); @VisibleForTesting void maybeInitializeAllKeys(); @Override String getPublicKeyMnemonic(); @Override List<AbstractAddress> getActiveAddresses(); @Override void markAddressAsUsed(AbstractAddress address); void markAddressAsUsed(BitAddress address); @Override String toString();  }
@Test public void signMessage() throws AddressMalformedException, MissingPrivateKeyException, KeyIsEncryptedException { WalletPocketHD pocketHD = new WalletPocketHD(rootKey, BTC, null, null); pocketHD.getReceiveAddress(); SignedMessage signedMessage = new SignedMessage("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", MESSAGE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_BITCOIN_SIG, signedMessage.getSignature()); signedMessage = new SignedMessage("1KUDsEDqSBAgxubSEWszoA9xscNRRCmujM", MESSAGE_UNICODE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_BITCOIN_SIG_UNICODE, signedMessage.getSignature()); pocketHD = new WalletPocketHD(rootKey, NBT, null, null); pocketHD.getReceiveAddress(); signedMessage = new SignedMessage("BNvJUwg3BgkbQk5br1CxvHxdcDp1EC3saE", MESSAGE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_NUBITS_SIG, signedMessage.getSignature()); signedMessage = new SignedMessage("BNvJUwg3BgkbQk5br1CxvHxdcDp1EC3saE", MESSAGE_UNICODE); pocketHD.signMessage(signedMessage, null); assertEquals(EXPECTED_NUBITS_SIG_UNICODE, signedMessage.getSignature()); }
@Test public void testSendingAndBalances() throws Exception { DeterministicHierarchy h = new DeterministicHierarchy(masterKey); WalletPocketHD account1 = new WalletPocketHD(h.get(BTC.getBip44Path(0), false, true), BTC, null, null); WalletPocketHD account2 = new WalletPocketHD(h.get(BTC.getBip44Path(1), false, true), BTC, null, null); WalletPocketHD account3 = new WalletPocketHD(h.get(BTC.getBip44Path(2), false, true), BTC, null, null); Transaction tx = new Transaction(BTC); tx.addOutput(BTC.oneCoin().toCoin(), account1.getReceiveAddress()); tx.getConfidence().setSource(Source.SELF); account1.addNewTransactionIfNeeded(tx); assertEquals(BTC.value("1"), account1.getBalance()); assertEquals(BTC.value("0"), account2.getBalance()); assertEquals(BTC.value("0"), account3.getBalance()); Sha256Hash txId = send(BTC.value("0.05"), account1, account2); assertEquals(BTC.value("0.94"), account1.getBalance()); assertEquals(BTC.value("0"), account2.getBalance()); assertEquals(BTC.value("0"), account3.getBalance()); setTrustedTransaction(account1, txId); setTrustedTransaction(account2, txId); assertEquals(BTC.value("0.94"), account1.getBalance()); assertEquals(BTC.value("0.05"), account2.getBalance()); txId = send(BTC.value("0.07"), account1, account3); setTrustedTransaction(account1, txId); setTrustedTransaction(account3, txId); assertEquals(BTC.value("0.86"), account1.getBalance()); assertEquals(BTC.value("0.05"), account2.getBalance()); assertEquals(BTC.value("0.07"), account3.getBalance()); txId = send(BTC.value("0.03"), account2, account3); setTrustedTransaction(account2, txId); setTrustedTransaction(account3, txId); assertEquals(BTC.value("0.86"), account1.getBalance()); assertEquals(BTC.value("0.01"), account2.getBalance()); assertEquals(BTC.value("0.1"), account3.getBalance()); }
@Test public void serializeTransactionsBtc() throws Exception, Bip44KeyLookAheadExceededException { WalletPocketHD account = new WalletPocketHD(rootKey, BTC, null, null); Transaction tx = new Transaction(BTC); tx.addOutput(BTC.oneCoin().toCoin(), account.getReceiveAddress()); account.addNewTransactionIfNeeded(tx); testWalletSerializationForCoin(account); }
@Test public void serializeTransactionsNbt() throws Exception, Bip44KeyLookAheadExceededException { WalletPocketHD account = new WalletPocketHD(rootKey, NBT, null, null); Transaction tx = new Transaction(NBT); tx.addOutput(NBT.oneCoin().toCoin(), account.getReceiveAddress()); account.addNewTransactionIfNeeded(tx); testWalletSerializationForCoin(account); }