Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ 🚚 Moved Currency and Validator related methods from IWorldState and IWorld to an extension class #3715

Merged
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ To be released.
type `IReadOnlyList<ITransaction>?` to `IActionContext`. [[#3713]]
- (Libplanet.Action) Removed `TotalFungibleAssets` property from
`IWorld`. [[#3714]]
- (Libplanet.Action) Changed `GetBalance()`, `GetTotalSupply()`, and
`GetValidatorSet()` of `IWorldState` to extension methods. [[#3715]]
- (Libplanet.Action) Changed `MintAsset()`, `BurnAsset()`, `TransferAsset()`,
and `SetValidator()` of `IWorld` to extension methods. [[#3715]]

### Backward-incompatible network protocol changes

Expand All @@ -31,6 +35,7 @@ To be released.

[#3713]: https://github.com/planetarium/libplanet/pull/3713
[#3714]: https://github.com/planetarium/libplanet/pull/3714
[#3715]: https://github.com/planetarium/libplanet/pull/3715


Version 4.2.0
Expand Down
6 changes: 2 additions & 4 deletions Libplanet.Action/ActionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ private static IWorld CommitLegacyWorld(IWorld prevWorld, IStateStore stateStore
return new World(
new WorldBaseState(
stateStore.Commit(prevWorld.GetAccount(ReservedAddresses.LegacyAccount).Trie),
stateStore),
new WorldDelta());
stateStore));
}

private static IWorld CommitWorld(IWorld prevWorld, IStateStore stateStore)
Expand All @@ -590,8 +589,7 @@ private static IWorld CommitWorld(IWorld prevWorld, IStateStore stateStore)
}

return new World(
new WorldBaseState(stateStore.Commit(worldTrie), stateStore),
new WorldDelta());
new WorldBaseState(stateStore.Commit(worldTrie), stateStore));
}

[Pure]
Expand Down
90 changes: 0 additions & 90 deletions Libplanet.Action/State/IWorld.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Consensus;

namespace Libplanet.Action.State
{
Expand Down Expand Up @@ -76,92 +73,5 @@ public interface IWorld : IWorldState
/// </exception>
[Pure]
IWorld SetAccount(Address address, IAccount account);

/// <summary>
/// Mints the fungible asset <paramref name="value"/> (i.e., in-game monetary),
/// and give it to the <paramref name="recipient"/>.
/// </summary>
/// <param name="context">The <see cref="IActionContext"/> of the <see cref="IAction"/>
/// executing this method.</param>
/// <param name="recipient">The address who receives the minted asset.</param>
/// <param name="value">The asset value to mint.</param>
/// <returns>A new <see cref="IWorld"/> instance that the given <paramref
/// name="value"/> is added to <paramref name="recipient"/>'s balance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="value"/>
/// is less than or equal to 0.</exception>
/// <exception cref="CurrencyPermissionException">Thrown when a transaction signer
/// (or a miner in case of block actions) is not a member of the <see
/// cref="FungibleAssetValue.Currency"/>'s <see cref="Currency.Minters"/>.</exception>
/// <exception cref="SupplyOverflowException">Thrown when the sum of the
/// <paramref name="value"/> to be minted and the current total supply amount of the
/// <see cref="FungibleAssetValue.Currency"/> exceeds the
/// <see cref="Currency.MaximumSupply"/>.</exception>
[Pure]
IWorld MintAsset(IActionContext context, Address recipient, FungibleAssetValue value);

/// <summary>
/// Burns the fungible asset <paramref name="value"/> (i.e., in-game monetary) from
/// <paramref name="owner"/>'s balance.
/// </summary>
/// <param name="context">The <see cref="IActionContext"/> of the <see cref="IAction"/>
/// executing this method.</param>
/// <param name="owner">The address who owns the fungible asset to burn.</param>
/// <param name="value">The fungible asset <paramref name="value"/> to burn.</param>
/// <returns>A new <see cref="IWorld"/> instance that the given <paramref
/// name="value"/> is subtracted from <paramref name="owner"/>'s balance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="value"/>
/// is less than or equal to zero.</exception>
/// <exception cref="CurrencyPermissionException">Thrown when a transaction signer
/// (or a miner in case of block actions) is not a member of the <see
/// cref="FungibleAssetValue.Currency"/>'s <see cref="Currency.Minters"/>.</exception>
/// <exception cref="InsufficientBalanceException">Thrown when the <paramref name="owner"/>
/// has insufficient balance than <paramref name="value"/> to burn.</exception>
[Pure]
IWorld BurnAsset(IActionContext context, Address owner, FungibleAssetValue value);

/// <summary>
/// Transfers the fungible asset <paramref name="value"/> (i.e., in-game monetary)
/// from the <paramref name="sender"/> to the <paramref name="recipient"/>.
/// </summary>
/// <param name="context">The <see cref="IActionContext"/> of the <see cref="IAction"/>
/// executing this method.</param>
/// <param name="sender">The address who sends the fungible asset to
/// the <paramref name="recipient"/>.</param>
/// <param name="recipient">The address who receives the fungible asset from
/// the <paramref name="sender"/>.</param>
/// <param name="value">The asset value to transfer.</param>
/// <param name="allowNegativeBalance">Turn on to allow <paramref name="sender"/>'s balance
/// less than zero. Turned off by default.</param>
/// <returns>A new <see cref="IWorld"/> instance that the given <paramref
/// name="value"/> is subtracted from <paramref name="sender"/>'s balance and added to
/// <paramref name="recipient"/>'s balance.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="value"/>
/// is less than or equal to zero.</exception>
/// <exception cref="InsufficientBalanceException">Thrown when the <paramref name="sender"/>
/// has insufficient balance than <paramref name="value"/> to transfer and
/// the <paramref name="allowNegativeBalance"/> option is turned off.</exception>
/// <remarks>
/// The behavior is different depending on <paramref name="context"/>'s
/// <see cref="IActionContext.BlockProtocolVersion"/>. There is a bug for version 0
/// where this may not act as intended. Such behavior is left intact for backward
/// compatibility.
/// </remarks>
[Pure]
IWorld TransferAsset(
IActionContext context,
Address sender,
Address recipient,
FungibleAssetValue value,
bool allowNegativeBalance = false);

/// <summary>
/// Sets <paramref name="validator"/> to the stored <see cref="ValidatorSet"/>.
/// If 0 is given as its power, removes the validator from the <see cref="ValidatorSet"/>.
/// </summary>
/// <param name="validator">The <see cref="Validator"/> instance to write.</param>
/// <returns>A new <see cref="IWorld"/> instance with
/// <paramref name="validator"/> set.</returns>
[Pure]
IWorld SetValidator(Validator validator);
}
}
Loading
Loading