Skip to content

Commit

Permalink
CORE-19286: Add priorty to UtxoToken (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephzunigadaly authored Mar 14, 2024
1 parent 79fedad commit 3f8e27d
Showing 1 changed file with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public final class UtxoToken {
@Nullable
private final UtxoTokenFilterFields filterFields;

@Nullable
private final Long priority;

/**
* Creates a new instance of the {@link UtxoToken} class.
*
Expand All @@ -43,9 +46,26 @@ public UtxoToken(
@NotNull final UtxoTokenPoolKey poolKey,
@NotNull final BigDecimal amount,
@Nullable final UtxoTokenFilterFields filterFields) {
this(poolKey, amount, filterFields, null);
}

/**
* Creates a new instance of the {@link UtxoToken} class.
*
* @param poolKey The key of the token pool that this token belongs to.
* @param amount The amount represented by this token.
* @param filterFields Optional fields available to the {@link TokenSelection} API {@link TokenClaimCriteria}.
* @param priority Priority for token selection, lower is higher
*/
public UtxoToken(
@NotNull final UtxoTokenPoolKey poolKey,
@NotNull final BigDecimal amount,
@Nullable final UtxoTokenFilterFields filterFields,
@Nullable final Long priority) {
this.poolKey = poolKey;
this.amount = amount;
this.filterFields = filterFields;
this.priority = priority;
}

/**
Expand Down Expand Up @@ -78,6 +98,16 @@ public UtxoTokenFilterFields getFilterFields() {
return filterFields;
}

/**
* Gets the token priority.
*
* @return Returns the token priority, lower is higher. `null` value means no priority is set.
*/
@Nullable
public Long getPriority() {
return priority;
}

/**
* Determines whether the specified object is equal to the current object.
*
Expand All @@ -98,7 +128,8 @@ public boolean equals(@Nullable final Object obj) {
public boolean equals(@NotNull final UtxoToken other) {
return Objects.equals(other.poolKey, poolKey)
&& Objects.compare(other.amount, amount, BigDecimal::compareTo) == 0
&& Objects.equals(other.filterFields, filterFields);
&& Objects.equals(other.filterFields, filterFields)
&& Objects.equals(other.priority, priority);
}

/**
Expand All @@ -108,7 +139,7 @@ public boolean equals(@NotNull final UtxoToken other) {
*/
@Override
public int hashCode() {
return Objects.hash(poolKey, amount, filterFields);
return Objects.hash(poolKey, amount, filterFields, priority);
}

/**
Expand All @@ -118,6 +149,10 @@ public int hashCode() {
*/
@Override
public String toString() {
return MessageFormat.format("UtxoToken(poolKey={0}, amount={1}, filterFields={2}", poolKey, amount, filterFields);
return MessageFormat.format("UtxoToken(poolKey={0}, amount={1}, filterFields={2}, priority={3}",
poolKey,
amount,
filterFields,
priority);
}
}

0 comments on commit 3f8e27d

Please sign in to comment.