Пример #1
0
        protected void ProcessValidatorStateDescriptor(StateDescriptor descriptor, DataCache <ECPoint, ValidatorState> validators)
        {
            ECPoint        pubkey    = ECPoint.DecodePoint(descriptor.Key, ECCurve.Secp256r1);
            ValidatorState validator = validators.GetAndChange(pubkey, () => new ValidatorState(pubkey));

            switch (descriptor.Field)
            {
            case "Registered":
                validator.Registered = BitConverter.ToBoolean(descriptor.Value, 0);
                break;
            }
        }
Пример #2
0
        private IEnumerable <UInt160> GetScriptHashesForVerifying_Validator(StateDescriptor descriptor)
        {
            switch (descriptor.Field)
            {
            case "Registered":
                yield return(Contract.CreateSignatureRedeemScript(ECPoint.DecodePoint(descriptor.Key, ECCurve.Secp256r1)).ToScriptHash());

                break;

            default:
                throw new InvalidOperationException();
            }
        }
Пример #3
0
        private IEnumerable <UInt160> GetScriptHashesForVerifying_Account(StateDescriptor descriptor)
        {
            switch (descriptor.Field)
            {
            case "Votes":
                yield return(new UInt160(descriptor.Key));

                break;

            default:
                throw new InvalidOperationException();
            }
        }
Пример #4
0
        protected void ProcessAccountStateDescriptor(StateDescriptor descriptor, DataCache <UInt160, AccountState> accounts, DataCache <ECPoint, ValidatorState> validators, MetaDataCache <ValidatorsCountState> validators_count)
        {
            UInt160      hash    = new UInt160(descriptor.Key);
            AccountState account = accounts.GetAndChange(hash, () => new AccountState(hash));

            switch (descriptor.Field)
            {
            case "Votes":
                Fixed8 balance = account.GetBalance(GoverningToken.Hash);
                foreach (ECPoint pubkey in account.Votes)
                {
                    ValidatorState validator = validators.GetAndChange(pubkey);
                    validator.Votes -= balance;
                    if (!validator.Registered && validator.Votes.Equals(Fixed8.Zero))
                    {
                        validators.Delete(pubkey);
                    }
                }
                ECPoint[] votes = descriptor.Value.AsSerializableArray <ECPoint>().Distinct().ToArray();
                if (votes.Length != account.Votes.Length)
                {
                    ValidatorsCountState count_state = validators_count.GetAndChange();
                    if (account.Votes.Length > 0)
                    {
                        count_state.Votes[account.Votes.Length - 1] -= balance;
                    }
                    if (votes.Length > 0)
                    {
                        count_state.Votes[votes.Length - 1] += balance;
                    }
                }
                account.Votes = votes;
                foreach (ECPoint pubkey in account.Votes)
                {
                    validators.GetAndChange(pubkey, () => new ValidatorState(pubkey)).Votes += balance;
                }
                break;
            }
        }