コード例 #1
0
        public override bool Validate()
        {
            if (this.contract == null)
            {
                throw new ContractValidateException("No contract!");
            }

            if (this.db_manager == null)
            {
                throw new ContractValidateException("No this.db_manager!");
            }

            if (this.contract.Is(SetAccountIdContract.Descriptor))
            {
                SetAccountIdContract account_id_contract = null;

                try
                {
                    account_id_contract = contract.Unpack <SetAccountIdContract>();
                }
                catch (InvalidProtocolBufferException e)
                {
                    Logger.Debug(e.Message);
                    throw new ContractValidateException(e.Message);
                }

                byte[] owner_address = account_id_contract.OwnerAddress.ToByteArray();
                byte[] account_id    = account_id_contract.AccountId.ToByteArray();
                if (!TransactionUtil.ValidAccountId(account_id))
                {
                    throw new ContractValidateException("Invalid accountId");
                }

                if (!Wallet.IsValidAddress(owner_address))
                {
                    throw new ContractValidateException("Invalid owner_address");
                }

                AccountCapsule account = this.db_manager.Account.Get(owner_address);
                if (account == null)
                {
                    throw new ContractValidateException("Account has not existed");
                }

                if (account.AccountId != null && !account.AccountId.IsEmpty)
                {
                    throw new ContractValidateException("This account id already set");
                }

                if (this.db_manager.AccountIdIndex.Contains(account_id))
                {
                    throw new ContractValidateException("This id has existed");
                }
            }
            else
            {
                throw new ContractValidateException(
                          "contract type error,expected type [SetAccountIdContract],real type[" + contract.GetType().Name + "]");
            }

            return(true);
        }