forked from DeepCoin/nxt-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNxt$Transaction.java
More file actions
740 lines (671 loc) · 25.9 KB
/
Copy pathNxt$Transaction.java
File metadata and controls
740 lines (671 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
class Nxt$Transaction
implements Comparable<Transaction>, Serializable
{
static final long serialVersionUID = 0L;
static final byte TYPE_PAYMENT = 0;
static final byte TYPE_MESSAGING = 1;
static final byte TYPE_COLORED_COINS = 2;
static final byte SUBTYPE_PAYMENT_ORDINARY_PAYMENT = 0;
static final byte SUBTYPE_MESSAGING_ARBITRARY_MESSAGE = 0;
static final byte SUBTYPE_MESSAGING_ALIAS_ASSIGNMENT = 1;
static final byte SUBTYPE_COLORED_COINS_ASSET_ISSUANCE = 0;
static final byte SUBTYPE_COLORED_COINS_ASSET_TRANSFER = 1;
static final byte SUBTYPE_COLORED_COINS_ASK_ORDER_PLACEMENT = 2;
static final byte SUBTYPE_COLORED_COINS_BID_ORDER_PLACEMENT = 3;
static final byte SUBTYPE_COLORED_COINS_ASK_ORDER_CANCELLATION = 4;
static final byte SUBTYPE_COLORED_COINS_BID_ORDER_CANCELLATION = 5;
static final int ASSET_ISSUANCE_FEE = 1000;
final byte type;
final byte subtype;
int timestamp;
final short deadline;
final byte[] senderPublicKey;
final long recipient;
final int amount;
final int fee;
final long referencedTransaction;
byte[] signature;
Nxt.Transaction.Attachment attachment;
int index;
volatile long block;
int height;
Nxt$Transaction(byte type, byte subtype, int timestamp, short deadline, byte[] senderPublicKey, long recipient, int amount, int fee, long referencedTransaction, byte[] signature)
{
this.type = type;
this.subtype = subtype;
this.timestamp = timestamp;
this.deadline = deadline;
this.senderPublicKey = senderPublicKey;
this.recipient = recipient;
this.amount = amount;
this.fee = fee;
this.referencedTransaction = referencedTransaction;
this.signature = signature;
this.height = 2147483647;
}
public int compareTo(Transaction o)
{
if (this.height < o.height) {
return -1;
}
if (this.height > o.height) {
return 1;
}
if (this.fee * o.getSize() > o.fee * getSize()) {
return -1;
}
if (this.fee * o.getSize() < o.fee * getSize()) {
return 1;
}
if (this.timestamp < o.timestamp) {
return -1;
}
if (this.timestamp > o.timestamp) {
return 1;
}
if (this.index < o.index) {
return -1;
}
if (this.index > o.index) {
return 1;
}
return 0;
}
public static final Comparator<Transaction> timestampComparator = new Nxt.Transaction.1();
private static final int TRANSACTION_BYTES_LENGTH = 128;
volatile transient long id;
int getSize()
{
return 128 + (this.attachment == null ? 0 : this.attachment.getSize());
}
byte[] getBytes()
{
ByteBuffer buffer = ByteBuffer.allocate(getSize());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put(this.type);
buffer.put(this.subtype);
buffer.putInt(this.timestamp);
buffer.putShort(this.deadline);
buffer.put(this.senderPublicKey);
buffer.putLong(this.recipient);
buffer.putInt(this.amount);
buffer.putInt(this.fee);
buffer.putLong(this.referencedTransaction);
buffer.put(this.signature);
if (this.attachment != null) {
buffer.put(this.attachment.getBytes());
}
return buffer.array();
}
volatile transient String stringId = null;
volatile transient long senderAccountId;
long getId()
{
calculateIds();
return this.id;
}
String getStringId()
{
calculateIds();
return this.stringId;
}
long getSenderAccountId()
{
calculateIds();
return this.senderAccountId;
}
private void calculateIds()
{
if (this.stringId != null) {
return;
}
byte[] hash = Nxt.getMessageDigest("SHA-256").digest(getBytes());
BigInteger bigInteger = new BigInteger(1, new byte[] { hash[7], hash[6], hash[5], hash[4], hash[3], hash[2], hash[1], hash[0] });
this.id = bigInteger.longValue();
this.stringId = bigInteger.toString();
this.senderAccountId = Nxt.Account.getId(this.senderPublicKey);
}
JSONObject getJSONObject()
{
JSONObject transaction = new JSONObject();
transaction.put("type", Byte.valueOf(this.type));
transaction.put("subtype", Byte.valueOf(this.subtype));
transaction.put("timestamp", Integer.valueOf(this.timestamp));
transaction.put("deadline", Short.valueOf(this.deadline));
transaction.put("senderPublicKey", Nxt.convert(this.senderPublicKey));
transaction.put("recipient", Nxt.convert(this.recipient));
transaction.put("amount", Integer.valueOf(this.amount));
transaction.put("fee", Integer.valueOf(this.fee));
transaction.put("referencedTransaction", Nxt.convert(this.referencedTransaction));
transaction.put("signature", Nxt.convert(this.signature));
if (this.attachment != null) {
transaction.put("attachment", this.attachment.getJSONObject());
}
return transaction;
}
long getRecipientDeltaBalance()
{
return this.amount * 100L + (this.attachment == null ? 0L : this.attachment.getRecipientDeltaBalance());
}
long getSenderDeltaBalance()
{
return -(this.amount + this.fee) * 100L + (this.attachment == null ? 0L : this.attachment.getSenderDeltaBalance());
}
static Transaction getTransaction(ByteBuffer buffer)
{
byte type = buffer.get();
byte subtype = buffer.get();
int timestamp = buffer.getInt();
short deadline = buffer.getShort();
byte[] senderPublicKey = new byte[32];
buffer.get(senderPublicKey);
long recipient = buffer.getLong();
int amount = buffer.getInt();
int fee = buffer.getInt();
long referencedTransaction = buffer.getLong();
byte[] signature = new byte[64];
buffer.get(signature);
Transaction transaction = new Transaction(type, subtype, timestamp, deadline, senderPublicKey, recipient, amount, fee, referencedTransaction, signature);
switch (type)
{
case 1:
switch (subtype)
{
case 0:
int messageLength = buffer.getInt();
if (messageLength <= 1000)
{
byte[] message = new byte[messageLength];
buffer.get(message);
transaction.attachment = new Nxt.Transaction.MessagingArbitraryMessageAttachment(message);
}
break;
case 1:
int aliasLength = buffer.get();
byte[] alias = new byte[aliasLength];
buffer.get(alias);
int uriLength = buffer.getShort();
byte[] uri = new byte[uriLength];
buffer.get(uri);
try
{
transaction.attachment = new Nxt.Transaction.MessagingAliasAssignmentAttachment(new String(alias, "UTF-8"), new String(uri, "UTF-8"));
}
catch (RuntimeException|UnsupportedEncodingException e)
{
Nxt.logDebugMessage("Error parsing alias assignment", e);
}
}
break;
case 2:
switch (subtype)
{
case 0:
int nameLength = buffer.get();
byte[] name = new byte[nameLength];
buffer.get(name);
int descriptionLength = buffer.getShort();
byte[] description = new byte[descriptionLength];
buffer.get(description);
int quantity = buffer.getInt();
try
{
transaction.attachment = new Nxt.Transaction.ColoredCoinsAssetIssuanceAttachment(new String(name, "UTF-8"), new String(description, "UTF-8"), quantity);
}
catch (RuntimeException|UnsupportedEncodingException e)
{
Nxt.logDebugMessage("Error in asset issuance", e);
}
break;
case 1:
long asset = buffer.getLong();
int quantity = buffer.getInt();
transaction.attachment = new Nxt.Transaction.ColoredCoinsAssetTransferAttachment(asset, quantity);
break;
case 2:
long asset = buffer.getLong();
int quantity = buffer.getInt();
long price = buffer.getLong();
transaction.attachment = new Nxt.Transaction.ColoredCoinsAskOrderPlacementAttachment(asset, quantity, price);
break;
case 3:
long asset = buffer.getLong();
int quantity = buffer.getInt();
long price = buffer.getLong();
transaction.attachment = new Nxt.Transaction.ColoredCoinsBidOrderPlacementAttachment(asset, quantity, price);
break;
case 4:
long order = buffer.getLong();
transaction.attachment = new Nxt.Transaction.ColoredCoinsAskOrderCancellationAttachment(order);
break;
case 5:
long order = buffer.getLong();
transaction.attachment = new Nxt.Transaction.ColoredCoinsBidOrderCancellationAttachment(order);
}
break;
}
return transaction;
}
static Transaction getTransaction(JSONObject transactionData)
{
byte type = ((Long)transactionData.get("type")).byteValue();
byte subtype = ((Long)transactionData.get("subtype")).byteValue();
int timestamp = ((Long)transactionData.get("timestamp")).intValue();
short deadline = ((Long)transactionData.get("deadline")).shortValue();
byte[] senderPublicKey = Nxt.convert((String)transactionData.get("senderPublicKey"));
long recipient = Nxt.parseUnsignedLong((String)transactionData.get("recipient"));
int amount = ((Long)transactionData.get("amount")).intValue();
int fee = ((Long)transactionData.get("fee")).intValue();
long referencedTransaction = Nxt.parseUnsignedLong((String)transactionData.get("referencedTransaction"));
byte[] signature = Nxt.convert((String)transactionData.get("signature"));
Transaction transaction = new Transaction(type, subtype, timestamp, deadline, senderPublicKey, recipient, amount, fee, referencedTransaction, signature);
JSONObject attachmentData = (JSONObject)transactionData.get("attachment");
switch (type)
{
case 1:
switch (subtype)
{
case 0:
String message = (String)attachmentData.get("message");
transaction.attachment = new Nxt.Transaction.MessagingArbitraryMessageAttachment(Nxt.convert(message));
break;
case 1:
String alias = (String)attachmentData.get("alias");
String uri = (String)attachmentData.get("uri");
transaction.attachment = new Nxt.Transaction.MessagingAliasAssignmentAttachment(alias.trim(), uri.trim());
}
break;
case 2:
switch (subtype)
{
case 0:
String name = (String)attachmentData.get("name");
String description = (String)attachmentData.get("description");
int quantity = ((Long)attachmentData.get("quantity")).intValue();
transaction.attachment = new Nxt.Transaction.ColoredCoinsAssetIssuanceAttachment(name.trim(), description.trim(), quantity);
break;
case 1:
long asset = Nxt.parseUnsignedLong((String)attachmentData.get("asset"));
int quantity = ((Long)attachmentData.get("quantity")).intValue();
transaction.attachment = new Nxt.Transaction.ColoredCoinsAssetTransferAttachment(asset, quantity);
break;
case 2:
long asset = Nxt.parseUnsignedLong((String)attachmentData.get("asset"));
int quantity = ((Long)attachmentData.get("quantity")).intValue();
long price = ((Long)attachmentData.get("price")).longValue();
transaction.attachment = new Nxt.Transaction.ColoredCoinsAskOrderPlacementAttachment(asset, quantity, price);
break;
case 3:
long asset = Nxt.parseUnsignedLong((String)attachmentData.get("asset"));
int quantity = ((Long)attachmentData.get("quantity")).intValue();
long price = ((Long)attachmentData.get("price")).longValue();
transaction.attachment = new Nxt.Transaction.ColoredCoinsBidOrderPlacementAttachment(asset, quantity, price);
break;
case 4:
transaction.attachment = new Nxt.Transaction.ColoredCoinsAskOrderCancellationAttachment(Nxt.parseUnsignedLong((String)attachmentData.get("order")));
break;
case 5:
transaction.attachment = new Nxt.Transaction.ColoredCoinsBidOrderCancellationAttachment(Nxt.parseUnsignedLong((String)attachmentData.get("order")));
}
break;
}
return transaction;
}
static void loadTransactions(String fileName)
throws FileNotFoundException
{
try
{
FileInputStream fileInputStream = new FileInputStream(fileName);Throwable localThrowable3 = null;
try
{
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);Throwable localThrowable4 = null;
try
{
Nxt.transactionCounter.set(objectInputStream.readInt());
Nxt.transactions.clear();
Nxt.transactions.putAll((HashMap)objectInputStream.readObject());
}
catch (Throwable localThrowable1)
{
localThrowable4 = localThrowable1;throw localThrowable1;
}
finally {}
}
catch (Throwable localThrowable2)
{
localThrowable3 = localThrowable2;throw localThrowable2;
}
finally
{
if (fileInputStream != null) {
if (localThrowable3 != null) {
try
{
fileInputStream.close();
}
catch (Throwable x2)
{
localThrowable3.addSuppressed(x2);
}
} else {
fileInputStream.close();
}
}
}
}
catch (FileNotFoundException e)
{
throw e;
}
catch (IOException|ClassNotFoundException e)
{
Nxt.logMessage("Error loading transactions from " + fileName, e);
System.exit(1);
}
}
static void processTransactions(JSONObject request, String parameterName)
{
JSONArray transactionsData = (JSONArray)request.get(parameterName);
JSONArray validTransactionsData = new JSONArray();
for (Object transactionData : transactionsData)
{
Transaction transaction = getTransaction((JSONObject)transactionData);
try
{
int curTime = Nxt.getEpochTime(System.currentTimeMillis());
if ((transaction.timestamp > curTime + 15) || (transaction.deadline < 1) || (transaction.timestamp + transaction.deadline * 60 < curTime) || (transaction.fee <= 0) || (transaction.validateAttachment()))
{
long senderId;
boolean doubleSpendingTransaction;
synchronized (Nxt.blocksAndTransactionsLock)
{
long id = transaction.getId();
if ((Nxt.transactions.get(Long.valueOf(id)) == null) && (Nxt.unconfirmedTransactions.get(Long.valueOf(id)) == null) && (Nxt.doubleSpendingTransactions.get(Long.valueOf(id)) == null) && (!transaction.verify())) {
continue;
}
senderId = transaction.getSenderAccountId();
Nxt.Account account = (Nxt.Account)Nxt.accounts.get(Long.valueOf(senderId));
boolean doubleSpendingTransaction;
if (account == null)
{
doubleSpendingTransaction = true;
}
else
{
int amount = transaction.amount + transaction.fee;
synchronized (account)
{
boolean doubleSpendingTransaction;
if (account.getUnconfirmedBalance() < amount * 100L)
{
doubleSpendingTransaction = true;
}
else
{
doubleSpendingTransaction = false;
account.addToUnconfirmedBalance(-amount * 100L);
if (transaction.type == 2) {
if (transaction.subtype == 1)
{
Nxt.Transaction.ColoredCoinsAssetTransferAttachment attachment = (Nxt.Transaction.ColoredCoinsAssetTransferAttachment)transaction.attachment;
Integer unconfirmedAssetBalance = account.getUnconfirmedAssetBalance(Long.valueOf(attachment.asset));
if ((unconfirmedAssetBalance == null) || (unconfirmedAssetBalance.intValue() < attachment.quantity))
{
doubleSpendingTransaction = true;
account.addToUnconfirmedBalance(amount * 100L);
}
else
{
account.addToUnconfirmedAssetBalance(Long.valueOf(attachment.asset), -attachment.quantity);
}
}
else if (transaction.subtype == 2)
{
Nxt.Transaction.ColoredCoinsAskOrderPlacementAttachment attachment = (Nxt.Transaction.ColoredCoinsAskOrderPlacementAttachment)transaction.attachment;
Integer unconfirmedAssetBalance = account.getUnconfirmedAssetBalance(Long.valueOf(attachment.asset));
if ((unconfirmedAssetBalance == null) || (unconfirmedAssetBalance.intValue() < attachment.quantity))
{
doubleSpendingTransaction = true;
account.addToUnconfirmedBalance(amount * 100L);
}
else
{
account.addToUnconfirmedAssetBalance(Long.valueOf(attachment.asset), -attachment.quantity);
}
}
else if (transaction.subtype == 3)
{
Nxt.Transaction.ColoredCoinsBidOrderPlacementAttachment attachment = (Nxt.Transaction.ColoredCoinsBidOrderPlacementAttachment)transaction.attachment;
if (account.getUnconfirmedBalance() < attachment.quantity * attachment.price)
{
doubleSpendingTransaction = true;
account.addToUnconfirmedBalance(amount * 100L);
}
else
{
account.addToUnconfirmedBalance(-attachment.quantity * attachment.price);
}
}
}
}
}
}
transaction.index = Nxt.transactionCounter.incrementAndGet();
if (doubleSpendingTransaction)
{
Nxt.doubleSpendingTransactions.put(Long.valueOf(transaction.getId()), transaction);
}
else
{
Nxt.unconfirmedTransactions.put(Long.valueOf(transaction.getId()), transaction);
if (parameterName.equals("transactions")) {
validTransactionsData.add(transactionData);
}
}
}
response = new JSONObject();
response.put("response", "processNewData");
JSONArray newTransactions = new JSONArray();
JSONObject newTransaction = new JSONObject();
newTransaction.put("index", Integer.valueOf(transaction.index));
newTransaction.put("timestamp", Integer.valueOf(transaction.timestamp));
newTransaction.put("deadline", Short.valueOf(transaction.deadline));
newTransaction.put("recipient", Nxt.convert(transaction.recipient));
newTransaction.put("amount", Integer.valueOf(transaction.amount));
newTransaction.put("fee", Integer.valueOf(transaction.fee));
newTransaction.put("sender", Nxt.convert(senderId));
newTransaction.put("id", transaction.getStringId());
newTransactions.add(newTransaction);
if (doubleSpendingTransaction) {
response.put("addedDoubleSpendingTransactions", newTransactions);
} else {
response.put("addedUnconfirmedTransactions", newTransactions);
}
for (Nxt.User user : Nxt.users.values()) {
user.send(response);
}
}
}
catch (RuntimeException e)
{
JSONObject response;
Nxt.logMessage("Error processing transaction", e);
}
}
if (validTransactionsData.size() > 0)
{
JSONObject peerRequest = new JSONObject();
peerRequest.put("requestType", "processTransactions");
peerRequest.put("transactions", validTransactionsData);
Nxt.Peer.sendToSomePeers(peerRequest);
}
}
static void saveTransactions(String fileName)
{
try
{
FileOutputStream fileOutputStream = new FileOutputStream(fileName);Throwable localThrowable3 = null;
try
{
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);Throwable localThrowable4 = null;
try
{
objectOutputStream.writeInt(Nxt.transactionCounter.get());
objectOutputStream.writeObject(new HashMap(Nxt.transactions));
objectOutputStream.close();
}
catch (Throwable localThrowable1)
{
localThrowable4 = localThrowable1;throw localThrowable1;
}
finally {}
}
catch (Throwable localThrowable2)
{
localThrowable3 = localThrowable2;throw localThrowable2;
}
finally
{
if (fileOutputStream != null) {
if (localThrowable3 != null) {
try
{
fileOutputStream.close();
}
catch (Throwable x2)
{
localThrowable3.addSuppressed(x2);
}
} else {
fileOutputStream.close();
}
}
}
}
catch (IOException e)
{
Nxt.logMessage("Error saving transactions to " + fileName, e);
throw new RuntimeException(e);
}
}
void sign(String secretPhrase)
{
this.signature = Nxt.Crypto.sign(getBytes(), secretPhrase);
try
{
while (!verify())
{
this.timestamp += 1;
this.signature = new byte[64];
this.signature = Nxt.Crypto.sign(getBytes(), secretPhrase);
}
}
catch (RuntimeException e)
{
Nxt.logMessage("Error signing transaction", e);
}
}
boolean validateAttachment()
{
if (this.fee > 1000000000L) {
return false;
}
switch (this.type)
{
case 0:
switch (this.subtype)
{
case 0:
if ((this.amount <= 0) || (this.amount > 1000000000L)) {
return false;
}
return true;
}
return false;
case 1:
switch (this.subtype)
{
case 0:
if (Nxt.Block.getLastBlock().height < 40000) {
return false;
}
try
{
Nxt.Transaction.MessagingArbitraryMessageAttachment attachment = (Nxt.Transaction.MessagingArbitraryMessageAttachment)this.attachment;
return (this.amount == 0) && (attachment.message.length <= 1000);
}
catch (RuntimeException e)
{
Nxt.logDebugMessage("Error validating arbitrary message", e);
return false;
}
case 1:
if (Nxt.Block.getLastBlock().height < 22000) {
return false;
}
try
{
Nxt.Transaction.MessagingAliasAssignmentAttachment attachment = (Nxt.Transaction.MessagingAliasAssignmentAttachment)this.attachment;
if ((this.recipient != 1739068987193023818L) || (this.amount != 0) || (attachment.alias.length() == 0) || (attachment.alias.length() > 100) || (attachment.uri.length() > 1000)) {
return false;
}
String normalizedAlias = attachment.alias.toLowerCase();
for (int i = 0; i < normalizedAlias.length(); i++) {
if ("0123456789abcdefghijklmnopqrstuvwxyz".indexOf(normalizedAlias.charAt(i)) < 0) {
return false;
}
}
Nxt.Alias alias = (Nxt.Alias)Nxt.aliases.get(normalizedAlias);
return (alias == null) || (Arrays.equals((byte[])alias.account.publicKey.get(), this.senderPublicKey));
}
catch (RuntimeException e)
{
Nxt.logDebugMessage("Error validation alias assignment", e);
return false;
}
}
return false;
}
return false;
}
boolean verify()
{
Nxt.Account account = (Nxt.Account)Nxt.accounts.get(Long.valueOf(getSenderAccountId()));
if (account == null) {
return false;
}
byte[] data = getBytes();
for (int i = 64; i < 128; i++) {
data[i] = 0;
}
return (Nxt.Crypto.verify(this.signature, data, this.senderPublicKey)) && (account.setOrVerify(this.senderPublicKey));
}
public static byte[] calculateTransactionsChecksum()
{
synchronized (Nxt.blocksAndTransactionsLock)
{
PriorityQueue<Transaction> sortedTransactions = new PriorityQueue(Nxt.transactions.size(), new Nxt.Transaction.2());
sortedTransactions.addAll(Nxt.transactions.values());
MessageDigest digest = Nxt.getMessageDigest("SHA-256");