diff --git a/NineChronicles.Headless/GraphTypes/ActionMutation.cs b/NineChronicles.Headless/GraphTypes/ActionMutation.cs index 053b6ed9c..4226a817a 100644 --- a/NineChronicles.Headless/GraphTypes/ActionMutation.cs +++ b/NineChronicles.Headless/GraphTypes/ActionMutation.cs @@ -454,6 +454,439 @@ public ActionMutation(NineChroniclesNodeService service) } } ); + + Field>("promoteValidator", + description: "Promote validator.", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "validator", + Description = "Validator public key to promote." + }, + new QueryArgument> + { + Name = "amount", + Description = "Amount of NCG to stake." + } + ), + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + string validatorString = context.GetArgument("validator"); + PublicKey validator = PublicKey.FromHex(validatorString); + BigInteger amount = context.GetArgument("amount"); + var fav = new FungibleAssetValue(ValidatorDelegatee.ValidatorDelegationCurrency, amount, 0); + var action = new PromoteValidator(validator, fav); + var actions = new[] { action }; + 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>("transferNCG", + description: "Transfer ncg to validtor to promote.", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "validator", + Description = "Validator public key to promote." + }, + new QueryArgument> + { + Name = "amount", + Description = "Amount of NCG to stake." + } + ), + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var amount = context.GetArgument("amount"); + var sender = service.MinerPrivateKey!.Address; + var recipient = context.GetArgument
("validator"); + var currency = blockChain.GetWorldState().GetGoldCurrency(); + var fav = currency * amount; + +#pragma warning disable CS0618 + var actions = new[] { new TransferAsset(sender, recipient, fav, "To promote") }; +#pragma warning restore CS0618 + + Transaction tx = blockChain.MakeTransaction( + service.MinerPrivateKey, + actions, + Currencies.Mead * 4, + 4L); + return tx.Id; + } + catch (Exception e) + { + var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; + context.Errors.Add(new ExecutionError(msg, e)); + throw; + } + } + ); + + Field>("transferMead", + description: "Transfer ncg to validtor to promote.", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "validator", + Description = "Validator public key to promote." + }, + new QueryArgument> + { + Name = "amount", + Description = "Amount of NCG to stake." + } + ), + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var amount = context.GetArgument("amount"); + var sender = service.MinerPrivateKey!.Address; + var recipient = context.GetArgument
("validator"); + var fav = Currencies.Mead * amount; + +#pragma warning disable CS0618 + var actions = new[] { new TransferAsset(sender, recipient, fav, "To promote") }; +#pragma warning restore CS0618 + + Transaction tx = blockChain.MakeTransaction( + service.MinerPrivateKey, + actions, + Currencies.Mead * 4, + 4L); + return tx.Id; + } + catch (Exception e) + { + var msg = $"Unexpected exception occurred during {typeof(ActionMutation)}: {e}"; + context.Errors.Add(new ExecutionError(msg, e)); + throw; + } + } + ); + + Field>("stake", + description: "Stake the NCG.", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "amount", + Description = "Total amount of NCG 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 actions = new[] { new Stake(amount) }; + 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>("migrateDelegationHeight", + description: "Migration of delegation height.", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "height", + Description = "Height to migrate." + } + ), + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + long height = context.GetArgument("height"); + + var actions = new[] { new MigrateDelegationHeight(height) }; + 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>("migratePlanetariumValidator", + description: "Migration Planetarium Validator", + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var actions = new[] { new MigratePlanetariumValidator() }; + 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>("migratePlanetariumGuild", + description: "Migrate Planetarium Guild", + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var actions = new[] { new MigratePlanetariumGuild() }; + 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>("unjailValidator", + description: "Unjail validator", + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var actions = new[] { new UnjailValidator() }; + 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>("delegateValidator", + description: "Delegate Validator", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "amount", + Description = "Amount of guild gold to delegate." + } + ), + 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; + } + } + ); + 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."); + } + + var shareString = context.GetArgument("share"); + var share = BigInteger.Parse(shareString); + 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>("claimValidatorRewardSelf", + description: "Claim Validator Reward Self", + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var actions = new[] { new ClaimValidatorRewardSelf() }; + 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>("setValidatorCommission", + description: "Set Validator Commission", + resolve: context => + { + try + { + BlockChain? blockChain = service.BlockChain; + if (blockChain is null) + { + throw new InvalidOperationException($"{nameof(blockChain)} is null."); + } + + var actions = new[] { new SetValidatorCommission() }; + 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; + } + } + ); } } }