Example #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);
        }
Example #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());
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
Example #6
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);
            }
        }
Example #7
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);
            }
        }
Example #8
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());
            }
        }
Example #9
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());
            }
        }
Example #10
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());
            }
        }
Example #11
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);
            }
        }