From 86bf7ccc3a56cb0537b74fe6de1f2d2a981c2410 Mon Sep 17 00:00:00 2001 From: XxshiftxX Date: Wed, 30 Aug 2023 09:22:08 +0900 Subject: [PATCH 01/15] make patchTableSheet can recieve tableName with new form --- NineChronicles.Headless/GraphTypes/ActionQuery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NineChronicles.Headless/GraphTypes/ActionQuery.cs b/NineChronicles.Headless/GraphTypes/ActionQuery.cs index 070458f12..207be91b5 100644 --- a/NineChronicles.Headless/GraphTypes/ActionQuery.cs +++ b/NineChronicles.Headless/GraphTypes/ActionQuery.cs @@ -223,7 +223,7 @@ public ActionQuery(StandaloneContext standaloneContext) @namespace.StartsWith($"{nameof(Nekoyume)}.{nameof(Nekoyume.TableData)}") && !type.IsAbstract && typeof(ISheet).IsAssignableFrom(type) && - type.Name == tableName); + tableName.Split('_').First() == type.Name); } catch (Exception) { From bd2c76e581b95f791c4cf4d50c21e6b875f9fd5c Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 29 Aug 2023 09:57:31 +0900 Subject: [PATCH 02/15] Bump Lib9c to feat/revise-staking --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 45c6a94ab..4557d10a5 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 45c6a94ab6c162d5771fa5dabaef160af2307b21 +Subproject commit 4557d10a576793d63563ff77d6e28a13135a00e9 From 3cf4ea4cc9d8b73bcbf56644fffd83ff2ab9332e Mon Sep 17 00:00:00 2001 From: moreal Date: Wed, 30 Aug 2023 11:28:44 +0900 Subject: [PATCH 03/15] Support `StakeStateV2` in GraphQL --- .../States/Models/StakeStateTypeTest.cs | 6 +- .../GraphTypes/StateQuery.cs | 20 +++- .../GraphTypes/States/StakeStateType.cs | 97 +++++++++++++++++-- 3 files changed, 109 insertions(+), 14 deletions(-) diff --git a/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs b/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs index a08ff0969..ad96debf9 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs @@ -36,7 +36,11 @@ public async Task Query(StakeState stakeState, long deposit, long blockIndex, Di claimableBlockIndex }"; var queryResult = await ExecuteQueryAsync( - query, source: new StakeStateType.StakeStateContext(stakeState, mockState, blockIndex)); + query, + source: new StakeStateType.StakeStateContext( + new StakeStateType.StakeStateContext.StakeStateWrapper(stakeState), + mockState, + blockIndex)); var data = (Dictionary)((ExecutionNode)queryResult.Data!).ToValue()!; Assert.Equal(expected, data); } diff --git a/NineChronicles.Headless/GraphTypes/StateQuery.cs b/NineChronicles.Headless/GraphTypes/StateQuery.cs index ed61ab8ba..b41390109 100644 --- a/NineChronicles.Headless/GraphTypes/StateQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StateQuery.cs @@ -13,6 +13,7 @@ using Nekoyume.Extensions; using Nekoyume.Model.Arena; using Nekoyume.Model.Item; +using Nekoyume.Model.Stake; using Nekoyume.Model.State; using Nekoyume.TableData; using Nekoyume.TableData.Crystal; @@ -239,10 +240,23 @@ public StateQuery() StakeStateType.StakeStateContext? GetStakeState(StateContext ctx, Address agentAddress) { - if (ctx.GetState(StakeState.DeriveAddress(agentAddress)) is Dictionary state) + var stakeStateAddress = StakeState.DeriveAddress(agentAddress); + var stakeStateValue = ctx.GetState(stakeStateAddress); + if (stakeStateValue is Dictionary dictionary) { return new StakeStateType.StakeStateContext( - new StakeState(state), + new StakeStateType.StakeStateContext.StakeStateWrapper(new StakeState(dictionary)), + ctx.AccountState, + ctx.BlockIndex + ); + } + + if (stakeStateValue is List list) + { + return new StakeStateType.StakeStateContext( + new StakeStateType.StakeStateContext.StakeStateWrapper( + new StakeStateV2(list), + stakeStateAddress), ctx.AccountState, ctx.BlockIndex ); @@ -252,7 +266,7 @@ public StateQuery() } Field( - name: nameof(StakeState), + name: "stakeState", description: "State for staking.", arguments: new QueryArguments(new QueryArgument> { diff --git a/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs b/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs index d7a4ee811..b4b5f4a2f 100644 --- a/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs @@ -1,9 +1,12 @@ using System; +using System.Collections.Generic; using Bencodex.Types; +using GraphQL; using GraphQL.Types; using Libplanet.Action; using Libplanet.Explorer.GraphTypes; using Libplanet.Action.State; +using Libplanet.Crypto; using Nekoyume.Model.State; using NineChronicles.Headless.GraphTypes.States.Models; using NineChronicles.Headless.GraphTypes.States.Models.World; @@ -12,6 +15,9 @@ using NineChronicles.Headless.GraphTypes.States.Models.Quest; using Nekoyume.Blockchain.Policy; using Nekoyume; +using Nekoyume.Model.Stake; +using Nekoyume.TableData; +using NineChronicles.Headless.GraphTypes.Abstractions; namespace NineChronicles.Headless.GraphTypes.States { @@ -19,38 +25,81 @@ public class StakeStateType : ObjectGraphType { public class StakeStateContext : StateContext { - public StakeStateContext(StakeState stakeState, IAccountState accountState, long blockIndex) + public class StakeStateWrapper + { + private readonly StakeState? _v1; + private readonly StakeStateV2? _v2; + private readonly Address? _v2Address; + + public StakeStateWrapper(StakeState stakeState) + { + _v1 = stakeState; + _v2 = null; + _v2Address = null; + } + + public StakeStateWrapper(StakeStateV2 stakeStateV2, Address stakeStateV2Address) + { + _v1 = null; + _v2 = stakeStateV2; + _v2Address = stakeStateV2Address; + } + + public long StartedBlockIndex => _v1?.StartedBlockIndex ?? + _v2?.StartedBlockIndex ?? throw new InvalidOperationException(); + + public long ReceivedBlockIndex => _v1?.ReceivedBlockIndex ?? + _v2?.ReceivedBlockIndex ?? throw new InvalidOperationException(); + + public long GetClaimableBlockIndex(long blockIndex) => _v1?.GetClaimableBlockIndex(blockIndex) ?? + _v2?.ClaimableBlockIndex ?? + throw new InvalidOperationException(); + + public long CancellableBlockIndex => _v1?.CancellableBlockIndex ?? + _v2?.CancellableBlockIndex ?? + throw new InvalidOperationException(); + + public StakeState.StakeAchievements? Achievements => _v1?.Achievements; + + public Address Address => _v1?.address ?? + _v2Address ?? + throw new InvalidOperationException(); + + public Contract? Contract => _v2?.Contract; + } + + public StakeStateContext(StakeStateWrapper stakeStateWrapper, IAccountState accountState, long blockIndex) : base(accountState, blockIndex) { - StakeState = stakeState; + StakeState = stakeStateWrapper; } - public StakeState StakeState { get; } + public StakeStateWrapper StakeState { get; } } public StakeStateType() { Field>( - nameof(StakeState.address), + "address", description: "The address of current state.", - resolve: context => context.Source.StakeState.address); + resolve: context => context.Source.StakeState.Address); Field>( "deposit", description: "The staked amount.", resolve: context => context.Source.AccountState.GetBalance( - context.Source.StakeState.address, + context.Source.StakeState.Address, new GoldCurrencyState((Dictionary)context.Source.GetState(GoldCurrencyState.Address)!).Currency) .GetQuantityString(true)); Field>( - nameof(StakeState.StartedBlockIndex), + "startedBlockIndex", description: "The block index the user started to stake.", resolve: context => context.Source.StakeState.StartedBlockIndex); Field>( - nameof(StakeState.ReceivedBlockIndex), + "receivedBlockIndex", description: "The block index the user received rewards.", resolve: context => context.Source.StakeState.ReceivedBlockIndex); Field>( - nameof(StakeState.CancellableBlockIndex), + "cancellableBlockIndex", description: "The block index the user can cancel the staking.", resolve: context => context.Source.StakeState.CancellableBlockIndex); Field>( @@ -58,10 +107,38 @@ public StakeStateType() description: "The block index the user can claim rewards.", resolve: context => context.Source.StakeState.GetClaimableBlockIndex( context.Source.BlockIndex)); - Field>( + Field( nameof(StakeState.Achievements), description: "The staking achievements.", resolve: context => context.Source.StakeState.Achievements); + Field( + "stakeRewards", + resolve: context => + { + if (context.Source.StakeState.Contract is not { } contract) + { + return null; + } + + IReadOnlyList values = context.Source.GetStates(new[] + { + Addresses.GetSheetAddress(contract.StakeRegularFixedRewardSheetTableName), + Addresses.GetSheetAddress(contract.StakeRegularRewardSheetTableName), + }); + + if (!(values[0] is Text fsv && values[1] is Text sv)) + { + throw new ExecutionError("Could not found stake rewards sheets"); + } + + StakeRegularFixedRewardSheet stakeRegularFixedRewardSheet = new StakeRegularFixedRewardSheet(); + StakeRegularRewardSheet stakeRegularRewardSheet = new StakeRegularRewardSheet(); + stakeRegularFixedRewardSheet.Set(fsv); + stakeRegularRewardSheet.Set(sv); + + return (stakeRegularRewardSheet, stakeRegularFixedRewardSheet); + } + ); } } } From f8a750853a6acae4d7b5bc5c85c0ee48ca8065ab Mon Sep 17 00:00:00 2001 From: moreal Date: Wed, 30 Aug 2023 11:32:38 +0900 Subject: [PATCH 04/15] Provide a new `latestStakeRewards` field --- .../GraphTypes/StateQuery.cs | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/StateQuery.cs b/NineChronicles.Headless/GraphTypes/StateQuery.cs index b41390109..9f1ca1c69 100644 --- a/NineChronicles.Headless/GraphTypes/StateQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StateQuery.cs @@ -17,6 +17,7 @@ using Nekoyume.Model.State; using Nekoyume.TableData; using Nekoyume.TableData.Crystal; +using Nekoyume.TableData.Stake; using NineChronicles.Headless.GraphTypes.Abstractions; using NineChronicles.Headless.GraphTypes.States; using NineChronicles.Headless.GraphTypes.States.Models; @@ -352,8 +353,42 @@ public StateQuery() } ); + Field( + "latestStakeRewards", + description: "The latest stake rewards based on StakePolicySheet.", + resolve: context => + { + var stakePolicySheetStateValue = context.Source.GetState(Addresses.GetSheetAddress()); + var stakePolicySheet = new StakePolicySheet(); + if (stakePolicySheetStateValue is not Text stakePolicySheetStateText) + { + return null; + } + + stakePolicySheet.Set(stakePolicySheetStateText); + + IReadOnlyList values = context.Source.GetStates(new[] + { + Addresses.GetSheetAddress(stakePolicySheet["StakeRegularFixedRewardSheet"].Value), + Addresses.GetSheetAddress(stakePolicySheet["StakeRegularRewardSheet"].Value), + }); + + if (!(values[0] is Text fsv && values[1] is Text sv)) + { + return null; + } + + var stakeRegularFixedRewardSheet = new StakeRegularFixedRewardSheet(); + var stakeRegularRewardSheet = new StakeRegularRewardSheet(); + stakeRegularFixedRewardSheet.Set(fsv); + stakeRegularRewardSheet.Set(sv); + + return (stakeRegularRewardSheet, stakeRegularFixedRewardSheet); + } + ); Field( "stakeRewards", + deprecationReason: "Since stake3, claim_stake_reward9 actions, each stakers have their own contracts.", resolve: context => { StakeRegularRewardSheet stakeRegularRewardSheet; @@ -362,9 +397,9 @@ public StateQuery() if (context.Source.BlockIndex < StakeState.StakeRewardSheetV2Index) { stakeRegularRewardSheet = new StakeRegularRewardSheet(); - stakeRegularRewardSheet.Set(ClaimStakeReward.V1.StakeRegularRewardSheetCsv); + stakeRegularRewardSheet.Set(ClaimStakeReward8.V1.StakeRegularRewardSheetCsv); stakeRegularFixedRewardSheet = new StakeRegularFixedRewardSheet(); - stakeRegularFixedRewardSheet.Set(ClaimStakeReward.V1.StakeRegularFixedRewardSheetCsv); + stakeRegularFixedRewardSheet.Set(ClaimStakeReward8.V1.StakeRegularFixedRewardSheetCsv); } else { From 5e8b27703ec28c95a4e0d15b80597994b8e8de25 Mon Sep 17 00:00:00 2001 From: moreal Date: Thu, 31 Aug 2023 07:44:55 +0900 Subject: [PATCH 05/15] Update testcases for obsolete claim_stake_reward8 --- .../Commands/ActionCommandTest.cs | 4 +++- NineChronicles.Headless.Executable/Commands/TxCommand.cs | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs index 8721e29b7..fde83dba4 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs @@ -198,7 +198,9 @@ public void ClaimStakeReward(string addressString, int expectedCode) [InlineData(ClaimStakeReward6.ObsoleteBlockIndex, typeof(ClaimStakeReward6))] [InlineData(ClaimStakeReward6.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward7))] [InlineData(ClaimStakeReward7.ObsoleteBlockIndex, typeof(ClaimStakeReward7))] - [InlineData(ClaimStakeReward7.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward))] + [InlineData(ClaimStakeReward7.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward8))] + [InlineData(ClaimStakeReward8.ObsoleteBlockIndex, typeof(ClaimStakeReward8))] + [InlineData(ClaimStakeReward8.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward))] [InlineData(long.MaxValue, typeof(ClaimStakeReward))] public void ClaimStakeRewardWithBlockIndex(long blockIndex, Type expectedActionType) { diff --git a/NineChronicles.Headless.Executable/Commands/TxCommand.cs b/NineChronicles.Headless.Executable/Commands/TxCommand.cs index 235d2a96c..88bef4faa 100644 --- a/NineChronicles.Headless.Executable/Commands/TxCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/TxCommand.cs @@ -76,6 +76,7 @@ public void Sign( nameof(ClaimStakeReward4) => new ClaimStakeReward4(), nameof(ClaimStakeReward5) => new ClaimStakeReward5(), nameof(ClaimStakeReward7) => new ClaimStakeReward7(), + nameof(ClaimStakeReward8) => new ClaimStakeReward8(), nameof(ClaimStakeReward) => new ClaimStakeReward(), nameof(TransferAsset) => new TransferAsset(), nameof(MigrateMonsterCollection) => new MigrateMonsterCollection(), From 157ccbebcdb73f7b1d7fffe5e5a5eaf4936b582f Mon Sep 17 00:00:00 2001 From: moreal Date: Thu, 31 Aug 2023 07:45:09 +0900 Subject: [PATCH 06/15] Bump Lib9c --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 4557d10a5..2453c0861 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 4557d10a576793d63563ff77d6e28a13135a00e9 +Subproject commit 2453c08616fb7b818bf854fb29e248b629746cce From 6fd7184b05deaf3d82ed84849bcb759f6f4738cf Mon Sep 17 00:00:00 2001 From: moreal Date: Thu, 31 Aug 2023 10:37:14 +0900 Subject: [PATCH 07/15] Fix tests --- .../Commands/ActionCommandTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs index fde83dba4..a0745ed60 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/ActionCommandTest.cs @@ -226,8 +226,8 @@ public void ClaimStakeRewardWithBlockIndex(long blockIndex, Type expectedActionT [Theory] [InlineData(0, 0, -1)] - [InlineData(1, 8, 0)] - [InlineData(9, 9, -1)] + [InlineData(1, 9, 0)] + [InlineData(10, 10, -1)] public void ClaimStakeRewardWithActionVersion( int actionVersionMin, int actionVersionMax, From 7eb52176ac1e3a1a5409ad2cb637b524942c2a86 Mon Sep 17 00:00:00 2001 From: moreal Date: Fri, 1 Sep 2023 14:03:27 +0900 Subject: [PATCH 08/15] Bump Lib9c --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 2453c0861..a1d92a3a1 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 2453c08616fb7b818bf854fb29e248b629746cce +Subproject commit a1d92a3a12e4d93606e6a9dac52a4ed1692406fa From e142d848e6f032d156176543c13d2fc8ef3db5e0 Mon Sep 17 00:00:00 2001 From: moreal Date: Fri, 1 Sep 2023 14:20:55 +0900 Subject: [PATCH 09/15] Use only StakeStateV2 - Deprecate `StakeStateType.Achievements` --- .../GraphTypes/StateQuery.cs | 19 ++---- .../GraphTypes/States/StakeStateType.cs | 63 ++++--------------- 2 files changed, 15 insertions(+), 67 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/StateQuery.cs b/NineChronicles.Headless/GraphTypes/StateQuery.cs index 9f1ca1c69..dd361c163 100644 --- a/NineChronicles.Headless/GraphTypes/StateQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StateQuery.cs @@ -242,25 +242,14 @@ public StateQuery() StakeStateType.StakeStateContext? GetStakeState(StateContext ctx, Address agentAddress) { var stakeStateAddress = StakeState.DeriveAddress(agentAddress); - var stakeStateValue = ctx.GetState(stakeStateAddress); - if (stakeStateValue is Dictionary dictionary) + if (ctx.AccountState.TryGetStakeStateV2(stakeStateAddress, out StakeStateV2 stakeStateV2)) { return new StakeStateType.StakeStateContext( - new StakeStateType.StakeStateContext.StakeStateWrapper(new StakeState(dictionary)), + stakeStateV2, + stakeStateAddress, ctx.AccountState, ctx.BlockIndex - ); - } - - if (stakeStateValue is List list) - { - return new StakeStateType.StakeStateContext( - new StakeStateType.StakeStateContext.StakeStateWrapper( - new StakeStateV2(list), - stakeStateAddress), - ctx.AccountState, - ctx.BlockIndex - ); + ); } return null; diff --git a/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs b/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs index b4b5f4a2f..a5435dbdf 100644 --- a/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs @@ -25,56 +25,15 @@ public class StakeStateType : ObjectGraphType { public class StakeStateContext : StateContext { - public class StakeStateWrapper - { - private readonly StakeState? _v1; - private readonly StakeStateV2? _v2; - private readonly Address? _v2Address; - - public StakeStateWrapper(StakeState stakeState) - { - _v1 = stakeState; - _v2 = null; - _v2Address = null; - } - - public StakeStateWrapper(StakeStateV2 stakeStateV2, Address stakeStateV2Address) - { - _v1 = null; - _v2 = stakeStateV2; - _v2Address = stakeStateV2Address; - } - - public long StartedBlockIndex => _v1?.StartedBlockIndex ?? - _v2?.StartedBlockIndex ?? throw new InvalidOperationException(); - - public long ReceivedBlockIndex => _v1?.ReceivedBlockIndex ?? - _v2?.ReceivedBlockIndex ?? throw new InvalidOperationException(); - - public long GetClaimableBlockIndex(long blockIndex) => _v1?.GetClaimableBlockIndex(blockIndex) ?? - _v2?.ClaimableBlockIndex ?? - throw new InvalidOperationException(); - - public long CancellableBlockIndex => _v1?.CancellableBlockIndex ?? - _v2?.CancellableBlockIndex ?? - throw new InvalidOperationException(); - - public StakeState.StakeAchievements? Achievements => _v1?.Achievements; - - public Address Address => _v1?.address ?? - _v2Address ?? - throw new InvalidOperationException(); - - public Contract? Contract => _v2?.Contract; - } - - public StakeStateContext(StakeStateWrapper stakeStateWrapper, IAccountState accountState, long blockIndex) + public StakeStateContext(StakeStateV2 stakeState, Address address, IAccountState accountState, long blockIndex) : base(accountState, blockIndex) { - StakeState = stakeStateWrapper; + StakeState = stakeState; + Address = address; } - public StakeStateWrapper StakeState { get; } + public StakeStateV2 StakeState { get; } + public Address Address { get; } } public StakeStateType() @@ -82,12 +41,12 @@ public StakeStateType() Field>( "address", description: "The address of current state.", - resolve: context => context.Source.StakeState.Address); + resolve: context => context.Source.Address); Field>( "deposit", description: "The staked amount.", resolve: context => context.Source.AccountState.GetBalance( - context.Source.StakeState.Address, + context.Source.Address, new GoldCurrencyState((Dictionary)context.Source.GetState(GoldCurrencyState.Address)!).Currency) .GetQuantityString(true)); Field>( @@ -105,13 +64,13 @@ public StakeStateType() Field>( "claimableBlockIndex", description: "The block index the user can claim rewards.", - resolve: context => context.Source.StakeState.GetClaimableBlockIndex( - context.Source.BlockIndex)); + resolve: context => context.Source.StakeState.ClaimableBlockIndex); Field( nameof(StakeState.Achievements), description: "The staking achievements.", - resolve: context => context.Source.StakeState.Achievements); - Field( + deprecationReason: "Since StakeStateV2, the achievement became removed.", + resolve: _ => null); + Field>( "stakeRewards", resolve: context => { From 5dc2ef1876f7c5f202b451c9c69a6ef972f32cc6 Mon Sep 17 00:00:00 2001 From: moreal Date: Fri, 1 Sep 2023 14:22:07 +0900 Subject: [PATCH 10/15] Use valid GraphQL types by the fields --- NineChronicles.Headless/GraphTypes/States/StakeStateType.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs b/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs index a5435dbdf..50deeb03d 100644 --- a/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/StakeStateType.cs @@ -49,11 +49,11 @@ public StakeStateType() context.Source.Address, new GoldCurrencyState((Dictionary)context.Source.GetState(GoldCurrencyState.Address)!).Currency) .GetQuantityString(true)); - Field>( + Field>( "startedBlockIndex", description: "The block index the user started to stake.", resolve: context => context.Source.StakeState.StartedBlockIndex); - Field>( + Field>( "receivedBlockIndex", description: "The block index the user received rewards.", resolve: context => context.Source.StakeState.ReceivedBlockIndex); From 40dca5525a13314db466099d8565a06d6f8e5c8d Mon Sep 17 00:00:00 2001 From: moreal Date: Fri, 1 Sep 2023 16:28:58 +0900 Subject: [PATCH 11/15] Support Mead in transferAsset actionQuery --- NineChronicles.Headless/GraphTypes/CurrencyEnumType.cs | 1 + NineChronicles.Headless/Utils/CurrencyFactory.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/NineChronicles.Headless/GraphTypes/CurrencyEnumType.cs b/NineChronicles.Headless/GraphTypes/CurrencyEnumType.cs index a3f91ac4b..ef6745ea3 100644 --- a/NineChronicles.Headless/GraphTypes/CurrencyEnumType.cs +++ b/NineChronicles.Headless/GraphTypes/CurrencyEnumType.cs @@ -9,6 +9,7 @@ public enum CurrencyEnum CRYSTAL, NCG, GARAGE, + MEAD } public class CurrencyEnumType : EnumerationGraphType diff --git a/NineChronicles.Headless/Utils/CurrencyFactory.cs b/NineChronicles.Headless/Utils/CurrencyFactory.cs index 3bba7b27c..e40359914 100644 --- a/NineChronicles.Headless/Utils/CurrencyFactory.cs +++ b/NineChronicles.Headless/Utils/CurrencyFactory.cs @@ -32,6 +32,7 @@ public bool TryGetCurrency(string ticker, out Currency currency) var result = ticker switch { "NCG" => GetNCG(), + "MEAD" => Currencies.Mead, _ => Currencies.GetMinterlessCurrency(ticker), }; if (result is null) From a45c5c7397efb9d46df7e5dcc365b605c10e60f1 Mon Sep 17 00:00:00 2001 From: moreal Date: Fri, 1 Sep 2023 17:02:39 +0900 Subject: [PATCH 12/15] Correct StakeTypeTest testcases --- .../States/Models/StakeStateTypeTest.cs | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs b/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs index ad96debf9..d2f91c95d 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/States/Models/StakeStateTypeTest.cs @@ -1,9 +1,12 @@ using System.Collections.Generic; using System.Threading.Tasks; using GraphQL.Execution; +using Libplanet.Crypto; using Libplanet.Types.Assets; using Nekoyume; +using Nekoyume.Model.Stake; using Nekoyume.Model.State; +using Nekoyume.TableData; using NineChronicles.Headless.GraphTypes.States; using NineChronicles.Headless.Tests.Common; using Xunit; @@ -15,7 +18,7 @@ public class StakeStateTypeTest { [Theory] [MemberData(nameof(Members))] - public async Task Query(StakeState stakeState, long deposit, long blockIndex, Dictionary expected) + public async Task Query(StakeStateV2 stakeState, Address stakeStateAddress, long deposit, long blockIndex, Dictionary expected) { #pragma warning disable CS0618 // Use of obsolete method Currency.Legacy(): https://github.com/planetarium/lib9c/discussions/1319 @@ -38,7 +41,8 @@ public async Task Query(StakeState stakeState, long deposit, long blockIndex, Di var queryResult = await ExecuteQueryAsync( query, source: new StakeStateType.StakeStateContext( - new StakeStateType.StakeStateContext.StakeStateWrapper(stakeState), + stakeState, + stakeStateAddress, mockState, blockIndex)); var data = (Dictionary)((ExecutionNode)queryResult.Data!).ToValue()!; @@ -49,76 +53,83 @@ public async Task Query(StakeState stakeState, long deposit, long blockIndex, Di { new object[] { - new StakeState(Fixtures.StakeStateAddress, 0), + new StakeStateV2( + new Contract("StakeRegularFixedRewardSheet_V1", "StakeRegularRewardSheet_V1", 50400, 201600), 0), + Fixtures.StakeStateAddress, 100, 0, new Dictionary { ["address"] = Fixtures.StakeStateAddress.ToString(), ["deposit"] = "100.00", - ["startedBlockIndex"] = 0, + ["startedBlockIndex"] = 0L, ["cancellableBlockIndex"] = StakeState.LockupInterval, - ["receivedBlockIndex"] = 0, - ["claimableBlockIndex"] = 0 + StakeState.RewardInterval, + ["receivedBlockIndex"] = 0L, + ["claimableBlockIndex"] = 0L + StakeState.RewardInterval, } }, new object[] { - new StakeState(Fixtures.StakeStateAddress, 100), + new StakeStateV2(new Contract("StakeRegularFixedRewardSheet_V1", "StakeRegularRewardSheet_V1", 50400, 201600), 100), + Fixtures.StakeStateAddress, 100, 0, new Dictionary { ["address"] = Fixtures.StakeStateAddress.ToString(), ["deposit"] = "100.00", - ["startedBlockIndex"] = 100, + ["startedBlockIndex"] = 100L, ["cancellableBlockIndex"] = 100 + StakeState.LockupInterval, - ["receivedBlockIndex"] = 0, + ["receivedBlockIndex"] = 0L, ["claimableBlockIndex"] = 100 + StakeState.RewardInterval, } }, new object[] { - new StakeState(Fixtures.StakeStateAddress, 100), + new StakeStateV2(new Contract("StakeRegularFixedRewardSheet_V1", "StakeRegularRewardSheet_V1", 50400, 201600), 100), + Fixtures.StakeStateAddress, 100, 0, new Dictionary { ["address"] = Fixtures.StakeStateAddress.ToString(), ["deposit"] = "100.00", - ["startedBlockIndex"] = 100, + ["startedBlockIndex"] = 100L, ["cancellableBlockIndex"] = StakeState.LockupInterval + 100, - ["receivedBlockIndex"] = 0, + ["receivedBlockIndex"] = 0L, ["claimableBlockIndex"] = StakeState.RewardInterval + 100, } }, new object[] { - new StakeState(Fixtures.StakeStateAddress, 10, 50412, 201610, new StakeState.StakeAchievements()), + new StakeStateV2( + new Contract("StakeRegularFixedRewardSheet_V1", "StakeRegularRewardSheet_V1", 50400, 201600), 10, 50412), + Fixtures.StakeStateAddress, 100, 0, new Dictionary { ["address"] = Fixtures.StakeStateAddress.ToString(), ["deposit"] = "100.00", - ["startedBlockIndex"] = 10, + ["startedBlockIndex"] = 10L, ["cancellableBlockIndex"] = 201610L, - ["receivedBlockIndex"] = 50412, - ["claimableBlockIndex"] = 100812L, + ["receivedBlockIndex"] = 50412L, + ["claimableBlockIndex"] = 100810L, } }, new object[] { - new StakeState(Fixtures.StakeStateAddress, 10, 50412, 201610, new StakeState.StakeAchievements()), + new StakeStateV2(new Contract("StakeRegularFixedRewardSheet_V1", "StakeRegularRewardSheet_V1", 50400, 201600), 10, 50412), + Fixtures.StakeStateAddress, 100, ActionObsoleteConfig.V100290ObsoleteIndex, new Dictionary { ["address"] = Fixtures.StakeStateAddress.ToString(), ["deposit"] = "100.00", - ["startedBlockIndex"] = 10, + ["startedBlockIndex"] = 10L, ["cancellableBlockIndex"] = 201610L, - ["receivedBlockIndex"] = 50412, + ["receivedBlockIndex"] = 50412L, ["claimableBlockIndex"] = 100810L, } } From c7d6bc5fc17064946a1144f5bf47568e72bece97 Mon Sep 17 00:00:00 2001 From: moreal Date: Fri, 1 Sep 2023 17:06:46 +0900 Subject: [PATCH 13/15] Apply `dotnet format` --- NineChronicles.Headless/GraphTypes/StateQuery.cs | 2 +- NineChronicles.Headless/Utils/CurrencyFactory.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/StateQuery.cs b/NineChronicles.Headless/GraphTypes/StateQuery.cs index dd361c163..c46f0f529 100644 --- a/NineChronicles.Headless/GraphTypes/StateQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StateQuery.cs @@ -249,7 +249,7 @@ public StateQuery() stakeStateAddress, ctx.AccountState, ctx.BlockIndex - ); + ); } return null; diff --git a/NineChronicles.Headless/Utils/CurrencyFactory.cs b/NineChronicles.Headless/Utils/CurrencyFactory.cs index e40359914..2c2945bf4 100644 --- a/NineChronicles.Headless/Utils/CurrencyFactory.cs +++ b/NineChronicles.Headless/Utils/CurrencyFactory.cs @@ -32,7 +32,7 @@ public bool TryGetCurrency(string ticker, out Currency currency) var result = ticker switch { "NCG" => GetNCG(), - "MEAD" => Currencies.Mead, + "MEAD" => Currencies.Mead, _ => Currencies.GetMinterlessCurrency(ticker), }; if (result is null) From 04db41ee91ef076fe576ff5a29e5a1be7e1e197f Mon Sep 17 00:00:00 2001 From: moreal Date: Mon, 4 Sep 2023 15:16:14 +0900 Subject: [PATCH 14/15] Fix misusage of TryGetStakeStateV2 --- NineChronicles.Headless/GraphTypes/StateQuery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NineChronicles.Headless/GraphTypes/StateQuery.cs b/NineChronicles.Headless/GraphTypes/StateQuery.cs index c46f0f529..8ce7407b8 100644 --- a/NineChronicles.Headless/GraphTypes/StateQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StateQuery.cs @@ -242,7 +242,7 @@ public StateQuery() StakeStateType.StakeStateContext? GetStakeState(StateContext ctx, Address agentAddress) { var stakeStateAddress = StakeState.DeriveAddress(agentAddress); - if (ctx.AccountState.TryGetStakeStateV2(stakeStateAddress, out StakeStateV2 stakeStateV2)) + if (ctx.AccountState.TryGetStakeStateV2(agentAddr: agentAddress, out StakeStateV2 stakeStateV2)) { return new StakeStateType.StakeStateContext( stakeStateV2, From 0179411b73748dee6c77c6ccdb1a3187418b8b6f Mon Sep 17 00:00:00 2001 From: moreal Date: Wed, 6 Sep 2023 07:07:14 +0900 Subject: [PATCH 15/15] Bump lib9c --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index b4fbea61c..9fb67c2f0 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit b4fbea61c9adbe9d70640075e01ab37503e92197 +Subproject commit 9fb67c2f0f4c96f71068eae86e72972852eb8867