-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Bencodex.Types; | ||
using Libplanet.Action.State; | ||
using Libplanet.Crypto; | ||
|
||
namespace Nekoyume.Module | ||
{ | ||
public static class ActionPointModule | ||
{ | ||
public static long GetActionPoint(this IWorldState worldState, Address address) | ||
{ | ||
var value = worldState.GetAccountState(Addresses.ActionPoint).GetState(address); | ||
if (value is Integer integer) | ||
{ | ||
return integer; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static IWorld SetActionPoint(this IWorld world, Address address, long actionPoint) | ||
{ | ||
var account = world.GetAccount(Addresses.ActionPoint); | ||
account = account.SetState(address, (Integer)actionPoint); | ||
return world.SetAccount(Addresses.ActionPoint, account); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using Bencodex; | ||
using Bencodex.Types; | ||
using Libplanet.Action.State; | ||
using Libplanet.Crypto; | ||
using Nekoyume.Action; | ||
using Nekoyume.Model.State; | ||
|
||
namespace Nekoyume.Module | ||
{ | ||
public static class DailyRewardModule | ||
{ | ||
public class DailyRewardInfo : IBencodable | ||
{ | ||
public Address AgentAddress; | ||
public long ReceivedBlockIndex; | ||
|
||
public DailyRewardInfo(Address address, long blockIndex) | ||
{ | ||
AgentAddress = address; | ||
ReceivedBlockIndex = blockIndex; | ||
} | ||
|
||
public IValue Bencoded => List.Empty.Add(AgentAddress.Serialize()).Add(ReceivedBlockIndex); | ||
} | ||
|
||
public static DailyRewardInfo GetDailyRewardInfo(this IWorldState worldState, | ||
Address avatarAddress) | ||
{ | ||
IAccountState account = worldState.GetAccountState(Addresses.DailyReward); | ||
var value = account.GetState(avatarAddress); | ||
if (value is List l) | ||
{ | ||
return new DailyRewardInfo(l[0].ToAddress(), (Integer)l[1]); | ||
} | ||
|
||
throw new FailedLoadStateException(""); | ||
} | ||
|
||
public static bool TryGetDailyRewardInfo(this IWorldState worldState, | ||
Address agentAddress, Address avatarAddress, out DailyRewardInfo dailyRewardInfo) | ||
{ | ||
dailyRewardInfo = null; | ||
try | ||
{ | ||
var temp= GetDailyRewardInfo(worldState, avatarAddress); | ||
if (!temp.AgentAddress.Equals(agentAddress)) | ||
{ | ||
return false; | ||
} | ||
|
||
dailyRewardInfo = temp; | ||
return true; | ||
} | ||
catch (FailedLoadStateException) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public static IWorld SetDailyRewardInfo(this IWorld world, Address avatarAddress, | ||
DailyRewardInfo dailyRewardInfo) | ||
{ | ||
IAccount account = world.GetAccount(Addresses.DailyReward); | ||
account = account.SetState(avatarAddress, dailyRewardInfo.Bencoded); | ||
return world.SetAccount(Addresses.DailyReward, account); | ||
} | ||
} | ||
} |