NPosts: 252 · Reputation: 12
I stumbled upon this article asking how many satoshis fit in a bitcoin. I could answer that without even thinking, but I got curious about why we measure Bitcoin in satoshis. So I peeked into the source code and found a pretty short snippet, only about 30 lines. But I got stuck on a couple of lines that seem to be causing the confusion.
MrPosts: 401 · Reputation: 35
I think we can't have negative amounts. We just need checks to kick out any invalid entries. When you’re looking at signed numbers like int64_t, you gotta watch for negatives. Just checking against the max isn’t enough; even -1 is less than max. It’s rejected only if you look for signs.
DaPosts: 375 · Reputation: 185
Right, in a 64-bit system, you can show anything from 1 satoshi to 21 quadrillion. But if we used Bitcoin instead, things would get messy with floating points. They only complicate stuff and aren’t needed here. Sure, they matter if we're talking about going beyond 21 million, but precision is key in currency.
MrPosts: 401 · Reputation: 35
That article you shared was about timestamps and signed int32 issues, not the signed int64 for amounts. We don’t need to mix those topics up. Just saying.
DiPosts: 200 · Reputation: 2112
So let's say you can technically create a transaction with a negative fee. If you sign it right, you might see a negative value pop up. It’s just theoretical though; it doesn’t mean it’s valid everywhere. Bob can only claim it by adding his own inputs.
NPosts: 252 · Reputation: 12
You're saying no negatives are allowed, but the signed 64-bit type might allow negative checks? It’s all confusing, especially if the fee is negative. How does that even work? Does Alice's input just stay False until Bob joins in?
WPosts: 127 · Reputation: 575
I think you’re kinda missing the point. CAmount is signed, so it can potentially hold negative values, but they aren’t valid everywhere. They just hint at possibilities. For example, if you check a wallet's balance history, sending bitcoins will show a negative change.
MrPosts: 401 · Reputation: 35
But you still can’t have a negative amount in outputs. Only fees might go negative, and that’s calculated at a higher level for the UI. You can use unsigned integers to make sense of total inputs vs outputs. If you think of numbers as binaries, that clears up signed vs unsigned confusion.