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 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(); }