sapio-lang / sapio

A Bitcoin Programming Language
Mozilla Public License 2.0
244 stars 43 forks source link

simplify amount_range / Amount* structs to a sane default? #241

Open JeremyRubin opened 1 year ago

ProofOfKeags commented 1 year ago

What is currently insane about Amount/AmountF64/AmountU64/AmountRange?

JeremyRubin commented 1 year ago

AmountF64 cannot be canonicalized as a json, and the Amount type doesn't have a Serialize impl at all (you have to manually specify, which doesn't compose well with data structures), and if you use a Amount{F,U}64 then it doesn't necessarily create an unambiguous Schema or serialization validation to know which is which.

ProofOfKeags commented 1 year ago

Do we want to keep the AmountF64 at all then? Do we lose anything by moving purely to integer sats as a representation?

JeremyRubin commented 1 year ago

people expect to be able to write 1.5 and have it be understood as bitcoin, see https://learn.sapio-lang.org/ch03-01-amounts.html

ProofOfKeags commented 1 year ago

Understood. I don't see this as a problem though, ideally we should just have a singular internal representation (which is the only one that actually needs to be serializable) and have multiple constructors, one from float space from_btc and one from integer space from_sats which I believe we already have. The reasonable approach here seems to be to make everything Serialize via integer space since it is lossless, and relegate the float vs int problem to be one of the UX on the compiler frontend.