@Override public String getPublicKeySerialized() { return Convert.toHexString(getPublicKey()); }
/** * {@link #sendCoinsOffline(NxtAddress, Value)} */ public NxtSendRequest sendCoinsOffline(NxtAddress address, Value amount, @Nullable String password) throws WalletAccountException { KeyParameter key = null; if (password != null) { checkState(isEncrypted()); key = checkNotNull(getKeyCrypter()).deriveKey(password); } return sendCoinsOffline(address, amount, key); }
@Override public void addEventListener(WalletAccountEventListener listener) { addEventListener(listener, Threading.USER_THREAD); }
@Override public void completeTransaction(SendRequest request) throws WalletAccountException { checkSendRequest(request); completeTransaction((NxtSendRequest) request); }
@Override public void signTransaction(SendRequest request) throws WalletAccountException { checkSendRequest(request); signTransaction((NxtSendRequest) request); }
@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()); } }
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 serializeUnencryptedNormal() throws Exception { List<Protos.Key> keys = nxtAccount.serializeKeychainToProtobuf(); NxtFamilyKey nxtKey = NxtFamilyKey.fromProtobuf(keys); NxtFamilyWallet newWallet; newWallet = new NxtFamilyWallet(nxtKey, NXT); }
@Test public void testHDAccountNxt() throws MnemonicException { byte[] privateKey = nxtAccount.rootKey.getPrivateKey(); byte[] publicKey = nxtAccount.getPublicKey(); assertArrayEquals(nxtPrivateKey, privateKey); assertEquals(nxtRsAddress, nxtAccount.getPublicKeyMnemonic()); assertArrayEquals(nxtPublicKey, publicKey); NxtAddress address = (NxtAddress) nxtAccount.getReceiveAddress(); assertEquals(nxtRsAddress, address.toString()); assertEquals(nxtAccountId, address.getAccountId()); }
@Test public void testNxtTransaction() throws WalletAccount.WalletAccountException, NxtException.ValidationException { NxtAddress destination = (NxtAddress) otherAccount.getReceiveAddress(); Value amount = NXT.value("1"); NxtSendRequest req = nxtAccount.sendCoinsOffline(destination, amount); nxtAccount.completeAndSignTx(req); Transaction nxtTx = req.nxtTxBuilder.build(); // nxtTx.sign(nxtSecret); byte[] txBytes = req.nxtTxBuilder.build().getBytes(); req.tx = new NxtTransaction(NXT, req.nxtTxBuilder.build()); Transaction parsedTx = TransactionImpl.parseTransaction(txBytes); assertEquals(Attachment.ORDINARY_PAYMENT, parsedTx.getAttachment()); assertEquals(NxtFamily.DEFAULT_DEADLINE, parsedTx.getDeadline()); assertEquals((req.tx.getRawTransaction()).getTimestamp(), parsedTx.getTimestamp()); assertEquals(nxtAccountId, parsedTx.getSenderId()); assertArrayEquals(nxtPublicKey, parsedTx.getSenderPublicKey()); assertEquals(amount.value, parsedTx.getAmountNQT()); assertEquals(req.fee.value, parsedTx.getFeeNQT()); assertEquals(destination.getAccountId(), parsedTx.getRecipientId()); // System.out.println(Convert.toHexString(nxtTx.getBytes())); // TODO check signature }
pocket = new NxtFamilyWallet(walletProto.getId(), rootKey, coinType); } else { pocket = new NxtFamilyWallet(rootKey, coinType); pocket.setDescription(walletProto.getDescription());
public static NxtSendRequest to(NxtFamilyWallet from, NxtAddress destination, Value amount) { checkNotNull(destination.getType(), "Address is for an unknown network"); checkState(from.getCoinType() == destination.getType(), "Incompatible destination address coin type"); checkState(TypeUtils.is(destination.getType(), amount.type), "Incompatible sending amount type"); checkTypeCompatibility(destination.getType()); NxtSendRequest req = new NxtSendRequest(destination.getType()); byte version = (byte) 1; int timestamp; if (req.type instanceof NxtMain) { timestamp = Convert.toNxtEpochTime(System.currentTimeMillis()); } else if (req.type instanceof BurstMain) { timestamp = Convert.toBurstEpochTime(System.currentTimeMillis()); } else { throw new RuntimeException("Unexpected NXT family type: " + req.type.toString()); } TransactionImpl.BuilderImpl builder = new TransactionImpl.BuilderImpl(version, from.getPublicKey(), amount.value, req.fee.value, timestamp, NxtFamily.DEFAULT_DEADLINE, Attachment.ORDINARY_PAYMENT); builder.recipientId(destination.getAccountId()); // TODO extra check, query the server if the public key announcement is actually needed if (destination.getPublicKey() != null) { Appendix.PublicKeyAnnouncement publicKeyAnnouncement = new Appendix.PublicKeyAnnouncement(destination.getPublicKey()); builder.publicKeyAnnouncement(publicKeyAnnouncement); } req.nxtTxBuilder = builder; return req; }
newPocket = new WalletPocketHD(rootKey, coinType, getKeyCrypter(), key); } else if (coinType instanceof NxtFamily) { newPocket = new NxtFamilyWallet(rootKey, coinType, getKeyCrypter(), key); } else { throw new UnsupportedCoinTypeException(coinType);
/** * Sends coins to the given address but does not broadcast the resulting pending transaction. */ public NxtSendRequest sendCoinsOffline(NxtAddress address, Value amount) throws WalletAccountException { return sendCoinsOffline(address, amount, (KeyParameter) null); }
@Override public void onTransactionBroadcast(NxtTransaction tx) { lock.lock(); try { log.info("Transaction sent {}", tx); //FIXME, when enabled it breaks the transactions connections and we get an incorrect coin balance addNewTransactionIfNeeded(tx); } finally { lock.unlock(); } //queueOnTransactionBroadcastSuccess(tx); }
@Override public SendRequest getEmptyWalletRequest(AbstractAddress destination) throws WalletAccountException { checkAddress(destination); return NxtSendRequest.emptyWallet(this, (NxtAddress) destination); }
@Override public boolean broadcastTxSync(AbstractTransaction tx) throws TransactionBroadcastException { if (tx instanceof NxtTransaction) { return broadcastNxtTxSync((NxtTransaction) tx); } else { throw new TransactionBroadcastException("Unsupported transaction class: " + tx.getClass().getName() + ", need: " + NxtTransaction.class.getName()); } }
@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()); }
@Before public void setup() throws MnemonicException, UnreadableWalletException { DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0); DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes()); hierarchy = new DeterministicHierarchy(masterKey); wallet = new Wallet(recoveryPhrase); nxtAccount = (NxtFamilyWallet)wallet.createAccount(NXT, null); otherAccount = new NxtFamilyWallet(hierarchy.get(NXT.getBip44Path(1), false, true), NXT); }
@Override public void onTransactionUpdate(NxtTransaction tx) { if (log.isInfoEnabled()) log.info("Got a new transaction {}", tx.getHashAsString()); lock.lock(); try { addNewTransactionIfNeeded(tx); } finally { lock.unlock(); } }