Skip to content

Commit a9ae186

Browse files
ovitrifclaude
andcommitted
refactor: add MSat value class
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a84e332 commit a9ae186

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • app/src/main/java/to/bitkit/models
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package to.bitkit.models
2+
3+
/**
4+
* A wrapper for millisatoshi [ULong] values that provides explicit sat conversions.
5+
*
6+
* Eliminates scattered `/ 1000u` and `(x + 999u) / 1000u` patterns by encoding
7+
* the rounding intent directly in the API: [ceil] rounds up, [floor] truncates.
8+
*
9+
* Zero runtime overhead — this is an [inline value class][JvmInline].
10+
*/
11+
@JvmInline
12+
value class MSat(val value: ULong) {
13+
14+
/** Round up to the nearest whole sat. Use for payment/display amounts. */
15+
fun ceil(): ULong = (value + 999u) / 1000u
16+
17+
/** Truncate sub-sat remainder. Use for fees and upper bounds. */
18+
fun floor(): ULong = value / 1000u
19+
}

0 commit comments

Comments
 (0)