package nxt.http;

import nxt.Account;
import nxt.Attachment;
import nxt.NxtException;
import org.json.simple.JSONStreamAware;

import javax.servlet.http.HttpServletRequest;

public final class SendMessage extends CreateTransaction {

    static final SendMessage instance = new SendMessage();

    private SendMessage() {
        super(new APITag[] {APITag.MESSAGES, APITag.CREATE_TRANSACTION}, "recipient");
    }

    @Override
    JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
        long recipient = ParameterParser.getRecipientId(req);
        Account account = ParameterParser.getSenderAccount(req);
        return createTransaction(req, account, recipient, 0, Attachment.ARBITRARY_MESSAGE);
    }

}

@@ -80,16 +80,41 @@
 eption;%0A
+import nxt.util.Convert;%0A
 import o
@@ -530,16 +530,100 @@
 ption %7B%0A
+        String recipientValue = Convert.emptyToNull(req.getParameter(%22recipient%22));%0A
         
@@ -636,18 +636,45 @@
 ecipient
+Id
  =
+ recipientValue != null ?
  Paramet
@@ -697,24 +697,28 @@
 pientId(req)
+ : 0
 ;%0A        Ac
@@ -772,16 +772,16 @@
 t(req);%0A
-
         
@@ -828,16 +828,18 @@
 ecipient
+Id
 , 0, Att

allow messages with no recipient