public override bool Execute(TransactionResultCapsule result) { long fee = CalcFee(); try { UpdateAssetContract update_asset_contract = this.contract.Unpack <UpdateAssetContract>(); long new_limit = update_asset_contract.NewLimit; long new_public_limit = update_asset_contract.NewPublicLimit; byte[] owner_address = update_asset_contract.OwnerAddress.ToByteArray(); ByteString new_url = update_asset_contract.Url; ByteString new_description = update_asset_contract.Description; AccountCapsule account = this.db_manager.Account.Get(owner_address); AssetIssueCapsule asset_issue = null; AssetIssueCapsule asset_issue_v2 = null; asset_issue_v2 = this.db_manager.AssetIssueV2.Get(account.AssetIssuedID.ToByteArray()); asset_issue_v2.FreeAssetNetLimit = new_limit; asset_issue_v2.PublicFreeAssetNetLimit = new_public_limit; asset_issue_v2.Url = new_url; asset_issue_v2.Description = new_description; if (this.db_manager.DynamicProperties.GetAllowSameTokenName() == 0) { asset_issue = this.db_manager.AssetIssue.Get(account.AssetIssuedName.ToByteArray()); asset_issue.FreeAssetNetLimit = new_limit; asset_issue.PublicFreeAssetNetLimit = new_public_limit; asset_issue.Url = new_url; asset_issue.Description = new_description; this.db_manager.AssetIssue.Put(asset_issue.CreateDatabaseKey(), asset_issue); this.db_manager.AssetIssueV2.Put(asset_issue_v2.CreateDatabaseKeyV2(), asset_issue_v2); } else { this.db_manager.AssetIssueV2.Put(asset_issue_v2.CreateDatabaseKeyV2(), asset_issue_v2); } result.SetStatus(fee, code.Sucess); } catch (InvalidProtocolBufferException e) { Logger.Debug(e.Message); result.SetStatus(fee, code.Failed); throw new ContractExeException(e.Message); } return(true); }
public static RpcApiResult CreateUpdateAssetContract(byte[] owner_address, byte[] description, byte[] url, long limit, long public_limit, out UpdateAssetContract contract) { contract = new UpdateAssetContract(); contract.OwnerAddress = ByteString.CopyFrom(owner_address); contract.Description = ByteString.CopyFrom(description); contract.Url = ByteString.CopyFrom(url); contract.NewLimit = limit; contract.NewPublicLimit = public_limit; return(RpcApiResult.Success); }
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(UpdateAssetContract.Descriptor)) { UpdateAssetContract update_asset_contract = null; try { update_asset_contract = this.contract.Unpack <UpdateAssetContract>(); } catch (InvalidProtocolBufferException e) { Logger.Debug(e.Message); throw new ContractValidateException(e.Message); } long new_limit = update_asset_contract.NewLimit; long new_public_limit = update_asset_contract.NewPublicLimit; byte[] owner_address = update_asset_contract.OwnerAddress.ToByteArray(); ByteString new_url = update_asset_contract.Url; ByteString new_description = update_asset_contract.Description; 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 (this.db_manager.DynamicProperties.GetAllowSameTokenName() == 0) { if (account.AssetIssuedName.IsEmpty) { throw new ContractValidateException("Account has not issue any asset"); } if (this.db_manager.AssetIssue.Get(account.AssetIssuedName.ToByteArray()) == null) { throw new ContractValidateException("Asset not exists in AssetIssueStore"); } } else { if (account.AssetIssuedID.IsEmpty) { throw new ContractValidateException("Account has not issue any asset"); } if (this.db_manager.AssetIssueV2.Get(account.AssetIssuedID.ToByteArray()) == null) { throw new ContractValidateException("Asset not exists in AssetIssueV2Store"); } } if (!TransactionUtil.ValidUrl(new_url.ToByteArray())) { throw new ContractValidateException("Invalid url"); } if (!TransactionUtil.ValidAssetDescription(new_description.ToByteArray())) { throw new ContractValidateException("Invalid description"); } if (new_limit < 0 || new_limit >= this.db_manager.DynamicProperties.GetOneDayNetLimit()) { throw new ContractValidateException("Invalid FreeAssetNetLimit"); } if (new_public_limit < 0 || new_public_limit >= this.db_manager.DynamicProperties.GetOneDayNetLimit()) { throw new ContractValidateException("Invalid PublicFreeAssetNetLimit"); } } else { throw new ContractValidateException( "contract type error,expected type [UpdateAssetContract],real type[" + contract.GetType().Name + "]"); } return(true); }
public async Task <TransactionExtention> UpdateAssetAsync(UpdateAssetContract contract) { return(await _grpcClient.UpdateAsset2Async(contract)); }
public async Task <Transaction> UpdateAssetAsync(UpdateAssetContract contract, CancellationToken token = default) { var wallet = GetWallet(); return(await wallet.UpdateAssetAsync(contract, _configuration.GetCallOptions(token))); }