Enum Class Transactions.TransactionType

java.lang.Object
java.lang.Enum<Transactions.TransactionType>
foundation.omni.tx.Transactions.TransactionType
All Implemented Interfaces:
Serializable, Comparable<Transactions.TransactionType>, java.lang.constant.Constable
Enclosing class:
Transactions

public static enum Transactions.TransactionType extends Enum<Transactions.TransactionType>
Omni Layer Transaction Type

Transaction type is an unsigned 16-bit value, and stored as a Java short that is treated as unsigned. The value() accessor performs the proper conversion and returns an unsigned int.

With JEP 427: Pattern Matching for Switch it is possible to handle null as a case. So if you're using a recent version of Java (with preview enabled) you can handle undefined transaction types in a single switch statement/expression. If you have an integer with a transaction type code named typeInt, you can do something like:

 
 Optional<TransactionType> optionalType = TransactionType.find(typeInt);
 boolean isSend = switch(optionalType.orElse(null)) {
     case SIMPLE_SEND, SEND_TO_OWNERS, SEND_ALL -> true;
     default -> false;
     case null -> false;
 }
 
The default case represents defined enum constants not handled with explicit cases and the null case provides a way to handle numeric codes not (yet) defined in the enum.

For versions of Java with switch expressions but no pattern matching, this above code can be written as:

 
 Optional<TransactionType> optionalType = TransactionType.find(typeInt);
 boolean isSend = optionalType.map(t -> switch(t) {
     case SIMPLE_SEND, SEND_TO_OWNERS, SEND_ALL -> true;
     default -> false;
 }).orElse(false);
 

For even earlier versions of Java (back to Java 9), it can be written as:

 
 Optional<TransactionType> optionalType = TransactionType.find(typeInt);
 boolean isSend;
 optionalType.ifPresentOrElse(t -> switch(t) {
     case SIMPLE_SEND:
     case SEND_TO_OWNERS:
     case SEND_ALL:
       isSend = true;
       break;
     default:
       isSend = false;
 }, {
  isSend = false;
 }
 
For a Java 8 example see the Java unit test TransactionTypeTest.java.

This is a partial list of transaction types, see omnicore.h for the complete list.

See Also: