示例#1
0
 public Asset(string type, AssetState state)
 {
     this.Type = type;
     this.Name = "";
     this.ADPath = "";
     this.State = state;
 }
示例#2
0
        public AssetItem(AssetState asset, Fixed8 value, Fixed8 claim, double rate = 1.5)
        {
            InitializeComponent();

            Asset = asset;
            Value = value;
            Claim = claim;
            Rate  = rate;

            RefreshInterface();
        }
示例#3
0
文件: StateReader.cs 项目: ys8090/NEU
        protected virtual bool Asset_GetIssuer(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(asset.Issuer.ToArray());
            return(true);
        }
示例#4
0
        private void ImportAssetsFromFile()
        {
            const string fileName   = "assets.acc";
            var          importPath = Tools.GetImportDirectory();

            if (!Directory.Exists(importPath))
            {
                _logger?.Error($"Directory {importPath} does not exist.");
                return;
            }
            _logger?.Info($"Scan directory: {importPath}");
            var filePath  = $"{importPath}{fileName}";
            var fileExist = File.Exists(filePath);

            if (!fileExist)
            {
                _logger?.Error($"No file {fileName} into directory {importPath}");
                return;
            }
            _logger?.Info($"-Import assets from file: {DateTime.Now}");
            var fileContent = File.ReadAllText(filePath);
            var jObject     = JObject.Parse(fileContent);
            var assets      = new List <AssetState>();

            foreach (var jAsset in (JArray)jObject)
            {
                var assetTypeValue = jAsset["type"].AsString();
                if (Enum.TryParse(assetTypeValue, true, out AssetType assetType))
                {
                    var asset = new AssetState
                    {
                        AssetId    = UInt256.Parse(jAsset["id"].AsString()),
                        AssetType  = (AssetType)assetType,
                        Name       = jAsset["name"].AsString(),
                        Amount     = Fixed8.Parse(jAsset["amount"].AsString()),
                        Available  = Fixed8.Parse(jAsset["available"].AsString()),
                        Issuer     = UInt160.Parse(jAsset["issuer"].AsString()),
                        Precision  = byte.Parse(jAsset["precision"].AsString()),
                        Fee        = Fixed8.Parse(jAsset["fee"].AsString()),
                        FeeAddress = UInt160.Parse(jAsset["feeaddress"].AsString()),
                        Owner      = ECPoint.Parse(jAsset["owner"].AsString(), ECCurve.Secp256r1),
                        Admin      = UInt160.Parse(jAsset["admin"].AsString()),
                        Expiration = uint.Parse(jAsset["expiration"].AsString()),
                        IsFrozen   = bool.Parse(jAsset["isfrozen"].AsString())
                    };
                    assets.Add(asset);
                }
            }
            var newFileName = $"{importPath}{fileName}p";

            File.Move(filePath, newFileName);
            ImportAssets(assets);
            _logger?.Info($"-Finish import assets from files: {DateTime.Now}");
        }
示例#5
0
文件: StateReader.cs 项目: ys8090/NEU
        protected virtual bool Asset_GetOwner(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(asset.Owner.EncodePoint(true));
            return(true);
        }
示例#6
0
文件: StateReader.cs 项目: ys8090/NEU
        protected virtual bool Asset_GetPrecision(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push((int)asset.Precision);
            return(true);
        }
示例#7
0
文件: StateReader.cs 项目: ys8090/NEU
        protected virtual bool Asset_GetAvailable(ExecutionEngine engine)
        {
            AssetState asset = engine.EvaluationStack.Pop().GetInterface <AssetState>();

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(asset.Available.GetData());
            return(true);
        }
示例#8
0
        private void TxbFeeAmount_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                AssetTypeItem tag   = ((ComboBoxItem)cmbAssetType.SelectedItem).Tag as AssetTypeItem;
                AssetState    asset = Blockchain.Default.GetAssetState(tag.AssetID);

                if (txbFeeAmount.Text == "")
                {
                    return;
                }

                Fixed8 fee = Fixed8.Satoshi * Convert.ToInt32(100000000 * Convert.ToDouble(txbFeeAmount.Text));

                if (fromAddress == null)
                {
                    foreach (UInt160 scriptHash in Constant.CurrentWallet.GetAddresses().ToArray())
                    {
                        VerificationContract contract = Constant.CurrentWallet.GetContract(scriptHash);
                        fromAddress = contract.Address;
                    }
                }

                if (Wallet.GetAddressVersion(fromAddress) == Wallet.AnonymouseAddressVersion || Wallet.GetAddressVersion(fromAddress) == Wallet.StealthAddressVersion)
                {
                    if (asset.AssetType == AssetType.GoverningToken)
                    {
                        if (asset.AFee < fee)
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        if (Fixed8.Satoshi * 10000000 + asset.AFee < fee)
                        {
                            throw new Exception();
                        }
                    }
                }
                else
                {
                    if (asset.FeeMin > fee || asset.FeeMax < fee)
                    {
                        throw new Exception();
                    }
                }
            }
            catch (Exception)
            {
                txbFeeAmount.Text = "";
                StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_RP_ERR_INPUT_FEE_IN_LIMIT", iLang));
            }
        }
示例#9
0
 /// <summary>
 /// 停止加载过程(其它不变);
 /// </summary>
 public void stop()
 {
     if (loader != null)
     {
         ResourceLoaderManager.sharedInstance().unQueue(loader);
         loader.cancel();
     }
     if (_status != AssetState.READY)
     {
         _status = AssetState.FAILD;
     }
 }
示例#10
0
 public IssueDialog(AssetState asset = null)
 {
     InitializeComponent();
     if (asset == null)
     {
         comboBox1.Items.AddRange(Program.CurrentWallet.GetTransactions <RegisterTransaction>().Select(p => Blockchain.Default.GetAssetState(p.Hash)).Where(p => Program.CurrentWallet.ContainsAddress(p.Issuer)).ToArray());
     }
     else
     {
         comboBox1.Items.Add(asset);
     }
 }
        internal static void SetState(int assetIndex, AssetState newState)
        {
            if (assetIndex == 0)
            {
                throw new InvalidOperationException("Cannot set the state of a null asset");
            }

            var asset = assets[assetIndex - 1];

            asset.state            = newState;
            assets[assetIndex - 1] = asset;
        }
        protected override bool Blockchain_GetAsset(ExecutionEngine engine)
        {
            UInt256    hash  = new UInt256(engine.EvaluationStack.Pop().GetByteArray());
            AssetState asset = assets.TryGet(hash);

            if (asset == null)
            {
                return(false);
            }
            engine.EvaluationStack.Push(StackItem.FromInterface(asset));
            return(true);
        }
示例#13
0
        private bool Blockchain_GetAsset(ExecutionEngine engine)
        {
            UInt256    hash  = new UInt256(engine.CurrentContext.EvaluationStack.Pop().GetByteArray());
            AssetState asset = Snapshot.Assets.TryGet(hash);

            if (asset == null)
            {
                return(false);
            }
            engine.CurrentContext.EvaluationStack.Push(StackItem.FromInterface(asset));
            return(true);
        }
示例#14
0
        private void cmbAssetType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                AssetTypeItem tag   = ((ComboBoxItem)cmbAssetType.SelectedItem).Tag as AssetTypeItem;
                AssetState    asset = Blockchain.Default.GetAssetState(tag.AssetID);

                if (fromAddress == null)
                {
                    foreach (UInt160 scriptHash in Constant.CurrentWallet.GetAddresses().ToArray())
                    {
                        VerificationContract contract = Constant.CurrentWallet.GetContract(scriptHash);
                        fromAddress = contract.Address;
                    }
                }

                if (Wallet.GetAddressVersion(fromAddress) == Wallet.AnonymouseAddressVersion || Wallet.GetAddressVersion(fromAddress) == Wallet.StealthAddressVersion)
                {
                    /*if (asset.AssetType == AssetType.GoverningToken)
                     * {
                     *  TxbFee.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_FEE", iLang), asset.AFee.ToString(), asset.GetName(), asset.AFee.ToString(), asset.GetName());
                     * }
                     * else
                     * {*/
                    TxbFee.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_FEE", iLang), (Fixed8.Satoshi * 10000000 + asset.AFee).ToString(), "XQG", (Fixed8.Satoshi * 10000000 + asset.AFee).ToString(), "XQG");
                    //}
                }
                else
                {
                    /*if (asset.AssetType == AssetType.GoverningToken)
                     * {
                     *  TxbFee.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_FEE", iLang), asset.FeeMin.ToString(), asset.GetName(), asset.FeeMax.ToString(), asset.GetName());
                     * }
                     * else
                     * {*/
                    TxbFee.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_FEE", iLang), (asset.FeeMin).ToString(), "XQG", (asset.FeeMax).ToString(), "XQG");
                    //}
                }

                if (tag != null)
                {
                    TxbSpendable.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_SPENDABLE", iLang), tag.Value.ToString(), tag.Name);
                }
                else
                {
                    TxbSpendable.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_SPENDABLE", iLang), 0, "");
                }
            }
            catch (Exception)
            {
                TxbSpendable.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_SPENDABLE", iLang), 0, "");
            }
        }
示例#15
0
            internal IEnumerator LoadAsset(string assetWWWDir, string assetDir, string inAssetWWWDir, string assetExtension)
            {
                m_AssetState = AssetState.LocalLoading;

                string assetWWWPath = assetWWWDir + m_AssetName + assetExtension;
                string assetPath    = assetDir + m_AssetName + assetExtension;

                if (!File.Exists(assetPath))
                {
                    assetWWWPath = inAssetWWWDir + m_AssetName + assetExtension;
                }

                using (m_AssetWWW = new WWW(assetWWWPath))
                {
                    //m_AssetWWW will be null when the www is done exactly in checking the attribute [AssetReady].
                    while (m_AssetWWW != null && !m_AssetWWW.isDone)
                    {
                        yield return(null);
                    }

                    if (m_AssetWWW != null)
                    {
                        if (m_AssetWWW.error == null)
                        {
                            m_AssetBundle = m_AssetWWW.assetBundle;
                        }
                        else
                        {
                            Debug.LogError("asset load error: " + assetWWWPath + " -- " + m_AssetWWW.error);
                        }

                        if (m_AssetState == AssetState.HasRelease)
                        {
                            Debug.Log("Asset set to be released before ready, check logic if not on purpose." + assetWWWPath);
#if UNITY_4_0
                            m_AssetObject = null;
                            UnloadAssetBundle(true);
#else
                            UnlaodAssetObject();
                            UnloadAssetBundle(true);
#endif
                        }
                        else
                        {
                            m_AssetState = AssetState.Finish;
                        }

                        m_AssetWWW.Dispose();
                        m_AssetWWW = null;
                    }
                }
            }
        private bool EnsureCreatedTokenIdMap(
            IEnumerable <KeyValuePair <UInt256, AssetState> > assets,
            AssetState r, UInt256 id,
            DataCache <UInt256, TransactionState> transactionsCache)
        {
            if (_dicTokenIds.ContainsKey(id))
            {
                return(true);
            }

            Dictionary <string, UInt256> L = new Dictionary <string, UInt256>();

            assets = assets.Where(x =>
                                  (!x.Key.Equals(Blockchain.GoverningToken.Hash)) &&
                                  (!x.Key.Equals(Blockchain.UtilityToken.Hash)));

            // Logger.Info($"== Preparing assets: {assets.Count()}");

            foreach (var s in assets)
            {
                // Logger.Info($"==== {s.Value.GetName()} {s.Key.ToString()}");
                var tx = transactionsCache.TryGet(s.Value.AssetId);
                if (tx != null)
                {
                    var f = tx.BlockIndex.ToString() + s.Value.AssetId.ToString();
                    L[f] = s.Value.AssetId;
                }
            }

            var LKS = L.Keys.ToList();

            LKS.Sort();

            byte baseTokenID = 2;

            foreach (var k in LKS)
            {
                var aid = L[k];
                if (baseTokenID > 254)
                {
                    return(false);       // still only 255 token IDs available
                }
                if (id.Equals(aid))
                {
                    // Logger.Info($"=== Adding {aid.ToString()} with id = {baseTokenID}");
                    _dicTokenIds[aid] = baseTokenID;
                    return(true);
                }
                baseTokenID++;
            }
            return(false);
        }
示例#17
0
        protected virtual void loadCancelHandle(EventX e)
        {
            loader.removeEventListener(EventX.CANCEL, loadCancelHandle);
            if (_status == AssetState.LOADING)
            {
                _status = AssetState.NONE;
            }

            if (hasEventListener(EventX.FAILED))
            {
                simpleDispatch(EventX.FAILED);
            }
        }
示例#18
0
    /// <summary>
    /// 得到该参数1状态的所有资源配置
    /// </summary>
    /// <param name="_state">资源状态</param>
    public List <DJAssetDataModel> GetAssetsByState(AssetState _state)
    {
        List <DJAssetDataModel> aseetsList = new List <DJAssetDataModel>();

        foreach (var _tempConfig in AssetsDict.Values)
        {
            if (_tempConfig.state == _state)
            {
                aseetsList.Add(_tempConfig);
            }
        }
        return(aseetsList);
    }
示例#19
0
        protected void resourceComplete(string eventType)
        {
            if (eventType == EventX.COMPLETE)
            {
                _status = AssetState.READY;
            }
            else
            {
                _status = AssetState.FAILD;
            }

            this.dispatchEvent(new EventX(eventType, _data));
        }
示例#20
0
 protected virtual void resourceComplete(string eventType, string errorMessage = "")
 {
     if (eventType == EventX.COMPLETE)
     {
         _status = AssetState.READY;
         this.simpleDispatch(eventType, _data);
     }
     else
     {
         _status = AssetState.FAILD;
         this.simpleDispatch(eventType, errorMessage);
     }
 }
示例#21
0
        private void TxbReceiveAddress_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                AssetTypeItem tag   = ((ComboBoxItem)cmbAssetType.SelectedItem).Tag as AssetTypeItem;
                AssetState    asset = Blockchain.Default.GetAssetState(tag.AssetID);

                if (fromAddress == null)
                {
                    foreach (UInt160 scriptHash in Constant.CurrentWallet.GetAddresses().ToArray())
                    {
                        VerificationContract contract = Constant.CurrentWallet.GetContract(scriptHash);
                        fromAddress = contract.Address;
                    }
                }

                if (Wallet.GetAddressVersion(fromAddress) == Wallet.AnonymouseAddressVersion || Wallet.GetAddressVersion(fromAddress) == Wallet.StealthAddressVersion)
                {
                    TxbFee.Text            = String.Format(StringTable.GetInstance().GetString("STR_SP_AFEE", iLang), Blockchain.UtilityToken.A_Fee.ToString(), "XQG");
                    txbFeeAmount.IsEnabled = false;
                    txbFeeAmount.Text      = Blockchain.UtilityToken.A_Fee.ToString();
                }
                else
                {
                    if (Wallet.GetAddressVersion(txbReceiveAddress.Text) == Wallet.AnonymouseAddressVersion || Wallet.GetAddressVersion(txbReceiveAddress.Text) == Wallet.StealthAddressVersion)
                    {
                        TxbFee.Text            = String.Format(StringTable.GetInstance().GetString("STR_SP_AFEE", iLang), asset.AFee.ToString(), "XQG");
                        txbFeeAmount.IsEnabled = false;
                        txbFeeAmount.Text      = asset.AFee.ToString();
                    }
                    else
                    {
                        TxbFee.Text            = String.Format(StringTable.GetInstance().GetString("STR_SP_FEE", iLang), (asset.FeeMin).ToString(), "XQG", (asset.FeeMax).ToString(), "XQG");
                        txbFeeAmount.IsEnabled = true;
                    }
                }

                if (tag != null)
                {
                    TxbSpendable.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_SPENDABLE", iLang), tag.Value.ToString(), tag.Name);
                }
                else
                {
                    TxbSpendable.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_SPENDABLE", iLang), 0, "");
                }
            }
            catch (Exception)
            {
                TxbSpendable.Text = String.Format(StringTable.GetInstance().GetString("STR_SP_SPENDABLE", iLang), 0, "");
            }
        }
示例#22
0
 private bool Asset_GetPrecision(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push((int)asset.Precision);
         return(true);
     }
     return(false);
 }
示例#23
0
 private bool Asset_GetIssuer(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(asset.Issuer.ToArray());
         return(true);
     }
     return(false);
 }
示例#24
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            AssetState asset = comboBox1.SelectedItem as AssetState;

            if (asset == null)
            {
                textBox3.Text = "";
            }
            else
            {
                textBox3.Text = Program.CurrentWallet.GetAvailable(asset.AssetId).ToString();
            }
            textBox_TextChanged(this, EventArgs.Empty);
        }
示例#25
0
 public void SetFolder(PostprocessorAssetType assetType, string path)
 {
     if (this.assetType != assetType || this.folder != path)
     {
         this.assetType = assetType;
         this.folder    = path;
         selectState    = AssetState.None;
         var guid      = postprocessorUtils.Get(this.assetType, this.folder);
         var assetPath = AssetDatabase.GUIDToAssetPath(guid);
         soAssetPostprocessor = AssetDatabase.LoadAssetAtPath <SoAssetPostprocessor>(assetPath);
         postprocessorGuid    = guid;
         Refresh(true);
     }
 }
示例#26
0
 public void SetItems(IEnumerable <TransactionOutput> outputs)
 {
     listBox1.Items.Clear();
     foreach (TransactionOutput output in outputs)
     {
         AssetState asset = Blockchain.Default.GetAssetState(output.AssetId);
         listBox1.Items.Add(new TxOutListBoxItem
         {
             Output    = output,
             AssetName = $"{asset.GetName()} ({asset.Owner})"
         });
     }
     ItemsChanged?.Invoke(this, EventArgs.Empty);
 }
示例#27
0
 protected virtual bool Asset_GetAmount(ExecutionEngine engine)
 {
     if (engine.EvaluationStack.Pop() is InteropInterface _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.EvaluationStack.Push(asset.Amount.GetData());
         return(true);
     }
     return(false);
 }
示例#28
0
 private bool Asset_GetOwner(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropContract _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(asset.Owner.EncodePoint(true));
         return(true);
     }
     return(false);
 }
示例#29
0
 private bool Asset_GetAvailable(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropContract _interface)
     {
         AssetState asset = _interface.GetInterface <AssetState>();
         if (asset == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(asset.Available.GetData());
         return(true);
     }
     return(false);
 }
示例#30
0
        private void LoadAssets()
        {
            for (int i = 0; i < AssetsImp.getInstance().GetList().Count; i++)
            {
                AssetState             state = Blockchain.Default.GetAssetState(AssetsImp.getInstance().GetList()[i].Asset_ID);
                Global.AssetDescriptor item  = new Global.AssetDescriptor(state);

                cmb_assets.Items.Add(item);
            }

            if (cmb_assets.Items.Count > 0)
            {
                cmb_assets.SelectedIndex = 0;
            }
        }
示例#31
0
        public override UInt160[] GetScriptHashesForVerifying(Snapshot snapshot)
        {
            HashSet <UInt160> hashes = new HashSet <UInt160>(base.GetScriptHashesForVerifying(snapshot));

            foreach (TransactionResult result in GetTransactionResults().Where(p => p.Amount < Fixed8.Zero))
            {
                AssetState asset = snapshot.Assets.TryGet(result.AssetId);
                if (asset == null)
                {
                    throw new InvalidOperationException();
                }
                hashes.Add(asset.Issuer);
            }
            return(hashes.OrderBy(p => p).ToArray());
        }
示例#32
0
 public Asset CreateAsset(string serialNumber, string description, AssetState state)
 {
     var result = _assets.GetBySerialNumber(serialNumber);
     if (result == null)
     {
         var newAssetState = state == AssetState.Unspecified ? AssetState.Available : state;
         result = new Asset
         {
             SerialNumber = serialNumber,
             State = newAssetState,
             AssetType = FindAssetTypeByDescription(description)
         };
         _assets.Add(result);
     }
     else
     {
         if (state != AssetState.Unspecified)
         {
             result.State = state;
             _assets.Update(result);
         }
     }
     return result;
 }
示例#33
0
        // upsert
        public Asset MergeAsset(int? id, string serialNumber, string description, AssetState state)
        {
            if (id.HasValue && id.Value > 0)
            {
                var asset = FindAssetById(id.Value);
                if (!string.IsNullOrEmpty(description))
                {
                    if (string.IsNullOrEmpty(asset.AssetType?.Description) ||
                        0 != string.Compare(description, asset.AssetType?.Description, true))
                    {
                        asset.AssetType = FindAssetTypeByDescription(description);
                    }
                }

                if (state != AssetState.Unspecified)
                {
                    asset.State = state;
                }

                _assets.Update(asset);

                return asset;
            }

            return CreateAsset(serialNumber, description, state);
        }