Write transfer, which moves money from one account to another and returns the updated accounts.
Input:
accounts: a plain object mapping account id to{ balanceCents, frozen }. Only own keys ofaccountsare accounts; inherited properties of plain objects are not.from,to: account ids.amountCents: the amount to move, in integer cents.
On success, return a new accounts object with the same keys, where from's balance went down by amountCents and to's went up by the same amount. A balance may reach exactly zero. The input object and the account objects inside it must never be modified (accounts not involved in the transfer may be shared with the input).
Failures, checked in exactly this order (report the first that applies):
{ kind: "invalid_amount" }whenamountCentsis not an integer or is not greater than zero.{ kind: "same_account" }whenfromandtoare the same id.{ kind: "unknown_account", id }whenfromis not an account, then the same check forto.{ kind: "frozen", id }whenfromis frozen, then the same check forto.{ kind: "insufficient_funds", id, balanceCents, amountCents }whenfrom's balance is less thanamountCents(idisfrom,balanceCentsits current balance).