Exemplo n.º 1
0
        private static WithdrawInfo GetTransferInfo(string coinType, string txid, JArray jValue, JToken tx)
        {
            var address = ZoroHelper.GetJsonAddress((JObject)jValue[1]);
            var amount  = ZoroHelper.GetJsonDecimal((JObject)jValue[3], 8);

            if (((JArray)tx["attributes"]).Count > 0)
            {
                JObject attribute = (JObject)tx["attributes"][0];
                string  usage     = (string)attribute["usage"];
                string  data      = Encoding.UTF8.GetString(ZoroHelper.HexString2Bytes((string)attribute["data"]));
                if (usage != "Remark1")
                {
                    return(null);
                }
                WithdrawInfo withdrawInfo = new WithdrawInfo();
                withdrawInfo.Method         = "withdraw";
                withdrawInfo.FromAddress    = address;
                withdrawInfo.ReceiveAddress = data;
                withdrawInfo.Value          = amount;
                withdrawInfo.CoinType       = coinType;

                Logger.Info("Zoro destroy: Address:" + withdrawInfo.FromAddress + ", CoinType:" + withdrawInfo.CoinType + " , Value:" + withdrawInfo.Value + ", Txid: " + txid);

                return(withdrawInfo);
            }
            return(null);
        }
Exemplo n.º 2
0
        private static decimal GetZoroBalance(string coinType, string address)
        {
            string  tokenHash = Config._nep5TokenHashDict[coinType];
            UInt160 nep5Hash  = UInt160.Parse(tokenHash);
            var     addrHash  = ZoroHelper.GetPublicKeyHashFromAddress(address);

            ScriptBuilder sb = new ScriptBuilder();

            if (coinType == "bct" || coinType == "bcp" || coinType == "zoro")
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", nep5Hash, addrHash);
            }
            else
            {
                sb.EmitAppCall(nep5Hash, "balanceOf", addrHash);
            }

            var info = ZoroHelper.InvokeScript(sb.ToArray(), "");

            JObject json  = JObject.Parse(info);
            decimal value = 0;

            if (json.ContainsKey("result"))
            {
                JObject json_result = json["result"] as JObject;
                JArray  stack       = json_result["stack"] as JArray;

                string result = ZoroHelper.GetJsonValue(stack[0] as JObject);
                value = Math.Round(decimal.Parse(result) / (decimal)Math.Pow(10, Config._nep5TokenDecimalDict[coinType]), Config._nep5TokenDecimalDict[coinType]);
            }

            return(value);
        }
Exemplo n.º 3
0
        private void BtnSend_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbxGasLimit.Text))
            {
                MessageBox.Show("Please estimategas first!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            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, 8));
            }
            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));
                }

                decimal gasLimit = decimal.Parse(tbxGasLimit.Text);
                decimal gasPrice = decimal.Parse(tbxGasPrice.Text);

                var tx = ZoroHelper.MakeTransaction(sb.ToArray(), Account.GetKey(), Fixed8.FromDecimal(gasLimit), Fixed8.FromDecimal(gasPrice));

                string txid = tx.Hash.ToString();

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

                var result = Handler.Process("sendrawtransaction", _params);

                string[] text = new string[] { "Result : " + result.ToString(), "Txid : " + txid };

                tbxResult.Lines = text;
            }
        }
Exemplo n.º 4
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;
            }

            try
            {
                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));

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

                    var info = Program.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;
                }
            }
            catch
            {
                MessageBox.Show("Transaction!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Exemplo n.º 5
0
        private static dynamic MintTokenResult(JArray jValue)
        {
            dynamic mintTokenLog = new ExpandoObject();

            mintTokenLog.address    = ZoroHelper.GetJsonAddress((JObject)jValue[1]);
            mintTokenLog.tokenId    = jValue[2]["value"].ToString();
            mintTokenLog.properties = jValue[3]["value"].ToString();

            return(mintTokenLog);
        }
Exemplo n.º 6
0
        private static dynamic DepositResult(JArray jValue)
        {
            dynamic depositLog = new ExpandoObject();

            depositLog.Address = ZoroHelper.GetJsonAddress((JObject)jValue[1]);
            depositLog.AssetId = ZoroHelper.GetJsonHash((JObject)jValue[2]);
            depositLog.Amount  = ZoroHelper.GetJsonDecimal((JObject)jValue[3], 8);

            return(depositLog);
        }
Exemplo n.º 7
0
        private static dynamic TransferTokenResult(JArray jValue)
        {
            dynamic transferTokenLog = new ExpandoObject();

            transferTokenLog.from    = ZoroHelper.GetJsonAddress((JObject)jValue[1]);
            transferTokenLog.to      = ZoroHelper.GetJsonAddress((JObject)jValue[2]);
            transferTokenLog.tokenId = jValue[3]["value"].ToString();

            return(transferTokenLog);
        }
Exemplo n.º 8
0
        public static async Task <decimal> getNativeDecimalBalanceOfAsync(string chainHash, string assetid, string address)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", UInt160.Parse(assetid), ZoroHelper.GetPublicKeyHashFromAddress(address));
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", UInt160.Parse(assetid));
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Symbol", UInt160.Parse(assetid));
                var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash);

                var value = GetDecimalBalanceFromJson(info);
                return(value);
            }
        }
Exemplo n.º 9
0
        private static dynamic CancelOffer(JArray notifications)
        {
            dynamic cancelOfferLog = new ExpandoObject();

            cancelOfferLog.OfferAddress    = ZoroHelper.GetJsonAddress((JObject)notifications[1]);
            cancelOfferLog.OfferHash       = notifications[2]["value"].ToString();
            cancelOfferLog.NftHash         = ZoroHelper.GetJsonHash((JObject)notifications[3]);
            cancelOfferLog.TokenId         = notifications[4]["value"].ToString();
            cancelOfferLog.OfferFeeAssetId = ZoroHelper.GetJsonHash((JObject)notifications[5]);
            cancelOfferLog.FeeReturnAmount = ZoroHelper.GetJsonDecimal((JObject)notifications[6], 8);
            cancelOfferLog.DeductFee       = ZoroHelper.GetJsonDecimal((JObject)notifications[7], 8);
            return(cancelOfferLog);
        }
Exemplo n.º 10
0
        public static async Task <decimal> getDecimalBalanceOfAsync(string chainHash, string assetid, string address)
        {
            using (Neo.VM.ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(ZoroHelper.Parse(assetid), "balanceOf", ZoroHelper.GetPublicKeyHashFromAddress(address));
                sb.EmitAppCall(ZoroHelper.Parse(assetid), "decimals");
                sb.EmitAppCall(ZoroHelper.Parse(assetid), "symbol");

                var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash);

                var value = GetDecimalBalanceFromJson(info);
                return(value);
            }
        }
Exemplo n.º 11
0
        private static dynamic MakeOfferResult(JArray notifications)
        {
            dynamic makeOfferLog = new ExpandoObject();

            makeOfferLog.Address         = ZoroHelper.GetJsonAddress((JObject)notifications[1]);
            makeOfferLog.OfferHash       = notifications[2]["value"].ToString();
            makeOfferLog.NftContractHash = ZoroHelper.GetJsonHash((JObject)notifications[3]);
            makeOfferLog.TokenId         = notifications[4]["value"].ToString();
            makeOfferLog.AcceptAssetId   = ZoroHelper.GetJsonHash((JObject)notifications[5]);
            makeOfferLog.Price           = ZoroHelper.GetJsonDecimal((JObject)notifications[6], 8);
            makeOfferLog.FeeAssetId      = ZoroHelper.GetJsonHash((JObject)notifications[7]);
            makeOfferLog.FeeAmount       = ZoroHelper.GetJsonDecimal((JObject)notifications[8], 8);

            return(makeOfferLog);
        }
Exemplo n.º 12
0
        private static Dictionary <string, decimal> GetZoroBalances(string coinType, JArray addrJArray)
        {
            Dictionary <string, decimal> balanceDict = new Dictionary <string, decimal>();

            ScriptBuilder sb        = new ScriptBuilder();
            string        tokenHash = Config._nep5TokenHashDict[coinType];
            UInt160       nep5Hash  = UInt160.Parse(tokenHash);

            for (int i = 0; i < addrJArray.Count; i++)
            {
                var addrHash = ZoroHelper.GetPublicKeyHashFromAddress(addrJArray[i].ToString());

                if (coinType == "bct" || coinType == "bcp" || coinType == "zoro")
                {
                    sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", nep5Hash, addrHash);
                }
                else
                {
                    sb.EmitAppCall(nep5Hash, "balanceOf", addrHash);
                }
            }

            var info = ZoroHelper.InvokeScript(sb.ToArray(), "");

            JObject json = JObject.Parse(info);

            if (json.ContainsKey("result"))
            {
                JObject json_result = json["result"] as JObject;
                JArray  stackJArray = json_result["stack"] as JArray;

                if (addrJArray.Count == stackJArray.Count)
                {
                    int i = 0;
                    for (int j = 0; j < stackJArray.Count; j++)
                    {
                        string  result = ZoroHelper.GetJsonValue(stackJArray[j] as JObject);
                        decimal value  = Math.Round(decimal.Parse(result) / (decimal)Math.Pow(10, Config._nep5TokenDecimalDict[coinType]), Config._nep5TokenDecimalDict[coinType]);

                        balanceDict[addrJArray[i].ToString()] = value;
                        i++;
                    }
                }
            }

            return(balanceDict);
        }
Exemplo n.º 13
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);
                    }
                }
            }
        }
Exemplo n.º 14
0
        private string GetBalanceFromJson(string info)
        {
            string  result = "";
            JObject json   = JObject.Parse(info);

            JArray stack = json["stack"] as JArray;

            if (stack != null && stack.Count > 0)
            {
                string balance = ZoroHelper.GetJsonValue(stack[0] as JObject);

                Decimal value = Decimal.Parse(balance) / new Decimal(Math.Pow(10, 8));
                string  fmt   = "{0:N" + 8 + "}";
                result = string.Format(fmt, value);
            }

            return(result);
        }
Exemplo n.º 15
0
        private static dynamic FillOfferResult(JArray notifications)
        {
            dynamic fillOfferLog = new ExpandoObject();

            fillOfferLog.FillAddress     = ZoroHelper.GetJsonAddress((JObject)notifications[1]);
            fillOfferLog.OfferHash       = notifications[2]["value"].ToString();
            fillOfferLog.OfferAddress    = ZoroHelper.GetJsonAddress((JObject)notifications[3]);
            fillOfferLog.FillAssetId     = ZoroHelper.GetJsonHash((JObject)notifications[4]);
            fillOfferLog.FillAmount      = ZoroHelper.GetJsonDecimal((JObject)notifications[5], 8);
            fillOfferLog.NftHash         = ZoroHelper.GetJsonHash((JObject)notifications[6]);
            fillOfferLog.TokenId         = notifications[7]["value"].ToString();
            fillOfferLog.FillFeeAssetId  = ZoroHelper.GetJsonHash((JObject)notifications[8]);
            fillOfferLog.FillFeeAmount   = ZoroHelper.GetJsonDecimal((JObject)notifications[9], 8);
            fillOfferLog.OfferFeeAssetId = ZoroHelper.GetJsonHash((JObject)notifications[10]);
            fillOfferLog.OfferFeeAmount  = ZoroHelper.GetJsonDecimal((JObject)notifications[11], 8);

            return(fillOfferLog);
        }
Exemplo n.º 16
0
        private static void SendGameIssueResult(ulong currentHeight, ulong blockTime, string txid, string coinType, JArray jValue, string method)
        {
            dynamic transferInfo = new ExpandoObject();

            var address = ZoroHelper.GetJsonAddress((JObject)jValue[2]);
            var amount  = ZoroHelper.GetJsonDecimal((JObject)jValue[3], 8);

            transferInfo.height    = currentHeight;
            transferInfo.blockTime = blockTime;
            transferInfo.txid      = txid;
            transferInfo.coinType  = coinType;
            transferInfo.method    = method;
            transferInfo.from      = Config._gameConfig.IssueAddress;
            transferInfo.to        = address;
            transferInfo.value     = amount;

            Logger.Info("Zoro shgame send;Height:" + currentHeight + ", Address:" + address + ", CoinType:" + coinType + " , Value:" + amount + ", Txid: " + txid);

            string url      = Config._gameConfig.GameUrl + "/sysGame/transConfirm";
            string jsonData = JsonConvert.SerializeObject(transferInfo);

            SendTransTimer(jsonData, url);
        }
Exemplo n.º 17
0
        private void GetBalance(UInt160 assetHash, WalletAccount account)
        {
            try
            {
                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    if (assetHash == Genesis.BcpContractAddress || assetHash == Genesis.BctContractAddress)
                    {
                        sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", assetHash, Account.ScriptHash);
                        sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", assetHash);
                        sb.EmitSysCall("Zoro.NativeNEP5.Call", "Symbol", assetHash);
                    }
                    else
                    {
                        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);


                    Zoro.IO.Json.JObject info;
                    info = Program.Handler.Process("invokescript", _params);


                    JObject json = JObject.Parse(info.ToString());
                    string  decimals;
                    string  symbol  = "";
                    decimal balance = 0.00m;

                    if (json.ContainsKey("stack"))
                    {
                        JArray stack = json["stack"] as JArray;

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

                        if (stack[0]["value"].ToString() == "" || stack[1]["value"].ToString() == "" || stack[2]["value"].ToString() == "")
                        {
                            this.lblBalance.Text     = "0.00";
                            this.btnTransfer.Enabled = false;
                        }
                        else
                        {
                            string value = ZoroHelper.GetJsonValue((JObject)stack[0]);

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

                            if (balance != 0)
                            {
                                this.btnTransfer.Enabled = true;
                            }
                        }

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

                    this.lblAsset.Text   = assetHash.ToString() + "(" + symbol + ")";
                    this.lblBalance.Text = balance.ToString();
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 18
0
        public async Task <object> getResAsync(JsonRPCrequest req, string reqAddr)
        {
            JArray result     = new JArray();
            string resultStr  = string.Empty;
            string findFliter = string.Empty;
            string sortStr    = string.Empty;

            try
            {
                switch (req.method)
                {
                    #region 获取block
                case "getblock":
                    result = msq.GetBlock(req);
                    break;

                case "getacblock":
                    result = msq.GetAppChainBlock(req);
                    break;
                    #endregion

                    #region 获取blocks
                case "getblocks":
                    result = msq.GetBlocks(req);
                    break;

                case "getappchainblocks":
                    result = msq.GetAppchainBlocks(req);
                    break;

                case "getblocksdesc":
                    result = msq.GetBlocksDESC(req);
                    break;

                case "getappchainblocksdesc":
                    result = msq.GetAppchainBlocksDESC(req);
                    break;

                case "getblocksdesccache":
                    result = msq.GetBlocksDESCCache(req);
                    break;

                case "getappchainblocksdesccache":
                    result = msq.GetAppchainBlocksDESCCache(req);
                    break;
                    #endregion

                    #region 获取block from hash
                case "getblockfromhash":
                    result = msq.GetBlockFromHash(req);
                    break;

                case "getappchainblockfromhash":
                    result = msq.GetAppChainBlockFromHash(req);
                    break;
                    #endregion

                    #region 获取blockcount
                case "getblockcount":
                    var blockcount = Helper.MakeRpcUrl(ZoroHelper.ZoroUrl, "getblockcount", rootChain);
                    var s          = await Helper.HttpGet(blockcount);

                    var a = new JArray();
                    a.Add(new JObject {
                        { "blockcount", JObject.Parse(s)["result"].ToString() }
                    });
                    result = a;
                    break;

                case "getappchainblockcount":
                    var appchainblockcount = Helper.MakeRpcUrl(ZoroHelper.ZoroUrl, "getblockcount", req.@params[0].ToString());
                    var apps = await Helper.HttpGet(appchainblockcount);

                    var appa = new JArray();
                    appa.Add(new JObject {
                        { "blockcount", JObject.Parse(apps)["result"].ToString() }
                    });
                    result = appa;
                    break;
                    #endregion

                    #region 获取爬虫爬到的blockcount
                case "getdatablockheight":
                    result = msq.GetDataBlockHeight(req);
                    break;

                case "getappchaindatablockheight":
                    result = msq.GetAppchainBlockCount(req);
                    break;
                    #endregion

                    #region 获取addrcount
                case "getaddrcount":
                    result = msq.GetAddrCount(req);
                    break;

                case "getappchainaddrcount":
                    result = msq.GetAppchainAddrCount(req);
                    break;
                    #endregion

                    #region 获取txcount
                case "gettxcount":
                    result = msq.GetTxCount(req);
                    break;

                case "getappchaintxcount":
                    result = msq.GetAppchainTxCount(req);
                    break;
                    #endregion

                    #region 获取rawtransaction
                case "getrawtransaction":
                    result = msq.GetRawTransaction(req);
                    break;

                case "getacrawtransaction":
                    result = msq.GetAppChainRawTransaction(req);
                    break;
                    #endregion

                    #region 获取transaction
                case "gettransaction":
                    result = msq.GetTransaction(req);
                    break;

                case "getactransaction":
                    result = msq.GetAppChainTransaction(req);
                    break;
                    #endregion

                    #region 获取transaction_ex
                case "gettransactions_ex":
                    result = msq.GetTransactions_EX(req);
                    break;

                case "getactransactions_ex":
                    result = msq.GetAppChainTransactions_EX(req);
                    break;
                    #endregion

                    #region 获取rawtransactions
                case "getrawtransactions":
                    result = msq.GetRawTransactions(req);
                    break;

                case "getappchainrawtransactions":
                    result = msq.GetAppchainRawTransactions(req);
                    break;

                case "getrawtransactionsdesc":
                    result = msq.GetRawTransactionsDESC(req);
                    break;

                case "getappchainrawtransactionsdesc":
                    result = msq.GetAppchainRawTransactionsDESC(req);
                    break;

                case "getrawtransactionsdesccache":
                    result = msq.GetRawTransactionsDESCCache(req);
                    break;

                case "getappchainrawtransactionsdesccache":
                    result = msq.GetAppchainRawTransactionsDESCCache(req);
                    break;
                    #endregion

                    #region 获取allnep5asset
                case "getallnep5asset":
                    result = msq.GetAllNep5Asset(req);
                    break;

                case "getappchainallnep5asset":
                    result = msq.GetAllNep5AssetByChainHash(req);
                    break;
                    #endregion

                    #region 获取hashlist,appchain
                case "gethashlist":
                    result = msq.GetHashlist(req);
                    break;

                case "getallappchains":
                    result = msq.GetAllAppchains(req);
                    break;

                case "getappchain":
                    result = msq.GetAppchain(req);
                    break;
                    #endregion

                    #region 获取nep5asset
                case "getnep5asset":
                    result = msq.GetNep5Asset(req);
                    break;

                case "getappchainnep5asset":
                    result = msq.GetAppChainNep5Asset(req);
                    break;

                case "getaddressasset":
                    result = msq.GetAddressAsset(req);
                    break;

                case "getaddressallasset":
                    result = await msq.GetAddressAllAssetAsync(req);

                    break;
                    #endregion

                    #region 获取address
                case "getaddress":
                    result = msq.GetAddress(req);
                    break;

                case "getappchainaddress":
                    result = msq.GetAppChainAddress(req);
                    break;
                    #endregion

                    #region 获取addr
                case "getaddr":
                    result = msq.GetAddr(req);
                    break;

                case "getappchainaddr":
                    result = msq.GetAppChainAddr(req);
                    break;
                    #endregion

                    #region 获取addrs
                case "getaddrs":
                    result = msq.GetAddrs(req);
                    break;

                case "getappchainaddrs":
                    result = msq.GetAppChainAddrs(req);
                    break;
                    #endregion

                    #region 获取addresstxs
                case "getaddresstxs":
                    result = msq.GetAddressTxs(req);
                    break;

                case "getappchainaddresstxs":
                    result = msq.GetAppChainAddressTxs(req);
                    break;

                case "getaddressnep5txs":
                    result = msq.GetAddressNep5Txs(req);
                    break;
                    #endregion

                    #region 获取balance
                case "getbalance":
                    result = await msq.GetBalanceByAssetAsync(req);

                    break;

                case "getbalancebyasset":
                    result = await msq.GetAssetBalanceAsync(req);

                    break;

                case "getappchainbalance":
                    result = await msq.GetAppChainBalanceAsync(req);

                    break;
                    #endregion

                    #region 获取utxo
                case "getutxo":
                    result = msq.GetUTXO(req);
                    break;

                case "getappchainutxo":
                    result = msq.GetAppChainUTXO(req);
                    break;
                    #endregion

                    #region 获取rankasset
                case "getrankbyasset":
                    result = msq.GetRankByAsset(req);
                    break;

                case "getappchainrankbyasset":
                    result = msq.GetAppChainRankByAsset(req);
                    break;
                    #endregion

                    #region 获取rankbyassetcount
                case "getrankbyassetcount":
                    result = msq.GetRankByAssetCount(req);
                    break;

                case "getappchainrankbyassetcount":
                    result = msq.GetAppChainRankByAssetCount(req);
                    break;
                    #endregion

                    #region 获取nep5transferbytxid
                case "getnep5transferbytxid":
                    result = msq.GetNep5TransferByTxid(req);
                    break;

                case "getappchainnep5transferbytxid":
                    result = msq.GetAppChainNep5TransferByTxid(req);
                    break;
                    #endregion

                    #region 获取nep5transferbytxidex
                case "getnep5transferbytxidex":
                    result = msq.GetNep5TransferByTxidEX(req);
                    break;

                case "getappchainnep5transferbytxidex":
                    result = msq.GetAppChainNep5TransferByTxidEX(req);
                    break;
                    #endregion

                    #region 获取nep5transferbytxids
                case "getnep5transferbytxids":
                    result = msq.GetNep5TransferByTxids(req);
                    break;

                case "gettransferbytxids":
                    result = msq.GetTransferByTxids(req);
                    break;
                    #endregion

                    #region 获取nep5transfer
                case "getnep5transfer":
                    result = msq.GetNep5Transfer(req);
                    break;

                case "getappchainnep5transfer":
                    result = msq.GetAppChainNep5Transfer(req);
                    break;

                case "getnep5transferbyasset":
                    result = msq.GetNep5TransferByAsset(req);
                    break;

                case "getnep5transferbyassetandaddress":
                    result = msq.GetNep5TransferByAssetAndAddress(req);
                    break;

                case "getsendallamountbyaddress":
                    result = msq.GetSendAllAmountByAddress(req);
                    break;

                    #endregion

                    #region 获取 nft 相关信息
                case "getnftfromaddrandhash":
                    result = msq.GetNFTFromAddrAndHash(req);
                    break;

                case "getnfthashfromaddr":
                    result = msq.GetNFTHashFromAddr(req);
                    break;

                case "getnftfromhash":
                    result = msq.GetNFTFromHash(req);
                    break;

                case "gettokenproperties":
                    result = msq.getProperties(req);
                    break;
                    #endregion

                    #region 和链交互
                case "sendrawtransaction":
                    var tx = "";
                    if ([email protected] > 1)
                    {
                        if (req.@params[0].ToString() == "")
                        {
                            chainhash = rootChain;
                        }
                        else
                        {
                            chainhash = req.@params[0].ToString();
                        }

                        tx = await ZoroHelper.SendRawTransaction(req.@params[1].ToString(), chainhash);
                    }
                    else
                    {
                        //byte[] postArray = APIHelper.HexString2Bytes(req.@params[0].ToString());
                        tx = await ZoroHelper.SendRawTransaction(req.@params[0].ToString(), rootChain);
                    }
                    if (JObject.Parse(tx)["result"].ToString() == "True")
                    {
                        result = new JArray()
                        {
                            new JObject {
                                { "sendrawtransactionresult", JObject.Parse(tx)["result"] }
                            }
                        }
                    }
                    ;
                    else
                    {
                        result = new JArray()
                        {
                            JObject.Parse(tx)["result"]
                        }
                    };
                    break;

                case "invokescript":
                    var invokescript = "";
                    if ([email protected] > 1)
                    {
                        byte[] postArray = APIHelper.HexString2Bytes(req.@params[1].ToString());
                        invokescript = await ZoroHelper.InvokeScript(postArray, req.@params[0].ToString());
                    }
                    else
                    {
                        byte[] postArray = APIHelper.HexString2Bytes(req.@params[0].ToString());
                        invokescript = await ZoroHelper.InvokeScript(postArray, rootChain);
                    }
                    result = new JArray()
                    {
                        JObject.Parse(invokescript)["result"]
                    };
                    break;

                case "estimategas":
                    decimal estimategas = 0;
                    if ([email protected] > 1)
                    {
                        //byte[] postArray = APIHelper.HexString2Bytes(req.@params[1].ToString());
                        estimategas = await ZoroHelper.EstimateGas(req.@params[1].ToString(), req.@params[0].ToString());
                    }
                    else
                    {
                        //byte[] postArray = APIHelper.HexString2Bytes(req.@params[0].ToString());
                        estimategas = await ZoroHelper.EstimateGas(req.@params[0].ToString(), rootChain);
                    }
                    result = new JArray()
                    {
                        new JObject {
                            { "gas", estimategas }
                        }
                    };
                    break;

                case "getcontractstate":
                    var url = "";
                    if ([email protected] > 1)
                    {
                        byte[] postArray           = null;
                        Zoro.IO.Json.JArray jArray = new Zoro.IO.Json.JArray();
                        jArray.Add(req.@params[0].ToString());
                        jArray.Add(req.@params[1].ToString());
                        url = Helper.MakeRpcUrlPost(ZoroHelper.ZoroUrl, "getcontractstate", out postArray, jArray);
                        url = await Helper.HttpPost(url, postArray);
                    }
                    else
                    {
                        byte[] postArray           = null;
                        Zoro.IO.Json.JArray jArray = new Zoro.IO.Json.JArray();
                        jArray.Add(rootChain);
                        jArray.Add(req.@params[0].ToString());
                        url = Helper.MakeRpcUrlPost(ZoroHelper.ZoroUrl, "getcontractstate", out postArray, jArray);
                        url = await Helper.HttpPost(url, postArray);
                    }
                    result = new JArray()
                    {
                        JObject.Parse(url)["result"]
                    };
                    break;
                    #endregion

                    #region 其他
                case "getpagemessage":
                    result = msq.getPageMessage(req.@params[0].ToString(), req.@params[1].ToString());
                    break;

                case "getnep5count":
                    result = msq.GetNep5Count(req);
                    break;

                case "getnep5allnep5assetofaddress":
                    result = msq.GetAllNep5AssetOfAddress(req);
                    break;

                case "getcontractmessage":
                    string contractChainHash = "";
                    string contract          = "";
                    if ([email protected] > 1)
                    {
                        if (req.@params[0].ToString() == "")
                        {
                            contractChainHash = rootChain;
                        }
                        else
                        {
                            contractChainHash = req.@params[0].ToString();
                        }
                        contract = req.@params[1].ToString();
                        if (!contract.StartsWith("0x"))
                        {
                            contract = "0x" + contract;
                        }
                        result = msq.GetContractMessage(contractChainHash, contract);
                    }
                    else
                    {
                        contract = req.@params[0].ToString();
                        if (!contract.StartsWith("0x"))
                        {
                            contract = "0x" + contract;
                        }
                        result = msq.GetContractMessage(rootChain, contract);
                    }
                    break;

                case "getallnep5assetofaddress":
                    string NEP5addr      = (string)req.@params[0];
                    bool   isNeedBalance = false;
                    string chainHash     = "";
                    if ([email protected]() > 1)
                    {
                        isNeedBalance = ((Int64)req.@params[1] == 1) ? true : false;
                    }
                    if ([email protected]() > 2)
                    {
                        chainHash = req.@params[2].ToString();
                    }

                    var assetAdds = msq.GetNep5AssetByAddress(chainHash, NEP5addr);
                    List <NEP5.AssetBalanceOfAddr> addrAssetBalances = new List <NEP5.AssetBalanceOfAddr>();
                    if (isNeedBalance)
                    {
                        //UInt160 addr = UInt160.Parse(ThinNeo.Helper.GetPublicKeyHashFromAddress(NEP5addr).ToString());
                        foreach (var assetAdd in assetAdds)
                        {
                            if (assetAdd["type"].ToString() == "NativeNep5")
                            {
                                var nep5 = await APIHelper.getNativeBalanceOfAsync(chainHash, assetAdd["assetid"].ToString(), NEP5addr);

                                if (nep5.balance != "0")
                                {
                                    addrAssetBalances.Add(nep5);
                                }
                            }
                            else
                            {
                                var nep5 = await APIHelper.getBalanceOfAsync(chainHash, assetAdd["assetid"].ToString(), NEP5addr);

                                if (nep5.balance != "0")
                                {
                                    addrAssetBalances.Add(nep5);
                                }
                            }
                        }
                    }

                    if (!isNeedBalance)
                    {
                        result = JArray.FromObject(assetAdds);
                    }
                    else
                    {
                        result = JArray.FromObject(addrAssetBalances);
                    }

                    break;
                    #endregion
                }
                if (result != null && result.Count > 0 && result[0]["errorCode"] != null)
                {
                    JsonPRCresponse_Error resE = new JsonPRCresponse_Error(req.id, (int)result[0]["errorCode"], (string)result[0]["errorMsg"], (string)result[0]["errorData"]);

                    return(resE);
                }
                if (result.Count == 0)
                {
                    JsonPRCresponse_Error resE = new JsonPRCresponse_Error(req.id, -1, "No Data", "Data does not exist");

                    return(resE);
                }
            }
            catch (Exception e)
            {
                JsonPRCresponse_Error resE = new JsonPRCresponse_Error(req.id, -100, "Parameter Error", e.Message);

                return(resE);
            }

            JsonPRCresponse res = new JsonPRCresponse();
            res.jsonrpc = req.jsonrpc;
            res.id      = req.id;
            res.result  = result;

            return(res);
        }
Exemplo n.º 19
0
        private static TransState TransParse(WebClient wc, JToken tx, ulong currentHeight, ulong blockTime)
        {
            TransState          transState       = new TransState();
            List <WithdrawInfo> withdrawInfoList = new List <WithdrawInfo>();
            string txid = tx["txid"].ToString();

            var applicationlogInfo = GetApplicationlog(wc, txid);

            var executions = applicationlogInfo["executions"] as JToken;

            if (executions[0]["vmstate"].ToString() == "FAULT, BREAK")
            {
                return(null);
            }

            var notifications = executions[0]["notifications"] as JArray;

            if (notifications == null || notifications.Count == 0)
            {
                return(null);
            }

            for (int i = 0; i < notifications.Count; i++)
            {
                string contract = notifications[i]["contract"].ToString();

                //nep5
                foreach (var token in Config._nep5TokenHashDict)
                {
                    if (contract == token.Value)
                    {
                        var    jValue = notifications[i]["state"]["value"] as JArray;
                        string method = Encoding.UTF8.GetString(ZoroHelper.HexString2Bytes(jValue[0]["value"].ToString()));

                        if (method == "transfer")
                        {
                            //游戏发奖 退款
                            if (jValue[1]["value"].ToString() == Config._gameConfig.IssueAddressHexString)
                            {
                                SendGameIssueResult(currentHeight, blockTime, txid, token.Key, jValue, method);
                                break;
                            }
                            //销毁 提币使用
                            if (jValue[2]["value"].ToString() == Config._destroyAddressHexString)
                            {
                                var withdrawInfo = GetTransferInfo(token.Key.ToUpper(), txid, jValue, tx);
                                if (withdrawInfo != null)
                                {
                                    withdrawInfoList.Add(withdrawInfo);
                                }
                                break;
                            }
                            //游戏中付款
                            else if (jValue[2]["value"].ToString() == Config._gameConfig.CollectionAddressHexString)
                            {
                                SendGameSpendResult(currentHeight, blockTime, txid, token.Key, jValue, method);
                                break;
                            }
                        }
                        break;
                    }
                }

                //nep10
                foreach (var token in Config._nftHashDict)
                {
                    if (contract == token.Value)
                    {
                        var jValue = notifications[i]["state"]["value"] as JArray;

                        string  method   = Encoding.UTF8.GetString(ZoroHelper.HexString2Bytes(jValue[0]["value"].ToString()));
                        dynamic transLog = null;
                        switch (method)
                        {
                        case "mintToken":
                            transLog = MintTokenResult(jValue);
                            break;

                        case "transfer":
                            transLog = TransferTokenResult(jValue);
                            break;

                        //case "modifyRwData":
                        //    transLog = ModifyRwDataResult(jValue);
                        //    break;
                        case "modifyProperties":
                            transLog = ModifyPropertiesResult(jValue);
                            break;

                        case "freeze":
                            transLog = FreezeTokenResult(jValue);
                            break;

                        case "unfreeze":
                            transLog = UnfreezeTokenResult(jValue);
                            break;
                        }

                        if (transLog != null && !string.IsNullOrEmpty((string)transLog.tokenId))
                        {
                            transLog.method      = method;
                            transLog.txid        = txid;
                            transLog.blockTime   = blockTime;
                            transLog.blockHeight = zoroHeight;

                            string url      = Config._gameConfig.GameUrl + "/sysGame/syncNFTInfo";
                            string jsonData = JsonConvert.SerializeObject(transLog);
                            SendNftTrans(jsonData, url);
                        }

                        break;
                    }
                }

                #region nftex
                //nft exchange
                //if (contract == Config._nftExchangeHash)
                //{
                //    var jValue = notifications[i]["state"]["value"] as JArray;
                //    string method = Encoding.UTF8.GetString(ZoroHelper.HexString2Bytes(jValue[0]["value"].ToString()));

                //    dynamic transLog = null;
                //    switch (method)
                //    {
                //        case "deposit":
                //            transLog = DepositResult(jValue);
                //            break;
                //        case "withdraw":
                //            transLog = WithdrawResult(jValue);
                //            break;
                //        case "makeOffer":
                //            transLog = MakeOfferResult(jValue);
                //            break;
                //        case "fillOffer":
                //            transLog = FillOfferResult(jValue);
                //            break;
                //        case "cancelOffer":
                //            transLog = CancelOffer(jValue);
                //            break;
                //    }

                //    if (transLog != null)
                //    {
                //        transLog.Method = method;
                //        transLog.Txid = txid;
                //        transLog.blockTime = blockTime;
                //        transLog.blockHeight = currentHeight;

                //        //string url = Config._gameConfig.GameUrl + "/sysGame/transConfirm";
                //        //string jsonData = JsonConvert.SerializeObject(transLog);
                //        //SendTransTimer(jsonData, url);
                //    }

                //    break;
                //}
                #endregion
            }

            if (withdrawInfoList.Count > 0)
            {
                transState.Txid          = txid;
                transState.VmState       = true;
                transState.Notifications = withdrawInfoList;

                return(transState);
            }

            return(null);
        }
Exemplo n.º 20
0
        private void BtnPublish_Click(object sender, EventArgs e)
        {
            if (contractScript.Length == 0)
            {
                MessageBox.Show("Contract file error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            byte[] parameter__list = ZoroHelper.HexString2Bytes(tbxParameterType.Text);
            byte[] return_type     = ZoroHelper.HexString2Bytes("05");
            int    need_storage    = cbxNeedStorge.Checked == true ? 1 : 0;
            int    need_nep4       = cbxNeedNep4.Checked == true ? 2 : 0;
            int    need_canCharge  = cbxNeedCharge.Checked == true ? 4 : 0;

            try
            {
                using (ScriptBuilder sb = new ScriptBuilder())
                {
                    var ss = need_storage | need_nep4 | need_canCharge;
                    sb.EmitPush(tbxDescri.Text);
                    sb.EmitPush(tbxEmail.Text);
                    sb.EmitPush(tbxAuthor.Text);
                    sb.EmitPush(tbxVersion.Text);
                    sb.EmitPush(tbxContractName.Text);
                    sb.EmitPush(ss);
                    sb.EmitPush(return_type);
                    sb.EmitPush(parameter__list);
                    sb.EmitPush(contractScript);
                    sb.EmitSysCall("Zoro.Contract.Create");

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

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

                    //var info = Program.Handler.Process("estimategas", _params);
                    //JObject json_response = JObject.Parse(info.ToString());
                    //string json_gas_consumed = json_response["gas_consumed"].ToString();

                    //lblZoroFee.Text = json_gas_consumed;


                    tx = ZoroHelper.MakeTransaction(sb.ToArray(), walletAccount.GetKey(), Fixed8.FromDecimal(decimal.Parse(lblZoroFee.Text)), Fixed8.FromDecimal(0.0001m));

                    string txid = tx.Hash.ToString();

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

                    var result = Program.Handler.Process("sendrawtransaction", _paramss);

                    string[] text = new string[] { "Result : " + result.ToString(), "Txid : " + txid };

                    tbxResult.Lines = text;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Published error:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }