From 53fc58a393e60a7223115cd8b31e23250efb2793 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Mon, 31 Oct 2022 18:31:40 -0400 Subject: [PATCH] more operator overloads for coin with BigInteger --- .../kotlin/io/eqoty/secretk/types/Coin.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/Coin.kt b/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/Coin.kt index a842bb1..e0da5b2 100644 --- a/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/Coin.kt +++ b/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/Coin.kt @@ -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( @@ -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( @@ -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( @@ -65,4 +83,9 @@ data class Coin( } } + operator fun div(increment: BigInteger): Coin { + return this.copy( + amount = (BigInteger.parseString(amount, 10) / increment).toString() + ) + } } \ No newline at end of file