Пример #1
0
        public async Task <UInt160> CreateNativeNEP5Async(string ChainHash, string WIF)
        {
            string symbol = "InvokeContractTest";
            string name   = "InvokeContractTest_NativeNEP5";

            BigInteger presion     = new BigInteger(8);
            Decimal    totalsupply = 2_000_000_000;
            Decimal    amount      = totalsupply * new Decimal(Math.Pow(10, (long)presion));

            KeyPair keypair    = ZoroHelper.GetKeyPairFromWIF(WIF);
            UInt160 scriptHash = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);

            UInt160 hash = new UInt160();

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitPush(scriptHash);
                sb.EmitPush(keypair.PublicKey.EncodePoint(true));
                sb.EmitPush(presion);
                sb.EmitPush(new BigInteger(amount));
                sb.EmitPush(symbol);
                sb.EmitPush(name);
                sb.EmitSysCall("Zoro.NativeNEP5.Create");

                hash = sb.ToArray().ToScriptHash();
                Console.WriteLine("NativeNEP5 Hash:" + hash);

                string result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, ChainHash, Config.GasPrice);

                Console.WriteLine(result);
            }

            return(hash);
        }
Пример #2
0
        public async Task SendRawTransactionTestAsync(string contractHash, string WIF, UInt160 nativeBcp, int transType)
        {
            Console.WriteLine("Transfer Amount:");
            string  transferValue    = Console.ReadLine();
            Decimal value            = Decimal.Parse(transferValue, NumberStyles.Float) * new Decimal(Math.Pow(10, 8));
            string  chainHash        = Config.getValue("ChainHash");
            KeyPair keypair          = ZoroHelper.GetKeyPairFromWIF(WIF);
            UInt160 scriptHash       = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);
            UInt160 targetscripthash = UInt160.Parse(contractHash);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                if (transType == 1)
                {
                    sb.EmitAppCall(ZoroHelper.Parse(contractHash), "transfer", nativeBcp, scriptHash, targetscripthash, (BigInteger)value);
                }
                if (transType == 2)
                {
                    sb.EmitAppCall(ZoroHelper.Parse(contractHash), "transfer_app", nativeBcp, scriptHash, (BigInteger)value);
                }

                var result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, chainHash, Config.GasPrice);

                MyJson.JsonNode_Object resJO = (MyJson.JsonNode_Object)MyJson.Parse(result);
                Console.WriteLine(resJO.ToString());
            }
        }
Пример #3
0
        string GetBalanceFromJson(string info)
        {
            string result = "";

            MyJson.JsonNode_Object json = MyJson.Parse(info) as MyJson.JsonNode_Object;

            if (json.ContainsKey("result"))
            {
                MyJson.JsonNode_Object json_result = json["result"] as MyJson.JsonNode_Object;
                MyJson.JsonNode_Array  stack       = json_result["stack"] as MyJson.JsonNode_Array;

                if (stack != null && stack.Count >= 2)
                {
                    string balance  = ZoroHelper.GetJsonValue(stack[0] as MyJson.JsonNode_Object);
                    string decimals = ZoroHelper.GetJsonValue(stack[1] as MyJson.JsonNode_Object);

                    Decimal value = Decimal.Parse(balance) / new Decimal(Math.Pow(10, int.Parse(decimals)));
                    string  fmt   = "{0:N" + decimals + "}";
                    result = string.Format(fmt, value);
                }
            }
            else if (json.ContainsKey("error"))
            {
                MyJson.JsonNode_Object json_error_obj = json["error"] as MyJson.JsonNode_Object;
                result = json_error_obj.ToString();
            }

            return(result);
        }
Пример #4
0
        public async Task InvokeNativeNep5Async(string chainHash, string nativeNEP5Hash)
        {
            UInt160 nativeNEP5AssetId = ZoroHelper.Parse(nativeNEP5Hash);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Name", nativeNEP5AssetId);
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Symbol", nativeNEP5AssetId);
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "TotalSupply", nativeNEP5AssetId);
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", nativeNEP5AssetId);

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

                //Console.WriteLine(result);

                MyJson.JsonNode_Object json_result_array = MyJson.Parse(result) as MyJson.JsonNode_Object;
                MyJson.JsonNode_Object json_result_obj   = json_result_array["result"] as MyJson.JsonNode_Object;
                MyJson.JsonNode_Array  stack             = json_result_obj["stack"].AsList();

                if (stack.Count == 4)
                {
                    Console.WriteLine("name:" + Helper.GetJsonString(stack[0] as MyJson.JsonNode_Object));
                    Console.WriteLine("symbol:" + Helper.GetJsonString(stack[1] as MyJson.JsonNode_Object));
                    Console.WriteLine("totalSupply:" + Helper.GetJsonBigInteger(stack[2] as MyJson.JsonNode_Object));
                    Console.WriteLine("decimals:" + Helper.GetJsonInteger(stack[3] as MyJson.JsonNode_Object));
                }
            }
        }
Пример #5
0
        public async Task StartAsync()
        {
            string[] ChainHashList = Config.getStringArray("ChainHashList");
            string   ChainHash     = Config.getValue("ChainHash");
            string   WIF           = Config.getValue("WIF");
            string   contractHash  = Config.getValue("TestContract");
            UInt160  address       = ZoroHelper.GetPublicKeyHashFromWIF(WIF);
            var      nativeBcp     = UInt160.Parse(Config.getValue("NativeNEP5"));

            Console.WriteLine("Choose Transaction Type,0 - Contract Invoke NativeNEP5, 1 -  Contract Transfer NativeNEP5, 2 -  Contract Transfer_App NativeNEP5, 3 - TestContract Balance:");
            int transType = int.Parse(Console.ReadLine());

            if (transType == 0)
            {
                await ContractInvokeTestAsync(contractHash, address, nativeBcp);
            }
            if (transType == 1)
            {
                await SendRawTransactionTestAsync(contractHash, WIF, nativeBcp, transType);
            }
            if (transType == 2)
            {
                await SendRawTransactionTestAsync(contractHash, WIF, nativeBcp, transType);
            }
            if (transType == 3)
            {
                await BalanceOfNativeNEP5(nativeBcp, UInt160.Parse(contractHash), ChainHashList);
            }
        }
Пример #6
0
        public async Task ContractInvokeTestAsync(string contractHash, UInt160 address, UInt160 nativeBcp)
        {
            string[] ChainHashList = Config.getStringArray("ChainHashList");
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "balanceOf", nativeBcp, address);
                //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "symbol", nativeBcp);
                //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "decimals", nativeBcp);
                //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "totalSupply", nativeBcp);
                //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "test");
                //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "call");
                //sb.EmitAppCall(ZoroHelper.Parse(contractHash), "getheight");
                sb.EmitAppCall(ZoroHelper.Parse(contractHash), "getheader", 20);

                Console.WriteLine($"Contract: {contractHash}");

                foreach (var chainHash in ChainHashList)
                {
                    var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash);

                    string chainName = chainHash.Length > 0 ? chainHash : "Root";
                    Console.WriteLine($"{info}");
                }
            }
        }
        private Transaction MakeTestTransaction(Random rnd)
        {
            Fixed8.TryParse((rnd.Next(1, 10000) * 0.00001).ToString(), out Fixed8 price);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", Genesis.BcpContractAddress, scriptHash, targetscripthash, new BigInteger(1));

                InvocationTransaction tx = new InvocationTransaction
                {
                    Nonce    = Transaction.GetNonce(),
                    Script   = sb.ToArray(),
                    GasPrice = price,
                    GasLimit = Fixed8.FromDecimal(1000),
                    Account  = ZoroHelper.GetPublicKeyHash(keypair.PublicKey)
                };

                tx.Attributes = new TransactionAttribute[0];

                tx.Witnesses = new Witness[0];
                byte[] data     = ZoroHelper.GetHashData(tx);
                byte[] signdata = ZoroHelper.Sign(data, keypair.PrivateKey, keypair.PublicKey);
                ZoroHelper.AddWitness(tx, signdata, keypair.PublicKey);

                return(tx);
            }
        }
Пример #8
0
        public async Task InvokeNep5Async(string chainHash, string WIF, string ContractHash)
        {
            UInt160 scriptHash = ZoroHelper.Parse(ContractHash);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(scriptHash, "name");
                sb.EmitAppCall(scriptHash, "totalSupply");
                sb.EmitAppCall(scriptHash, "symbol");
                sb.EmitAppCall(scriptHash, "decimals");

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

                //Console.WriteLine(result);

                MyJson.JsonNode_Object json_result_array = MyJson.Parse(result) as MyJson.JsonNode_Object;
                MyJson.JsonNode_Object json_result_obj   = json_result_array["result"] as MyJson.JsonNode_Object;
                MyJson.JsonNode_Array  stack             = json_result_obj["stack"].AsList();

                if (stack.Count == 4)
                {
                    Console.WriteLine("name:" + Helper.GetJsonString(stack[0] as MyJson.JsonNode_Object));
                    Console.WriteLine("totalSupply:" + Helper.GetJsonBigInteger(stack[1] as MyJson.JsonNode_Object));
                    Console.WriteLine("symbol:" + Helper.GetJsonString(stack[2] as MyJson.JsonNode_Object));
                    Console.WriteLine("decimals:" + Helper.GetJsonInteger(stack[3] as MyJson.JsonNode_Object));
                }
            }
        }
Пример #9
0
        private void Test()
        {
            Console.Write("选择交易类型,0 - NEP5 SmartContract, 1 - NativeNEP5, 2 - BCP, 3 - InvokeNEP5:");
            var param1 = Console.ReadLine();
            Console.Write("输入并发的数量:");
            var param2 = Console.ReadLine();
            Console.Write("发送几次交易:");
            var param3 = Console.ReadLine();
            Console.Write("转账金额:");
            var param4 = Console.ReadLine();
            Console.Write("目标账户随机, 0 - no, 1 - yes:");
            var param5 = Console.ReadLine();
            Console.Write("GasPrice随机, 0 - no, 1 - yes:");
            var param6 = Console.ReadLine();

            transactionType = int.Parse(param1);
            transferCount = int.Parse(param3);
            concurrencyCount = int.Parse(param2);
            transferValue = param4;
            randomTargetAddress = int.Parse(param5) == 1;
            randomGasPrice = int.Parse(param6) == 1;

            string[] chainHashList = Config.getStringArray("ChainHashList");
            string WIF = Config.getValue("WIF");
            string targetWIF = Config.getValue("targetWIF");

            keypair = ZoroHelper.GetKeyPairFromWIF(WIF);
            scriptHash = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);
            targetAddress = ZoroHelper.GetPublicKeyHashFromWIF(targetWIF);

            string contractHash = Config.getValue("ContractHash");
            nep5ContractHash = UInt160.Parse(contractHash);

            string nativeNEP5Hash = Config.getValue("NativeNEP5");
            nativeNEP5AssetId = UInt160.Parse(nativeNEP5Hash);

            BCPAssetId = Genesis.BcpContractAddress;

            if (randomTargetAddress)
            {
                InitializeRandomTargetAddressList(transferCount);
            }

            if (transactionType == 0 || transactionType == 1 || transactionType == 2)
            {
                Console.WriteLine($"From:{WIF}");
                Console.WriteLine($"To:{targetWIF}");
                Console.WriteLine($"Count:{transferCount}");
                Console.WriteLine($"Value:{transferValue}");
            }

            cancelTokenSource = new CancellationTokenSource();

            Task.Run(() => RunTask(chainHashList));

            Console.WriteLine("输入回车键停止:");
            var input = Console.ReadLine();
            cancelTokenSource.Cancel();
        }
Пример #10
0
        public async Task StartAsync()
        {
            Console.WriteLine("AppChainName:");
            string name = Console.ReadLine();
            string WIF  = Config.getValue("WIF");

            Console.Write("validators Length: ");
            string vlength = Console.ReadLine();

            string[] validators = new string[int.Parse(vlength)];
            for (int i = 0; i < validators.Length; i++)
            {
                Console.Write("validator " + (i + 1) + ": ");
                validators[i] = Console.ReadLine();
            }
            Console.Write("seedList Length: ");
            string slength = Console.ReadLine();

            string[] seedList = new string[int.Parse(slength)];
            for (int i = 0; i < seedList.Length; i++)
            {
                Console.Write("seed " + (i + 1) + ": ");
                seedList[i] = Console.ReadLine();
            }
            Console.Write("IsPrivate: ");
            string isprivate = Console.ReadLine();

            KeyPair keypair = ZoroHelper.GetKeyPairFromWIF(WIF);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                foreach (string validator in validators)
                {
                    sb.EmitPush(validator);
                }
                sb.EmitPush(validators.Length);
                foreach (string seed in seedList)
                {
                    sb.EmitPush(seed);
                }
                sb.EmitPush(seedList.Length);
                sb.EmitPush(DateTime.UtcNow.ToTimestamp());
                sb.EmitPush(isprivate == "1" ? 1 : 0);
                sb.EmitPush(keypair.PublicKey.EncodePoint(true));
                sb.EmitPush(name);

                UInt160 chainHash = new UInt160(Crypto.Default.Hash160(sb.ToArray()));
                sb.EmitPush(chainHash.ToArray());
                sb.EmitSysCall("Zoro.AppChain.Create");

                Console.WriteLine("Appchain hash:" + chainHash.ToArray().Reverse().ToHexString());

                string result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, "", Config.GasPrice);

                Console.WriteLine(result);
            }
        }
        private void Test()
        {
            string WIF       = Config.getValue("WIF");
            string targetWIF = Config.getValue("targetWIF");

            keypair          = ZoroHelper.GetKeyPairFromWIF(WIF);
            scriptHash       = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);
            targetscripthash = ZoroHelper.GetPublicKeyHashFromWIF(targetWIF);

            string   path     = Config.getValue("LevelDB");
            Store    appStore = new LevelDBStore(path);
            Snapshot snapshot = appStore.GetSnapshot();

            Console.WriteLine("请输入数量:");
            var param = Console.ReadLine();

            int count = int.Parse(param);

            if (count <= 0)
            {
                return;
            }

            Random             rnd  = new Random();
            DateTime           dt   = DateTime.Now;
            List <Transaction> txns = new List <Transaction>();

            for (int i = 0; i < count; i++)
            {
                txns.Add(MakeTestTransaction(rnd));
            }

            Console.Write("maketxn, ");
            PrintTimeCost(dt);

            dt = DateTime.Now;
            foreach (var tx in txns)
            {
                tx.Verify(snapshot);
            }

            Console.Write("verify, ");
            PrintTimeCost(dt);

            dt = DateTime.Now;
            foreach (var tx in txns)
            {
                tx.Reverify(snapshot);
            }

            Console.Write("reverify, ");
            PrintTimeCost(dt);

            snapshot.Dispose();
            appStore.Dispose();
        }
Пример #12
0
        protected async Task NftBuyTest(string chainHash, UInt160 targetAddress, int buyCount)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(nftHash, "buy", targetAddress, (BigInteger)buyCount);
                //Console.WriteLine(buyCount);
                string result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, chainHash, Fixed8.FromDecimal(6000 * buyCount), Fixed8.FromDecimal(0.0001m));

                ParseResult(result);
            }
        }
Пример #13
0
        async Task <byte> GetNEP5Decimals(string contractHash, string chainHash)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(UInt160.Parse(contractHash), "decimals");

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

                return(ParseDecimals(info));
            }
        }
Пример #14
0
        protected async Task BCPTransfer(string chainHash, UInt160 targetAddress, Fixed8 gasPrice)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", BCPAssetId, scriptHash, targetAddress, BigInteger.Parse(transferValue));

                string result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, chainHash, Config.GasLimit["BCPTransfer"], gasPrice);

                ParseResult(result);
            }
        }
Пример #15
0
        async Task <byte> GetNativeNEP5Decimals(string assetId, string chainHash)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", UInt160.Parse(assetId));

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

                return(ParseDecimals(info));
            }
        }
Пример #16
0
        protected async Task NEP5Transfer(string chainHash, UInt160 targetAddress, Fixed8 gasPrice)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(nep5ContractHash, "transfer", scriptHash, targetAddress, BigInteger.Parse(transferValue));

                string result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, chainHash, Config.GasLimit["NEP5Transfer"], gasPrice);

                ParseResult(result);
            }
        }
Пример #17
0
        public async Task DeployNEP5Async(string ChainHash, string WIF, string ContractHash)
        {
            KeyPair keypair = ZoroHelper.GetKeyPairFromWIF(WIF);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(ZoroHelper.Parse(ContractHash), "deploy", "1");

                string result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, ChainHash, Config.GasPrice);

                Console.WriteLine(result);
            }
        }
        private void Test()
        {
            string WIF       = Config.getValue("WIF");
            string targetWIF = Config.getValue("targetWIF");

            keypair          = ZoroHelper.GetKeyPairFromWIF(WIF);
            scriptHash       = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);
            targetscripthash = ZoroHelper.GetPublicKeyHashFromWIF(targetWIF);

            Console.WriteLine("请输入数量:");
            var param = Console.ReadLine();

            int count = int.Parse(param);

            if (count <= 0)
            {
                return;
            }

            Random             rnd  = new Random();
            DateTime           dt   = DateTime.Now;
            List <Transaction> txns = new List <Transaction>();

            for (int i = 0; i < count; i++)
            {
                txns.Add(MakeTestTransaction(rnd));
            }

            Console.Write("maketxn, ");
            PrintTimeCost(dt);

            dt = DateTime.Now;

            IEnumerable <CompressedTransactionPayload> payloads = CompressedTransactionPayload.CreateGroup(txns.ToArray());

            Console.Write("compress, ");
            PrintTimeCost(dt);

            dt = DateTime.Now;

            foreach (var payload in payloads)
            {
                Transaction[] txn = CompressedTransactionPayload.DecompressTransactions(payload.CompressedData);
                foreach (var tx in txn)
                {
                }
            }

            Console.Write("decompress, ");
            PrintTimeCost(dt);
        }
Пример #19
0
        protected async Task InvokeNEP5Test(string chainHash)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(nep5ContractHash, "name");
                sb.EmitAppCall(nep5ContractHash, "totalSupply");
                sb.EmitAppCall(nep5ContractHash, "symbol");
                sb.EmitAppCall(nep5ContractHash, "decimals");

                string result = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash);

                ParseInvokeResult(result);
            }
        }
Пример #20
0
        public async Task StartAsync()
        {
            string WIF          = Config.getValue("WIF");
            string ContractHash = Config.getValue("ContractHash");

            string[] ChainHashList  = Config.getStringArray("ChainHashList");
            string   nativeNEP5Hash = Config.getValue("NativeNEP5");
            UInt160  address        = ZoroHelper.GetPublicKeyHashFromWIF(WIF);

            Console.WriteLine($"Account: {WIF}");
            await BalanceOfBCP(address, ChainHashList);
            await BalanceOfNEP5Contract(ContractHash, address, ChainHashList);
            await BalanceOfNativeNEP5(nativeNEP5Hash, address, ChainHashList);
        }
Пример #21
0
        public async Task TransferNativeNEP5Async(string chainHash, string WIF, string targetWIF, string assetId, BigInteger value)
        {
            KeyPair keypair          = ZoroHelper.GetKeyPairFromWIF(WIF);
            UInt160 scriptHash       = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);
            UInt160 targetscripthash = ZoroHelper.GetPublicKeyHashFromWIF(targetWIF);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", UInt160.Parse(assetId), scriptHash, targetscripthash, value);

                var result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, chainHash, Config.GasPrice);

                MyJson.JsonNode_Object resJO = (MyJson.JsonNode_Object)MyJson.Parse(result);
                Console.WriteLine(resJO.ToString());
            }
        }
Пример #22
0
        async Task BalanceOfNEP5Contract(string NEP5Contract, UInt160 address, string[] chainHashList)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitAppCall(ZoroHelper.Parse(NEP5Contract), "balanceOf", address);
                sb.EmitAppCall(ZoroHelper.Parse(NEP5Contract), "decimals");

                foreach (var chainHash in chainHashList)
                {
                    var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash);

                    var    value     = GetBalanceFromJson(info);
                    string chainName = chainHash.Length > 0 ? chainHash : "Root";
                    Console.WriteLine($"BalanceOf NEP5:{value}, chain:{chainName}");
                }
            }
        }
Пример #23
0
        async Task BalanceOfNativeNEP5(UInt160 nativeNEP5AssetId, UInt160 address, string[] chainHashList)
        {
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "BalanceOf", nativeNEP5AssetId, address);
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Decimals", nativeNEP5AssetId);

                Console.WriteLine($"NativeNEP5: {nativeNEP5AssetId}");
                foreach (var chainHash in chainHashList)
                {
                    var info = await ZoroHelper.InvokeScript(sb.ToArray(), chainHash);

                    var    value     = GetBalanceFromJson(info);
                    string chainName = chainHash.Length > 0 ? chainHash : "Root";
                    Console.WriteLine($"balanceOf: {value}, chain:{chainName}");
                }
            }
        }
Пример #24
0
        byte ParseDecimals(string info)
        {
            byte decimals = 0;

            MyJson.JsonNode_Object json = MyJson.Parse(info) as MyJson.JsonNode_Object;

            if (json.ContainsKey("result"))
            {
                MyJson.JsonNode_Object json_result = json["result"] as MyJson.JsonNode_Object;
                MyJson.JsonNode_Array  json_stack  = json_result["stack"] as MyJson.JsonNode_Array;

                if (json_stack != null && json_stack.Count >= 1)
                {
                    string value = ZoroHelper.GetJsonValue(json_stack[0] as MyJson.JsonNode_Object);
                    decimals = byte.Parse(value);
                }
            }
            return(decimals);
        }
Пример #25
0
        async Task SendTransaction(UInt160 assetId, string[] wif_list, string targetWIF, BigInteger value, string chainHash)
        {
            KeyPair[] keypairs = wif_list.Select(p => ZoroHelper.GetKeyPairFromWIF(p)).ToArray();
            int       m        = keypairs.Length - (keypairs.Length - 1) / 3;

            UInt160 scriptHash = ZoroHelper.GetMultiSigRedeemScriptHash(m, keypairs);

            UInt160 targetscripthash = ZoroHelper.GetPublicKeyHashFromWIF(targetWIF);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitSysCall("Zoro.NativeNEP5.Call", "Transfer", assetId, scriptHash, targetscripthash, value);

                var result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), m, keypairs, chainHash, Config.GasPrice);

                MyJson.JsonNode_Object resJO = (MyJson.JsonNode_Object)MyJson.Parse(result);
                Console.WriteLine(resJO.ToString());
            }
        }
Пример #26
0
        private void Test()
        {
            Console.Write("输入并发的数量:");
            var param2 = Console.ReadLine();

            Console.Write("发送几次交易:");
            var param3 = Console.ReadLine();

            Console.Write("目标账户随机, 0 - no, 1 - yes:");
            var param5 = Console.ReadLine();

            Console.Write("购买数量随机, 0 - no, 1 - yes:");
            var param6 = Console.ReadLine();

            transferCount       = int.Parse(param3);
            concurrencyCount    = int.Parse(param2);
            randomTargetAddress = int.Parse(param5) == 1;
            randomBuyCount      = int.Parse(param6) == 1;
            string[] chainHashList = Config.getStringArray("ChainHashList");
            string   WIF           = Config.getValue("WIF");
            string   targetWIF     = Config.getValue("targetWIF");

            keypair       = ZoroHelper.GetKeyPairFromWIF(WIF);
            scriptHash    = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);
            targetAddress = ZoroHelper.GetPublicKeyHashFromWIF(targetWIF);
            nftHash       = UInt160.Parse(Config.getValue("nftHash"));
            BCPAssetId    = Genesis.BcpContractAddress;

            if (randomTargetAddress)
            {
                InitializeRandomTargetAddressList(transferCount);
            }

            cancelTokenSource = new CancellationTokenSource();

            Task.Run(() => RunTask(chainHashList));

            Console.WriteLine("输入回车键停止:");
            var input = Console.ReadLine();

            cancelTokenSource.Cancel();
        }
Пример #27
0
        public async Task CreateContractAsync(string ChainHash, string WIF, string ContractPath)
        {
            KeyPair keypair = ZoroHelper.GetKeyPairFromWIF(WIF);

            byte[] script = System.IO.File.ReadAllBytes(ContractPath);
            Console.WriteLine("合约脚本Hash:" + script.ToScriptHash());
            byte[] parameter__list = ZoroHelper.HexString2Bytes("0710");
            byte[] return_type     = ZoroHelper.HexString2Bytes("05");
            int    need_storage    = 0;
            int    need_nep4       = 0;
            int    need_canCharge  = 4;
            string name            = "test contract";
            string version         = "1.0";
            string auther          = "zz";
            string email           = "0";
            string description     = "0";

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                var ss = need_storage | need_nep4 | need_canCharge;
                sb.EmitPush(description);
                sb.EmitPush(email);
                sb.EmitPush(auther);
                sb.EmitPush(version);
                sb.EmitPush(name);
                sb.EmitPush(ss);
                sb.EmitPush(return_type);
                sb.EmitPush(parameter__list);
                sb.EmitPush(script);
                sb.EmitSysCall("Zoro.Contract.Create");

                Console.WriteLine($"ScriptHash:{script.ToScriptHash()}");

                var result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, ChainHash, Config.GasPrice);

                MyJson.JsonNode_Object resJO = (MyJson.JsonNode_Object)MyJson.Parse(result);
                Console.WriteLine(resJO.ToString());
            }
        }
Пример #28
0
        public async Task StartAsync()
        {
            Console.WriteLine("AppChainHash:");
            string appchainHash = Console.ReadLine();

            var url    = Helper.MakeRpcUrl(Program.local, "getappchainstate", new MyJson.JsonNode_ValueString(appchainHash));
            var result = await Helper.HttpGet(url);

            MyJson.JsonNode_Object json_result_array = MyJson.Parse(result) as MyJson.JsonNode_Object;
            MyJson.JsonNode_Object json_result_obj;

            bool exists = true;

            if (json_result_array.TryGetValue("result", out MyJson.IJsonNode json_result))
            {
                json_result_obj = json_result as MyJson.JsonNode_Object;

                string appchainName = json_result_obj["name"].AsString();

                if (appchainName == "null")
                {
                    exists = false;
                }
            }
            else
            {
                exists = false;
            }

            if (!exists)
            {
                Console.WriteLine("Can't find appchain " + appchainHash);
                return;
            }

            string WIF = Config.getValue("WIF");

            Console.Write("validators Length: ");
            string vlength = Console.ReadLine();

            string[] validators = new string[int.Parse(vlength)];
            for (int i = 0; i < validators.Length; i++)
            {
                Console.Write("validator " + (i + 1) + ": ");
                validators[i] = Console.ReadLine();
            }

            KeyPair keypair = ZoroHelper.GetKeyPairFromWIF(WIF);

            using (ScriptBuilder sb = new ScriptBuilder())
            {
                foreach (string validator in validators)
                {
                    sb.EmitPush(validator);
                }
                sb.EmitPush(validators.Length);
                sb.EmitSysCall("Zoro.AppChain.ChangeValidators");

                result = await ZoroHelper.SendInvocationTransaction(sb.ToArray(), keypair, appchainHash, Config.GasPrice);

                Console.WriteLine(result);
            }
        }