-
Notifications
You must be signed in to change notification settings - Fork 48
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
example for hardfork DailyReward #2492
Draft
ipdae
wants to merge
1
commit into
development
Choose a base branch
from
exp/issue-2478
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어차피 이 IValue의 Address를 AvatarAddress로 가져올거면 굳이 AgentAddress를 들고있을 이유가 있을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
나중에 statestore 에서 직접 값 읽어보고 할 때 편하긴 할 겁니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
상태만 덜렁 들고있을때 이게 어떤 아바타의 DailyRewardInfo인지 헷갈릴 것 같다 싶긴했는데, 음... 네 상관없을 것 같네요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제약조건(아바타어드레스가 에이전트어드레스종속적인지)를 확인할 방법이 AgentState나 AvatarState를 직접 확인하는 방법밖에 없었어서 DailyRewardInfo에 넣어놨는데, 생각해보니 별도 어카운트에 넣어두거나(다른 액션들도 확인할 수 있으니) 액션안에서는 Derive를 해보는게 낫겠다 싶네요.