예제 #1
0
        public void OnProperty(HttpMessage httpMessage)
        {
            if (!GetParam(httpMessage, "1", "address", out string address))
            {
                httpMessage.result = "command error! \nexample: account address";
                return;
            }

            using (DbSnapshot dbSnapshot = Entity.Root.GetComponent <LevelDBStore>().GetSnapshot(0))
            {
                var map = new Dictionary <string, string>();

                Account account = dbSnapshot.Accounts.Get(address);
                map.Add("1", "SAT:" + (account != null ? account.amount : "0") + ":");

                var abc      = dbSnapshot.ABC.Get(address);
                var blockSub = new BlockSub();
                var index    = 2;
                if (abc != null)
                {
                    var      consensus = Entity.Root.GetComponent <Consensus>();
                    var      luaVMEnv  = Entity.Root.GetComponent <LuaVMEnv>();
                    var      amount    = "";
                    var      symbol    = "";
                    object[] result    = null;
                    bool     rel;
                    for (int ii = 0; ii < abc.Count; ii++)
                    {
                        blockSub.addressIn  = address;
                        blockSub.addressOut = abc[ii];
                        try
                        {
                            if (!luaVMEnv.IsERC(dbSnapshot, blockSub.addressOut, "ERC20"))
                            {
                                continue;
                            }
                            symbol = LuaContract.GetSymbol(blockSub.addressOut);

                            blockSub.data = $"balanceOf(\"{address}\")";
                            rel           = luaVMEnv.Execute(dbSnapshot, blockSub, consensus.transferHeight, out result);
                            if (rel && result != null && result.Length == 1)
                            {
                                amount = ((string)result[0]) ?? "0";
                                map.Add(index++.ToString(), $"{symbol}:{amount}:{blockSub.addressOut}");
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                httpMessage.result = JsonHelper.ToJson(map);
            }
        }
예제 #2
0
        private void OnBlocktranHash(HttpMessage httpMessage)
        {
            if (!GetParam(httpMessage, "1", "hash", out string hash))
            {
                httpMessage.result = "please input hash";
                return;
            }
            using (var dbSnapshot = Entity.Root.GetComponent <LevelDBStore>().GetSnapshot(0))
            {
                var transfer = dbSnapshot.Transfers.Get(hash);
                if (transfer != null)
                {
                    Block myblk = BlockChainHelper.GetMcBlock(transfer.height);
                    if (transfer.addressIn == "" && transfer.addressOut == "" || transfer.addressIn == null && transfer.addressOut == null)
                    {
                        transfer.addressIn  = "00000000000000000000000000000000";
                        transfer.addressOut = "00000000000000000000000000000000";
                    }

                    if (transfer.type == "contract")
                    {
                        string[] arr = transfer.data.Replace("\"", "").Replace("\\", "").Replace("transfer(", "").Replace(")", "").Split(",");
                        transfer.amount = arr[arr.Length - 1];
                        if (transfer.data.Contains("transfer("))
                        {
                            var symbol = LuaContract.GetSymbol(transfer.addressOut);
                            transfer.temp = new List <string>();
                            transfer.temp.Add(symbol);
                        }
                    }
                }

                if (transfer == null)
                {
                    httpMessage.result = "false";
                }
                else
                {
                    httpMessage.result = JsonHelper.ToJson(transfer);
                }
            }
        }