private void AddAssets(AssetState asset, Fixed8 value, Fixed8 claim)
        {
            bool isAdd = true;

            foreach (AssetItem item in assetItems)
            {
                if (item.Asset.AssetId == asset.AssetId)
                {
                    isAdd      = false;
                    item.Asset = asset;
                    item.Value = value;
                    item.Claim = claim;
                    item.RefreshInterface();
                }
            }

            if (isAdd)
            {
                AssetItem item = new AssetItem(asset, value, claim);
                assetItems.Add(item);
            }

            assetInfoPage.Refresh(assetItems);

            if (AssetsManager.GetInstance().AddAssets(asset.AssetId, asset.GetName()))
            {
                sendPage.AddAsset(asset.AssetId, asset.GetName(), value);
            }
            else
            {
                sendPage.RefreshAsset(asset.AssetId, value);
            }
        }
Пример #2
0
 public AssetDescriptor(UIntBase asset_id, UInt256 ChainHash)
 {
     if (asset_id is UInt160 asset_id_160)
     {
         byte[] script;
         using (ScriptBuilder sb = new ScriptBuilder())
         {
             sb.EmitAppCall(asset_id_160, "decimals");
             sb.EmitAppCall(asset_id_160, "name");
             script = sb.ToArray();
         }
         ApplicationEngine engine = ApplicationEngine.Run(script, ChainHash);
         if (engine.State.HasFlag(VMState.FAULT))
         {
             throw new ArgumentException();
         }
         this.AssetId   = asset_id;
         this.AssetName = engine.EvaluationStack.Pop().GetString();
         this.Decimals  = (byte)engine.EvaluationStack.Pop().GetBigInteger();
     }
     else
     {
         AssetState state = BlockchainBase.GetBlockchain(ChainHash).GetAssetState((UInt256)asset_id);
         this.AssetId   = state.AssetId;
         this.AssetName = state.GetName();
         this.Decimals  = state.Precision;
     }
 }
        public void InitInstance()
        {
            outPutItems = new List <TxOutPutItem>();
            cmbAssetType.Items.Add(assetState.GetName());
            TxbAvailableAmount.Text = (assetState.Amount - assetState.Available).ToString();

            cmbAssetType.SelectedIndex = 0;
        }
Пример #4
0
        public void GetName()
        {
            UInt256   assetId;
            AssetType assetType;
            string    name;
            Fixed8    amount, available, fee;
            byte      precision;
            UInt160   feeAddress, admin, issuer;
            ECPoint   owner;
            uint      expiration;
            bool      isFrozen;

            setupAssetStateWithValues(uut, out assetId, out assetType, out name, out amount, out available, out precision, out fee, out feeAddress, out owner, out admin, out issuer, out expiration, out isFrozen);

            uut.GetName().Should().Be("krona");
            // The base class GetName() method should be be optimised to avoid the slow try / catch
        }
Пример #5
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);
 }
Пример #6
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
         {
             AssetName  = $"{asset.GetName()} ({asset.Owner})",
             AssetId    = output.AssetId,
             Value      = new BigDecimal(output.Value.GetData(), 8),
             ScriptHash = output.ScriptHash
         });
     }
     ItemsChanged?.Invoke(this, EventArgs.Empty);
 }
Пример #7
0
        public static string CustomGetAssetName(AssetState state, CultureInfo culture = null)
        {
            string name = state.GetName();

            if (name != null)
            {
                if (name == "NEO")
                {
                    name = "CRONIUM";
                }
                if (name == "NeoGas")
                {
                    name = "CRON";
                }
            }
            return(name);
        }
Пример #8
0
        private void TxbIssueAssetID_TextChanged(object sender, TextChangedEventArgs e)
        {
            AssetState state = null;

            if (UInt256.TryParse(TxbIssueAssetID.Text, out UInt256 asset_id))
            {
                state = Blockchain.Default.GetAssetState(asset_id);
            }

            if (state == null)
            {
                state = null;
                TxbIssueAssetName.Text      = "";
                TxbIssueAssetOwner.Text     = "";
                TxbIssueAssetAdmin.Text     = "";
                TxbIssueAssetAmount.Text    = "";
                TxbIssueAssetIssued.Text    = "";
                TxbIssueAssetPrecision.Text = "";
                StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_ERR_NOT_FOUND_ASSET", iLang));
                BtnMakeOutput.IsEnabled  = false;
                BtnIssueLaunch.IsEnabled = false;

                BtnMakeOutput.Style  = FindResource("QurasDisableAddAssetButtonStyle") as Style;
                BtnIssueLaunch.Style = FindResource("QurasDisableAddAssetButtonStyle") as Style;
                return;
            }


            TxbIssueAssetName.Text      = state.GetName();
            TxbIssueAssetOwner.Text     = state.Owner.ToString();
            TxbIssueAssetAdmin.Text     = Wallet.ToAddress(state.Admin);
            TxbIssueAssetAmount.Text    = state.Amount.ToString();
            TxbIssueAssetIssued.Text    = state.Available.ToString();
            TxbIssueAssetPrecision.Text = state.Precision.ToString();

            BtnMakeOutput.IsEnabled = true;
            BtnMakeOutput.Style     = FindResource("QurasAddAssetButtonStyle") as Style;
            assetState = state;
            StaticUtils.ShowMessageBox(StaticUtils.GreenBrush, StringTable.GetInstance().GetString("STR_FOUND_ASSET", iLang));
        }
Пример #9
0
        public void RefreshInterface()
        {
            tbAssetName.Text = Asset.GetName();
            tbBalance.Text   = Windows.Helper.FormatNumber(Value.ToString());

            Fixed8 usdBalance;

            if (Asset.AssetId == Blockchain.GoverningToken.Hash)
            {
                tbBalanceUSD.Text = $"${Windows.Helper.FormatNumber((Value * Fixed8.Satoshi * 8000000).ToString())}";
            }
            else if (Asset.AssetId == Blockchain.UtilityToken.Hash)
            {
                tbBalanceUSD.Text = $"${Windows.Helper.FormatNumber((Value * Fixed8.Satoshi * 2000000).ToString())}";
            }
            else
            {
                tbBalanceUSD.Text = $"${Windows.Helper.FormatNumber(((double)((decimal)Value) * Rate).ToString())}";
            }


            tbPrecision.Text   = String.Format(StringTable.GetInstance().GetString("STR_MENU_ASSET_PRECISION", iLang), Asset.Precision.ToString());
            tbTotalSupply.Text = String.Format(StringTable.GetInstance().GetString("STR_MENU_ASSET_TOTAL_SUPPLY", iLang), Windows.Helper.FormatNumber(Asset.Amount.ToString()));
        }
Пример #10
0
 public AssetDescriptor(AssetState state)
 {
     this.AssetId   = state.AssetId;
     this.AssetName = state.GetName();
     this.Precision = state.Precision;
 }
        private static JArray GetMempoolTransaction(UInt160 ScriptHash)
        {
            JArray result = new JArray();

            foreach (Transaction tx in LocalNode.GetMemoryPool())
            {
                UInt160 from_script = null;
                UInt160 to_script   = null;
                JObject obj         = new JObject();

                if (tx is ContractTransaction)
                {
                    try
                    {
                        foreach (CoinReference input in tx.Inputs)
                        {
                            Transaction inputTx = Blockchain.Default.GetTransaction(input.PrevHash);
                            if (inputTx != null)
                            {
                                from_script = inputTx.Outputs[input.PrevIndex].ScriptHash;
                            }
                            else
                            {
                                foreach (Transaction inTx in LocalNode.GetMemoryPool())
                                {
                                    if (inTx.Hash.Equals(input.PrevHash))
                                    {
                                        from_script = inTx.Outputs[input.PrevIndex].ScriptHash;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex) { }

                    if (tx.Outputs.Length > 0)
                    {
                        to_script = tx.Outputs[0].ScriptHash;
                    }

                    Dictionary <UInt256, Fixed8> balance = new Dictionary <UInt256, Fixed8>();
                    Dictionary <UInt256, Fixed8> fee     = new Dictionary <UInt256, Fixed8>();
                    for (int i = 0; i < tx.Outputs.Length; i++)
                    {
                        AssetState state = Blockchain.Default.GetAssetState(tx.Outputs[i].AssetId);
                        if (tx.Outputs[i].ScriptHash.Equals(to_script))
                        {
                            if (balance.ContainsKey(tx.Outputs[i].AssetId))
                            {
                                balance[tx.Outputs[i].AssetId] += tx.Outputs[i].Value;
                            }
                            else
                            {
                                balance[tx.Outputs[i].AssetId] = tx.Outputs[i].Value;
                            }
                        }

                        if (!fee.ContainsKey(tx.Outputs[i].AssetId))
                        {
                            if (tx.Outputs[i].Fee != Fixed8.Zero)
                            {
                                fee[tx.Outputs[i].AssetId] = tx.Outputs[i].Fee;
                            }
                        }
                    }
                    Fixed8 qrgFee = fee.Sum(p => p.Value);
                    if (balance.Count > 0)
                    {
                        UInt256 assetId = balance.First().Key;
                        Fixed8  value   = balance.Sum(p => p.Value);

                        AssetState assetState = Blockchain.Default.GetAssetState(assetId);
                        obj["asset"]  = assetState.GetName();
                        obj["amount"] = value.ToString();
                        obj["fee"]    = qrgFee.ToString();
                    }
                }
                else if (tx is ClaimTransaction)
                {
                    ClaimTransaction claimTx = (ClaimTransaction)tx;
                    if (claimTx.Outputs.Length > 0)
                    {
                        from_script = to_script = tx.Outputs[0].ScriptHash;
                    }

                    Dictionary <UInt256, Fixed8> balance = new Dictionary <UInt256, Fixed8>();
                    Dictionary <UInt256, Fixed8> fee     = new Dictionary <UInt256, Fixed8>();

                    for (int i = 0; i < tx.Outputs.Length; i++)
                    {
                        AssetState state = Blockchain.Default.GetAssetState(tx.Outputs[i].AssetId);
                        if (tx.Outputs[i].ScriptHash.Equals(to_script))
                        {
                            if (balance.ContainsKey(tx.Outputs[i].AssetId))
                            {
                                balance[tx.Outputs[i].AssetId] += tx.Outputs[i].Value;
                            }
                            else
                            {
                                balance[tx.Outputs[i].AssetId] = tx.Outputs[i].Value;
                            }
                        }

                        if (!fee.ContainsKey(tx.Outputs[i].AssetId))
                        {
                            if (tx.Outputs[i].Fee != Fixed8.Zero)
                            {
                                fee[tx.Outputs[i].AssetId] = tx.Outputs[i].Fee;
                            }
                        }
                    }
                    obj["asset"]  = Blockchain.UtilityToken.Name;
                    obj["amount"] = balance[Blockchain.UtilityToken.Hash].value.ToString();
                    obj["fee"]    = Fixed8.Zero.ToString();
                }
                else if (tx is InvocationTransaction)
                {
                    InvocationTransaction invocTx = (InvocationTransaction)tx;
                    try
                    {
                        foreach (CoinReference input in tx.Inputs)
                        {
                            from_script = tx.References[input].ScriptHash;
                        }
                    }
                    catch (Exception ex) { }
                    obj["asset"]  = Blockchain.UtilityToken.Name;
                    obj["amount"] = invocTx.Gas.ToString();
                    obj["fee"]    = Fixed8.Zero.ToString();
                }
                else if (tx is IssueTransaction)
                {
                    AssetState       state   = Blockchain.Default.GetAssetState(Blockchain.UtilityToken.Hash);
                    IssueTransaction issueTx = (IssueTransaction)tx;

                    try
                    {
                        foreach (CoinReference input in tx.Inputs)
                        {
                            from_script = tx.References[input].ScriptHash;
                        }
                    }
                    catch (Exception ex) { }

                    if (tx.Outputs.Length > 0)
                    {
                        to_script = tx.Outputs[0].ScriptHash;
                    }


                    if (tx.Outputs.Length > 0)
                    {
                        state = Blockchain.Default.GetAssetState(tx.Outputs[0].AssetId);
                    }

                    Fixed8 totalAmount = Fixed8.Zero;
                    foreach (TransactionOutput output in tx.Outputs)
                    {
                        if (output.AssetId != Blockchain.UtilityToken.Hash)
                        {
                            totalAmount += output.Value;
                        }
                    }

                    Fixed8 fee = issueTx.NetworkFee + issueTx.SystemFee;

                    obj["asset"]  = state.GetName();
                    obj["amount"] = totalAmount.ToString();
                    obj["fee"]    = fee.ToString();
                }

                if (!ScriptHash.Equals(from_script) && !ScriptHash.Equals(to_script))
                {
                    continue;
                }

                if (from_script != null)
                {
                    obj["from"] = Wallet.ToAddress(from_script);
                }
                else
                {
                    obj["from"] = "";
                }

                if (to_script != null)
                {
                    obj["to"] = Wallet.ToAddress(to_script);
                }
                else
                {
                    obj["to"] = "";
                }

                obj["txType"]      = tx.Type;
                obj["blockHeight"] = Fixed8.Zero.ToString();
                obj["txid"]        = tx.Hash.ToString();
                obj["timestamp"]   = DateTime.Now.ToTimestamp();
                obj["status"]      = 0;
                result.Add(obj);
            }
            return(result);
        }