Is there is reason why Bitcoin uses signed instead of unsigned integers for amounts? I can't imagine a scenario where negative amounts could come up. Was it simply something Satoshi implemented for some future use this way and now we are stuck with it?
-
3As an aside, in C++ it is considered bad practice to use unsigned variable just because the underlying thing they represent can only be a positive value. There are a lot of traps in the language when you mixed signed and unsigned quantities thanks to the way implicit conversions work. This might have had some influence as well, since the original implementation was in C++.– ChuuNov 29, 2021 at 21:03
1 Answer
CAmount is used for multiple purposes in Bitcoin Core, not just in transaction validation logic. It is also used to represent the net effect transactions have on wallet balance, for example, and that net effect is negative as often as it is positive.