예제 #1
0
        private void BecomeStaker(BigInteger stakeAmount)
        {
            Logger.LogInformation("BecomeStaker");
            var tx = _transactionBuilder.InvokeTransaction(
                _systemContractReader.NodeAddress(),
                ContractRegisterer.StakingContract,
                Money.Zero,
                StakingInterface.MethodBecomeStaker,
                _systemContractReader.NodePublicKey(),
                (object)stakeAmount.ToUInt256()
                );

            AddTxToPool(tx);
        }
예제 #2
0
        private JObject GetAccount(string?address = null)
        {
            address ??= _systemContractReader.NodeAddress().ToHex();
            var publicKey      = _systemContractReader.NodePublicKey().ToHex();
            var addressUint160 = address.HexToBytes().ToUInt160();
            var balance        =
                _stateManager.LastApprovedSnapshot.Balances.GetBalance(addressUint160);

            var staked             = _systemContractReader.GetStake(addressUint160).ToMoney();
            var staking            = _systemContractReader.GetStakerTotalStake(addressUint160).ToMoney();
            var penalty            = _systemContractReader.GetPenalty(addressUint160).ToMoney();
            var isCurrentValidator = _stateManager.CurrentSnapshot.Validators
                                     .GetValidatorsPublicKeys().Any(pk =>
                                                                    pk.Buffer.ToByteArray().SequenceEqual(_systemContractReader.NodePublicKey()));
            var isNextValidator     = _systemContractReader.IsNextValidator();
            var isPreviousValidator = _systemContractReader.IsPreviousValidator();
            var isAbleToBeValidator = _systemContractReader.IsAbleToBeValidator();
            var isStaker            = !_systemContractReader.GetStake().IsZero();
            var isAbleToBeStaker    = balance.ToWei() > StakingContract.TokenUnitsInRoll;

            var isWalletLocked = _privateWallet.IsLocked();

            var withdrawTriggered = _validatorStatusManager.IsWithdrawTriggered();
            var isValidatorStatusManagerActive = _validatorStatusManager.IsStarted();
            var withdrawRequestCycle           = _systemContractReader.GetWithdrawRequestCycle();

            string state;

            if (isValidatorStatusManagerActive && withdrawTriggered)
            {
                if (isNextValidator)
                {
                    state = "StakeReserved";
                }
                else if (withdrawRequestCycle == 0)
                {
                    state = "SubmittingWithdrawRequest";
                }
                else
                {
                    state = "WaitingForTheNextCycleToWithdraw";
                }
            }
            else if (isCurrentValidator)
            {
                state = "Validator";
            }
            else if (isNextValidator)
            {
                state = "NextValidator";
            }
            else if (isAbleToBeValidator)
            {
                state = "AbleToBeValidator";
            }
            else if (isPreviousValidator)
            {
                state = "PreviousValidator";
            }
            else if (isAbleToBeStaker)
            {
                state = "AbleToBeStaker";
            }
            else
            {
                state = "Newbie";
            }

            return(new JObject
            {
                ["address"] = address,
                ["publicKey"] = publicKey,
                ["balance"] = balance.ToString(),
                ["staked"] = staked.ToString(),
                ["staking"] = staking.ToString(),
                ["penalty"] = penalty.ToString(),
                ["state"] = state,
                ["online"] = isStaker,
                ["isWalletLocked"] = isWalletLocked,
            });
        }