dfinity / invoice-canister

Providing an example and simplified experience for accepting payments in smart contracts
Apache License 2.0
44 stars 13 forks source link

Prevent arithmetic overflow when amount in TransferArgs is below 10_000 #35

Open seb-icp opened 2 years ago

seb-icp commented 2 years ago

Currently when requesting a transfer with an amount in TransferArgs below 10_000 e8s the invoice canister will trap on an arithmetic overflow, due to this line :

amount = {
                // Total amount, minus the fee
                e8s = Nat64.sub(Nat64.fromNat(args.amount), 10000);
              };

Is it expected behaviour? I would rather have a specific error indicating that the amount is too low to pay for the fee. For the context, I have a function (called periodically) that check the balance in the invoice canister and request a transfer to another wallet.

Trunkzz commented 2 years ago

I've had this issue a ton. I worked around it by adding 10,000 extra.

krpeacock commented 2 years ago

Some better error handling here would be worthwhile