예제 #1
0
        private void BtnEstimateGas_Click(object sender, EventArgs e)
        {
            UInt160 to;
            Decimal value;

            try
            {
                to = ZoroHelper.GetPublicKeyHashFromAddress(tbxTo.Text);
            }
            catch
            {
                MessageBox.Show("To address error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                value = Decimal.Parse(tbxValue.Text, NumberStyles.Float) * new Decimal(Math.Pow(10, Decimals));
            }
            catch
            {
                MessageBox.Show("Value error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                if (Symbol == "ZORO" || Symbol == "BCT")
                {
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", AssetId, Account.ScriptHash, to, new BigInteger(value));
                }
                else
                {
                    sb.EmitAppCall(AssetId, "transfer", Account.ScriptHash, to, new BigInteger(value));
                }

                var tx = ZoroHelper.MakeTransaction(sb.ToArray(), Account.GetKey(), Fixed8.Zero, Fixed8.FromDecimal(0.0001m));

                var script = sb.ToArray().ToHexString();
                Zoro.IO.Json.JArray _params = new Zoro.IO.Json.JArray();
                _params.Add("");
                _params.Add(tx.ToArray().ToHexString());

                var info = Handler.Process("estimategas", _params);

                JObject json_response     = JObject.Parse(info.ToString());
                string  json_gas_consumed = json_response["gas_consumed"].ToString();

                tbxGasLimit.Text = json_gas_consumed;
            }
        }
예제 #2
0
        public JObject HandleRequest(RpcRequestPayload payload)
        {
            JArray _params = null;

            try
            {
                JObject parameters = JArray.Parse(payload.Params);

                if (parameters is JArray)
                {
                    _params = (JArray)parameters;
                }
            }
            catch
            {
            }

            if (_params == null)
            {
                throw new RpcException(-32602, "Error occurred when parsing parameters.");
            }

            JObject result = PluginManager.Singleton.ProcessRpcMethod(null, payload.Method, _params);

            if (result == null)
            {
                result = handler.Process(payload.Method, _params);
            }

            return(result);
        }
예제 #3
0
        private void GetBalance(UInt160 assetHash, WalletAccount account)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(assetHash, "balanceOf", account.ScriptHash);
                sb.EmitAppCall(assetHash, "decimals");
                sb.EmitAppCall(assetHash, "symbol");

                var script = sb.ToArray().ToHexString();
                Zoro.IO.Json.JArray _params = new Zoro.IO.Json.JArray();
                _params.Add("");
                _params.Add(script);

                var info = Handler.Process("invokescript", _params);

                JObject json = JObject.Parse(info.ToString());
                if (json.ContainsKey("stack"))
                {
                    JArray stack = json["stack"] as JArray;

                    if (stack[0]["value"].ToString() == "" || stack[1]["value"].ToString() == "" || stack[2]["value"].ToString() == "")
                    {
                        return;
                    }

                    string value    = ZoroHelper.GetJsonValue((JObject)stack[0]);
                    string decimals = BigInteger.Parse(stack[1]["value"].ToString()).ToString();
                    string symbol   = Encoding.UTF8.GetString(ZoroHelper.HexString2Bytes(stack[2]["value"].ToString()));

                    decimal balance = Math.Round(decimal.Parse(value) / (decimal)Math.Pow(10, double.Parse(decimals)), int.Parse(decimals));

                    if (balance > 0)
                    {
                        IsShow = true;
                        this.lblAddress.Text = account.Address;
                        this.lblAsset.Text   = assetHash.ToString() + "(" + symbol + ")";
                        this.lblBalance.Text = balance.ToString();

                        Account     = account;
                        AssetHash   = assetHash;
                        AssetSymbol = symbol;
                        Decimals    = int.Parse(decimals);
                    }
                }
            }
        }