public static RpcApiResult CreateWithdrawBalanceContract(byte[] owner_address, out WithdrawBalanceContract contract) { contract = new WithdrawBalanceContract(); contract.OwnerAddress = ByteString.CopyFrom(owner_address); return(RpcApiResult.Success); }
public override bool Validate() { if (this.contract == null) { throw new ContractValidateException("No contract!"); } if (this.db_manager == null && (Deposit == null || Deposit.DBManager == null)) { throw new ContractValidateException("No this.db_manager!"); } if (this.contract.Is(WithdrawBalanceContract.Descriptor)) { WithdrawBalanceContract withdraw_contract = null; try { withdraw_contract = this.contract.Unpack <WithdrawBalanceContract>(); } catch (InvalidProtocolBufferException e) { Logger.Debug(e.Message); throw new ContractValidateException(e.Message); } byte[] owner_address = withdraw_contract.OwnerAddress.ToByteArray(); if (!Wallet.IsValidAddress(owner_address)) { throw new ContractValidateException("Invalid address"); } AccountCapsule account = Deposit == null? this.db_manager.Account.Get(owner_address) : Deposit.GetAccount(owner_address); if (account == null) { throw new ContractValidateException( ActuatorParameter.ACCOUNT_EXCEPTION_STR + owner_address.ToHexString() + "] not exists"); } if (!this.db_manager.Witness.Contains(owner_address)) { throw new ContractValidateException( ActuatorParameter.ACCOUNT_EXCEPTION_STR + owner_address.ToHexString() + "] is not a witnessAccount"); } if (Args.Instance.GenesisBlock.Witnesses.Where(witness => owner_address.SequenceEqual(witness.Address)).Count() > 0) { throw new ContractValidateException( ActuatorParameter.ACCOUNT_EXCEPTION_STR + owner_address.ToHexString() + "] is a guard representative and is not allowed to withdraw Balance"); } long now = this.db_manager.GetHeadBlockTimestamp(); long frozen_time = Deposit == null? this.db_manager.DynamicProperties.GetWitnessAllowanceFrozenTime() * 86_400_000L : Deposit.GetWitnessAllowanceFrozenTime() * 86_400_000L; if (now - account.LatestWithdrawTime < frozen_time) { throw new ContractValidateException("The last withdraw time is " + account.LatestWithdrawTime + ",less than 24 hours"); } if (account.Allowance <= 0) { throw new ContractValidateException("witnessAccount does not have any allowance"); } try { long add_result = checked (account.Balance + account.Allowance); } catch (OverflowException e) { Logger.Debug(e.Message); throw new ContractValidateException(e.Message); } } else { throw new ContractValidateException( "contract type error, expected type [WithdrawBalanceContract],real type[" + contract.GetType().Name + "]"); } return(true); }
public async Task <TransactionExtention> WithdrawBalanceAsync(WithdrawBalanceContract contract) { return(await _grpcClient.WithdrawBalance2Async(contract)); }
public async Task <Transaction> WithdrawBalanceAsync(WithdrawBalanceContract contract, CancellationToken token = default) { var wallet = GetWallet(); return(await wallet.WithdrawBalanceAsync(contract, _configuration.GetCallOptions(token))); }