Skip to content

Commit

Permalink
add rem operators to coin
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Oct 31, 2022
1 parent 1ae8294 commit 2ab57f6
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions secretk/src/commonMain/kotlin/io/eqoty/secretk/types/Coin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ data class Coin(
)
}

operator fun times(increment: Coin): Coin {
return if (increment.denom == denom) {
operator fun times(other: Coin): Coin {
return if (other.denom == denom) {
this.copy(
amount = (BigInteger.parseString(amount, 10) * BigInteger.parseString(
increment.amount,
other.amount,
10
)).toString()
)
Expand All @@ -64,17 +64,36 @@ data class Coin(
}
}

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

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

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

operator fun rem(other: Coin): Coin {
return if (other.denom == denom) {
this.copy(
amount = (BigInteger.parseString(amount, 10) % BigInteger.parseString(
other.amount,
10
)).toString()
)
Expand All @@ -83,9 +102,9 @@ data class Coin(
}
}

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

0 comments on commit 2ab57f6

Please sign in to comment.