Skip to content

Commit

Permalink
more operator overloads for coin with BigInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Oct 31, 2022
1 parent ff42e7b commit 53fc58a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions secretk/src/commonMain/kotlin/io/eqoty/secretk/types/Coin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ data class Coin(
}
}

operator fun plus(increment: BigInteger): Coin {
return this.copy(
amount = (BigInteger.parseString(amount, 10) + increment).toString()
)
}

operator fun minus(increment: Coin): Coin {
return if (increment.denom == denom) {
this.copy(
Expand All @@ -39,6 +45,12 @@ data class Coin(
}
}

operator fun minus(increment: BigInteger): Coin {
return this.copy(
amount = (BigInteger.parseString(amount, 10) - increment).toString()
)
}

operator fun times(increment: Coin): Coin {
return if (increment.denom == denom) {
this.copy(
Expand All @@ -52,6 +64,12 @@ data class Coin(
}
}

operator fun times(increment: BigInteger): Coin {
return this.copy(
amount = (BigInteger.parseString(amount, 10) * increment).toString()
)
}

operator fun div(increment: Coin): Coin {
return if (increment.denom == denom) {
this.copy(
Expand All @@ -65,4 +83,9 @@ data class Coin(
}
}

operator fun div(increment: BigInteger): Coin {
return this.copy(
amount = (BigInteger.parseString(amount, 10) / increment).toString()
)
}
}

0 comments on commit 53fc58a

Please sign in to comment.