@Override public SendRequest getEmptyWalletRequest(AbstractAddress destination) throws WalletAccountException { checkAddress(destination); return NxtSendRequest.emptyWallet(this, (NxtAddress) destination); }
@Override public SendRequest getSendToRequest(AbstractAddress destination, Value amount) throws WalletAccountException { checkAddress(destination); return NxtSendRequest.to(this, (NxtAddress) destination, amount); }
public void completeTransaction(NxtSendRequest request) throws WalletAccountException { checkArgument(!request.isCompleted(), "Given SendRequest has already been completed."); if (request.type.getTransactionVersion() > 0) { request.nxtTxBuilder.ecBlockHeight(lastEcBlockHeight); request.nxtTxBuilder.ecBlockId(lastEcBlockId); } // TODO check if the destination public key was announced and if so, remove it from the tx: // request.nxtTxBuilder.publicKeyAnnouncement(null); try { request.tx = new NxtTransaction(type, request.nxtTxBuilder.build()); request.setCompleted(true); } catch (NxtException.NotValidException e) { throw new WalletAccount.WalletAccountException(e); } if (request.signTransaction) { signTransaction(request); } }
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; }
public void signTransaction(NxtSendRequest request) { checkArgument(request.isCompleted(), "Send request is not completed"); checkArgument(request.tx != null, "No transaction found in send request"); Transaction tx = request.tx.getRawTransaction(); byte[] privateKey; if (rootKey.isEncrypted()) { checkArgument(request.aesKey != null, "Wallet is encrypted but no decryption key provided"); privateKey = rootKey.toDecrypted(request.aesKey).getPrivateKey(); } else { privateKey = rootKey.getPrivateKey(); } tx.sign(privateKey); Arrays.fill(privateKey, (byte) 0); // clear private key }
/** * {@link #sendCoinsOffline(NxtAddress, Value)} */ public NxtSendRequest sendCoinsOffline(NxtAddress address, Value amount, @Nullable KeyParameter aesKey) throws WalletAccountException { NxtSendRequest request; try { request = NxtSendRequest.to(this, address, amount); } catch (Exception e) { throw new WalletAccountException(e); } request.aesKey = aesKey; return request; }
public static NxtSendRequest emptyWallet(NxtFamilyWallet from, NxtAddress destination) { checkNotNull(destination.getType(), "Address is for an unknown network"); checkState(destination.getType().getFeePolicy() == FeePolicy.FLAT_FEE, "Only flat fee is supported"); Value allFundsMinusFee = from.getBalance().subtract(destination.getType().getFeeValue()); return to(from, destination, allFundsMinusFee); }