SpongeAPI icon indicating copy to clipboard operation
SpongeAPI copied to clipboard

Refactor EconomyTransactionEvent

Open ImMorpheus opened this issue 5 years ago • 3 comments

Part of the Economy API refactor.

Fix https://github.com/SpongePowered/SpongeAPI/issues/1501

EconomyTransactionEvent is now split between

Pre: is fired BEFORE the transaction has been processed (it can still fails and is cancellable). Post: is fired AFTER the transaction has been processed. This is read-only and the transaction result can be used to reliably check the result of the transaction.

ImMorpheus avatar Jul 10 '20 17:07 ImMorpheus

Looking back at this, I missed something about EconomyTransactionEvent.Pre and getAccount. Specifically: while the method works fine for deposit/withdraw, it's unclear for transfer since that involves two accounts. Something to retrieve the other account is needed. Do we add a method returning an Optional<Account> ? A subclass for the event ? Input wanted.

ImMorpheus avatar Aug 24 '20 23:08 ImMorpheus

Would it be better to just have an event that can handle multiple transactions at once? Rather than having a getAccount() and getCurrency() etc., have a collection of ProposedTransactions (or whatever) that contains this info, each one being a simple deposit or withdraw That way, a transfer is one event and the same event, and a plugin listening to this can treat/use it the same way as other plugins.

This could also allow economy plugins to build a complex web of transactions that might happen - a currency exchange plugin might allow two players to exchange their currencies so you might have two deposits and two withdrawals that all depend on each other (two accounts, two currencies, deposit and withdrawal on each side).

dualspiral avatar Aug 24 '20 23:08 dualspiral

I've shifted the base branch here to API-9, but is this something we want to revisit, or are we better off closing and thinking about Economy in a wider sense?

dualspiral avatar Feb 01 '22 19:02 dualspiral