Enum Class Transactions.TransactionType
- All Implemented Interfaces:
Serializable
,Comparable<Transactions.TransactionType>
,java.lang.constant.Constable
- Enclosing class:
Transactions
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional
<Transactions.TransactionType> find
(int code) Find transaction type by numeric valueshort
Return the 16-bit unsigned value in a Javashort
.int
value()
Return transaction type numeric value as an unsignedint
static Transactions.TransactionType
valueOf
(int code) Get transaction type by numeric valuestatic Transactions.TransactionType
Returns the enum constant of this class with the specified name.static Transactions.TransactionType[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.short
version()
Return the latest defined version for the transaction typeint
-
Enum Constant Details
-
SIMPLE_SEND
-
SEND_TO_OWNERS
-
SEND_ALL
-
TRADE_OFFER
-
ACCEPT_OFFER_BTC
-
METADEX_TRADE
-
CREATE_PROPERTY_FIXED
-
CREATE_PROPERTY_VARIABLE
-
PROMOTE_PROPERTY
-
CLOSE_CROWDSALE
-
CREATE_PROPERTY_MANUAL
-
GRANT_PROPERTY_TOKENS
-
REVOKE_PROPERTY_TOKENS
-
CHANGE_ISSUER_ADDRESS
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
valueOf
Get transaction type by numeric value- Parameters:
code
- transaction type integer value- Returns:
- The correct enum
- Throws:
IllegalArgumentException
- if not found
-
find
Find transaction type by numeric value- Parameters:
code
- transaction type integer value- Returns:
- an Optional enum or
Optional.empty()
if not found.
-
version
public short version()Return the latest defined version for the transaction type- Returns:
- numeric value of transaction version
-
value
public int value()Return transaction type numeric value as an unsignedint
- Returns:
- numeric value of TransactionType
-
unsignedShortValue
public short unsignedShortValue()Return the 16-bit unsigned value in a Javashort
.Use this method with caution as Java treats
short
s as signed.- Returns:
- numeric value of TransactionType as an unsigned
short
-
versionType
public int versionType()
-