From 1789953d4af9c9ad78b5c7ebe28270fb6ecf0e32 Mon Sep 17 00:00:00 2001 From: s2quake Date: Thu, 21 Nov 2024 15:10:03 +0900 Subject: [PATCH] feat: Add delegateValidator action mutation --- .../GraphTypes/ActionMutation.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/NineChronicles.Headless/GraphTypes/ActionMutation.cs b/NineChronicles.Headless/GraphTypes/ActionMutation.cs index 9fecf836f..6fb5820f6 100644 --- a/NineChronicles.Headless/GraphTypes/ActionMutation.cs +++ b/NineChronicles.Headless/GraphTypes/ActionMutation.cs @@ -702,6 +702,43 @@ public ActionMutation(NineChroniclesNodeService service) } } ); + Field>("delegateValidator", + description: "Unjail validator", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "amount", + Description = "Amount of guild gold to stake." + } + ), + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + BigInteger amount = context.GetArgument("amount"); + var fav = new FungibleAssetValue(ValidatorDelegatee.ValidatorDelegationCurrency, amount, 0); + var actions = new[] { new DelegateValidator(fav) }; + Transaction tx = blockChain.MakeTransaction( + service.MinerPrivateKey, + actions, + Currencies.Mead * 1, + 1L); + return tx.Id; + } + catch (Exception e) + { + var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; + context.Errors.Add(new ExecutionError(msg, e)); + throw; + } + } + ); } } }