diff --git a/NineChronicles.Headless/GraphTypes/ActionMutation.cs b/NineChronicles.Headless/GraphTypes/ActionMutation.cs index 73fa984d3..457108dab 100644 --- a/NineChronicles.Headless/GraphTypes/ActionMutation.cs +++ b/NineChronicles.Headless/GraphTypes/ActionMutation.cs @@ -601,12 +601,12 @@ public ActionMutation(NineChroniclesNodeService service) ); Field>("stake", - description: "Claim reward for self delegation of validator.", + description: "Stake the NCG.", arguments: new QueryArguments( new QueryArgument> { Name = "amount", - Description = "Amount to stake." + Description = "Total amount of NCG to stake." } ), resolve: context => @@ -731,12 +731,12 @@ public ActionMutation(NineChroniclesNodeService service) } ); Field>("delegateValidator", - description: "Unjail validator", + description: "Delegate Validator", arguments: new QueryArguments( new QueryArgument> { Name = "amount", - Description = "Amount of guild gold to stake." + Description = "Amount of guild gold to delegate." } ), resolve: context => @@ -767,6 +767,77 @@ public ActionMutation(NineChroniclesNodeService service) } } ); + Field>("undelegateValidator", + description: "Undelegate validator", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "share", + Description = "Share to undelegate." + } + ), + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + BigInteger share = context.GetArgument("amount"); + var actions = new[] { new UndelegateValidator(share) }; + 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; + } + } + ); + Field>("claimStakeReward", + description: "Claim Stake Reward", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "avatarAddress", + Description = "Avatar address to claim stake reward." + } + ), + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var actions = new[] { new ClaimStakeReward() }; + 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; + } + } + ); } } }