-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Remove installed kitchen equipment action & query
- Loading branch information
Showing
4 changed files
with
152 additions
and
10 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
backend/app/Savor22b/Action/RemoveInstalledKitchenEquipmentAction.cs
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,56 @@ | ||
namespace Savor22b.Action; | ||
|
||
using Libplanet.Action; | ||
using Savor22b.States; | ||
using Savor22b.Action.Util; | ||
using System.Collections.Immutable; | ||
using Bencodex.Types; | ||
using Libplanet.Headless.Extensions; | ||
using Libplanet.State; | ||
|
||
[ActionType(nameof(RemoveInstalledKitchenEquipmentAction))] | ||
public class RemoveInstalledKitchenEquipmentAction : SVRAction | ||
{ | ||
public RemoveInstalledKitchenEquipmentAction() { } | ||
|
||
public RemoveInstalledKitchenEquipmentAction(Guid installedEquipmentStateId) | ||
{ | ||
InstalledEquipmentStateId = installedEquipmentStateId; | ||
} | ||
|
||
public Guid InstalledEquipmentStateId { get; private set; } | ||
|
||
protected override IImmutableDictionary<string, IValue> PlainValueInternal => | ||
new Dictionary<string, IValue>() | ||
{ | ||
[nameof(InstalledEquipmentStateId)] = InstalledEquipmentStateId.Serialize(), | ||
}.ToImmutableDictionary(); | ||
|
||
protected override void LoadPlainValueInternal(IImmutableDictionary<string, IValue> plainValue) | ||
{ | ||
InstalledEquipmentStateId = plainValue[nameof(InstalledEquipmentStateId)].ToGuid(); | ||
} | ||
|
||
public override IAccountStateDelta Execute(IActionContext ctx) | ||
{ | ||
if (ctx.Rehearsal) | ||
{ | ||
return ctx.PreviousStates; | ||
} | ||
|
||
IAccountStateDelta states = ctx.PreviousStates; | ||
|
||
RootState rootState = states.GetState(ctx.Signer) is Dictionary rootStateEncoded | ||
? new RootState(rootStateEncoded) | ||
: new RootState(); | ||
|
||
Validation.EnsureReplaceInProgress(rootState, ctx.BlockIndex); | ||
Validation.EnsureVillageStateExists(rootState); | ||
|
||
KitchenState kitchenState = rootState.VillageState!.HouseState.KitchenState; | ||
|
||
kitchenState.RemoveInstalledEquipment(InstalledEquipmentStateId); | ||
|
||
return states.SetState(ctx.Signer, rootState.Serialize()); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
backend/app/Savor22b/GraphTypes/Query/RemoveInstalledKitchenEquipmentActionQuery.cs
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,56 @@ | ||
namespace Savor22b.GraphTypes.Query; | ||
|
||
using GraphQL; | ||
using GraphQL.Resolvers; | ||
using GraphQL.Types; | ||
using Libplanet.Blockchain; | ||
using Libplanet.Crypto; | ||
using Libplanet.Net; | ||
using Savor22b.Action; | ||
|
||
public class RemoveInstalledKitchenEquipmentActionQuery : FieldType | ||
{ | ||
public RemoveInstalledKitchenEquipmentActionQuery(BlockChain blockChain, Swarm swarm) | ||
: base() | ||
{ | ||
Name = "createAction_RemoveInstalledKitchenEquipmentActionQuery"; | ||
Type = typeof(NonNullGraphType<StringGraphType>); | ||
Description = "설치된 큰 조리도구를 설치 제거합니다."; | ||
Arguments = new QueryArguments( | ||
new QueryArgument<NonNullGraphType<StringGraphType>> | ||
{ | ||
Name = "publicKey", | ||
Description = "대상 유저의 40-hex 형태의 address 입니다.", | ||
}, | ||
new QueryArgument<NonNullGraphType<GuidGraphType>> | ||
{ | ||
Name = "installedEquipmentStateId", | ||
Description = "제거하려는 설치된 큰 조리도구의 State Id(Guid) 입니다.", | ||
} | ||
); | ||
Resolver = new FuncFieldResolver<string>(context => | ||
{ | ||
try | ||
{ | ||
var publicKey = new PublicKey( | ||
Libplanet.ByteUtil.ParseHex(context.GetArgument<string>("publicKey")) | ||
); | ||
var action = new RemoveInstalledKitchenEquipmentAction( | ||
context.GetArgument<Guid>("installedEquipmentStateId") | ||
); | ||
return new GetUnsignedTransactionHex( | ||
action, | ||
publicKey, | ||
blockChain, | ||
swarm | ||
).UnsignedTransactionHex; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new ExecutionError(e.Message); | ||
} | ||
}); | ||
} | ||
} |
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