Vixen
c7401864
csharp
public sealed class MemoryEconomyLedger

An IEconomyLedger in memory. For tests, and for a single-process game.

Read the guide page for this →

Remarks

⚠ Built with Never, so a long-running realm leaks until it says otherwise. Every applied key is kept for ever by default, which over a week of uptime is every key of that week — Samples/14-Mmo's soak measures it at about a megabyte a minute. Pass a KeyHorizon and call Forget off the frame path; see that type for why the default is the leak rather than a chosen number.

⚠ A player's account may not go negative and a world account may. That asymmetry is what makes a world account a source or a sink: a vendor's stock comes from somewhere and a fee goes nowhere, and modelling either with a real balance would mean seeding the world with every coin it will ever mint. A player who cannot pay is refused, which is the check the whole thing exists for.

Fields and properties (4)

  • public KeyHorizon Horizon

    How long an applied key is remembered.

  • public long Applied

    How many intents have been applied, not counting replays.

  • public int Keys

    How many distinct keys it is holding.

  • public long Forgotten

    How many keys have been dropped past the horizon.

Methods (8)

  • public MemoryEconomyLedger()

    One that forgets nothing.

  • public MemoryEconomyLedger(KeyHorizon horizon)

    One that forgets a key once no retry can still carry it.

  • public long Balance(EconomyAccount account, DefId asset)

    What an account holds of something.

  • public IEnumerable<(DefId Asset, long Amount)> Holdings(EconomyAccount account)

    Everything an account holds, in address order of the asset id.

  • public long Total(DefId asset)

    What every account holds of one asset, added up.

  • public int Release(EconomyAccount account, EconomyAccount into)

    Hands everything an account holds to another, and stops keeping rows for it.

  • public EconomyResult Post(EconomyIntent intent)

    Records an intent, or says why not.

  • public int Forget(DateTimeOffset now)

    Drops every key that is older than the horizon guarantees.

Used by (10)

  • ShardMmo.Soak
  • AuctionTestsVixen.Gameplay.Economy.Tests
  • HousekeepingTestsVixen.Live.Gameplay.Tests
  • KeyHorizonTestsVixen.Gameplay.Economy.Tests
  • LedgerBridgeTestsVixen.Live.Gameplay.Tests
  • LedgerReleaseTestsVixen.Gameplay.Economy.Tests
  • LedgerTestsVixen.Gameplay.Economy.Tests
  • MarketFixtureVixen.Gameplay.Economy.Tests
  • TradeTestsVixen.Gameplay.Economy.Tests
  • VendorTestsVixen.Gameplay.Economy.Tests