示例#1
0
        public override bool Execute(TransactionResultCapsule result)
        {
            long fee = CalcFee();

            try
            {
                AccountCreateContract account_create_contract = contract.Unpack <AccountCreateContract>();
                bool           default_permission             = this.db_manager.DynamicProperties.GetAllowMultiSign() == 1;
                AccountCapsule account = new AccountCapsule(
                    account_create_contract,
                    this.db_manager.GetHeadBlockTimestamp(),
                    default_permission,
                    this.db_manager);

                this.db_manager.Account.Put(account_create_contract.AccountAddress.ToByteArray(), account);
                this.db_manager.AdjustBalance(account_create_contract.OwnerAddress.ToByteArray(), -fee);
                this.db_manager.AdjustBalance(this.db_manager.Account.GetBlackHole().CreateDatabaseKey(), fee);

                result.SetStatus(fee, code.Sucess);
            }
            catch (BalanceInsufficientException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }
            catch (InvalidProtocolBufferException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }

            return(true);
        }
示例#2
0
        public static RpcApiResult CreateAccountContract(byte[] owner_address,
                                                         byte[] create_address,
                                                         out AccountCreateContract contract)
        {
            contract = new AccountCreateContract();
            contract.AccountAddress = ByteString.CopyFrom(create_address);
            contract.OwnerAddress   = ByteString.CopyFrom(owner_address);

            return(RpcApiResult.Success);
        }
示例#3
0
        public TransactionCapsule(AccountCreateContract contract, AccountStore account_store)
        {
            AccountCapsule account = account_store.Get(contract.OwnerAddress.ToByteArray());

            if (account != null && account.Type == contract.Type)
            {
                return;
            }

            CreateTransaction(contract, Transaction.Types.Contract.Types.ContractType.AccountCreateContract);
        }
示例#4
0
        public AccountCapsule(AccountCreateContract contract, long create_time, bool default_permission, DatabaseManager db_manager)
        {
            if (default_permission)
            {
                Permission owner  = CreateDefaultOwnerPermission(this.account.Address);
                Permission active = CreateDefaultActivePermission(this.account.Address, db_manager);

                this.account                 = new Account();
                this.account.Type            = contract.Type;
                this.account.Address         = contract.AccountAddress;
                this.account.CreateTime      = create_time;
                this.account.OwnerPermission = owner;
                this.account.ActivePermission.Add(active);
            }
            else
            {
                this.account            = new Account();
                this.account.Type       = contract.Type;
                this.account.Address    = contract.AccountAddress;
                this.account.CreateTime = create_time;
            }
        }
示例#5
0
        public override bool Validate()
        {
            if (this.contract == null)
            {
                throw new ContractValidateException("No contract!");
            }

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

            if (this.contract.Is(AccountCreateContract.Descriptor))
            {
                AccountCreateContract account_create_contract = null;
                try
                {
                    account_create_contract = this.contract.Unpack <AccountCreateContract>();
                }
                catch (InvalidProtocolBufferException e)
                {
                    Logger.Debug(e.Message);
                    throw new ContractValidateException(e.Message);
                }

                byte[] owner_address = account_create_contract.OwnerAddress.ToByteArray();
                if (!Wallet.IsValidAddress(owner_address))
                {
                    throw new ContractValidateException("Invalid ownerAddress");
                }

                AccountCapsule account = this.db_manager.Account.Get(owner_address);
                if (account == null)
                {
                    throw new ContractValidateException(
                              "Account[" + owner_address.ToHexString() + "] not exists");
                }

                long fee = CalcFee();
                if (account.Balance < fee)
                {
                    throw new ContractValidateException(
                              "Validate CreateAccountActuator error, insufficient fee.");
                }

                byte[] account_address = account_create_contract.AccountAddress.ToByteArray();
                if (!Wallet.IsValidAddress(account_address))
                {
                    throw new ContractValidateException("Invalid account address");
                }

                if (this.db_manager.Account.Contains(account_address))
                {
                    throw new ContractValidateException("Account has existed");
                }
            }
            else
            {
                throw new ContractValidateException(
                          "contract type error,expected type [AccountCreateContract],real type[" + contract.GetType().Name + "]");
            }

            return(true);
        }
示例#6
0
 public async Task <TransactionExtention> CreateAccountAsync(AccountCreateContract contract)
 {
     return(await _grpcClient.CreateAccount2Async(contract));
 }
示例#7
0
        public async Task <Transaction> CreateAccountAsync(AccountCreateContract contract, CancellationToken token = default)
        {
            var wallet = GetWallet();

            return(await wallet.CreateAccountAsync(contract, _configuration.GetCallOptions(token)));
        }