示例#1
0
        public static UserCredentials GetUserCredentials(byte[] encodedUsername)
        {
            UserCredentials uc = null;

            var api = NeoRPC.ForTestNet();
            //Console.WriteLine("guc.encodedUsername: '******'");
            var response2 = api.TestInvokeScript(NeoDraw_ContractHash, new object[] { "get", "user", new object[] { encodedUsername } });

            object[]   resultsArray2    = (object[])response2.result;
            byte[]     bencodedUsername = (byte[])(((object[])((object[])resultsArray2[0])[0])[0]);
            byte[]     bencodedPassword = (byte[])(((object[])((object[])resultsArray2[0])[0])[1]);
            BigInteger status           = (BigInteger)(((object[])((object[])resultsArray2[0])[0])[2]);
            //string sencodedUsername = Encoding.ASCII.GetString(bencodedUsername).Replace("\0", "");
            //string sencodedPassword = Encoding.ASCII.GetString(bencodedPassword).Replace("\0", "");
            string sencodedUsername = bencodedUsername.ToHexString();
            string sencodedPassword = bencodedPassword.ToHexString();

            //Console.WriteLine("guc.sencodedUsername,sencodedPassword: '******' '" + sencodedPassword + "'");
            //Console.WriteLine("guc.sencodedUsername,sencodedPassword: "******" " + sencodedPassword.Length + "");
            //Console.WriteLine("guc.status: " + status.ToString());

            if (status != 5 && sencodedUsername.Length > 0 && sencodedPassword.Length > 0)
            {
                uc = new UserCredentials {
                    encodedUsername = bencodedUsername, encodedPassword = bencodedPassword
                };
            }

            return(uc);
        }
        public static bool CallContract(string method, object[] values)
        {
            try
            {
                var key        = new KeyPair(privateKey.HexToBytes());
                var scriptHash = new UInt160(contractScriptHash.HexToBytes());

                var api      = NeoRPC.ForTestNet();
                var response = api.CallContract(key, scriptHash, method, values);
                if (response != null)
                {
                    return(true);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Null response received on CallContract");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(false);
            }
        }
示例#3
0
        public static UserPoint[] GetAllPoints(byte[] encodedUsername)
        {
            List <UserPoint> points = new List <UserPoint>();

            var api      = NeoRPC.ForTestNet();
            var response = api.TestInvokeScript(NeoDraw_ContractHash, new object[] { "getall", "point", new object[] { encodedUsername } });

            object[] resultsArray = (object[])response.result;
            if (resultsArray != null)
            {
                //Console.WriteLine("resultsArray.length: " + resultsArray.Length);
                for (int element = 0; element < resultsArray.Length; element++)
                {
                    byte[] bx = (byte[])(((object[])((object[])resultsArray[element])[0])[0]);
                    byte[] by = (byte[])(((object[])((object[])resultsArray[element])[0])[1]);
                    string sx = Encoding.ASCII.GetString(bx);
                    string sy = Encoding.ASCII.GetString(by);
                    //Console.WriteLine("sx,sy: " + sx + " " + sy);
                    int ix = Int32.Parse(sx);
                    int iy = Int32.Parse(sy);
                    //Console.WriteLine("ix,iy: " + ix.ToString() + " " + iy.ToString());

                    points.Add(new UserPoint {
                        x = ix, y = iy
                    });
                }
            }

            return(points.ToArray <UserPoint>());
        }
示例#4
0
        public static NeoAPI GetLuxApi()
        {
            NeoRPC resultInstance = BaseRpcInstance();

            resultInstance.rpcEndpoint = NextNode();
            resultInstance.UseRetries  = false;
            return(resultInstance);
        }
示例#5
0
    void Start()
    {
        this.api = NeoRPC.ForTestNet();

        this.keys = new KeyPair("a9e2b5436cab6ff74be2d5c91b8a67053494ab5b454ac2851f872fb0fd30ba5e".HexToBytes());

        this.addressLabel.text = keys.address;
        this.balanceLabel.text = "Please wait, syncing balance...";
    }
示例#6
0
 /// <summary>
 /// Facilitates the invoking of the Treatail Smart Contract
 /// </summary>
 /// <param name="networkType">Network to use</param>
 /// <param name="contextWallet">Wallet to use for signing context</param>
 public Contract(NetworkType networkType, string privateKeyHex)
 {
     _api   = NetworkHelper.GetNeoRPCForType(networkType);
     _token = new NEP5(_api, _contractScriptHash);
     if (privateKeyHex != null)
     {
         _contextWallet = WalletHelper.GetWallet(privateKeyHex);
     }
 }
示例#7
0
        public static bool AddUser(byte[] encodedUsername, byte[] encodedPassword)
        {
            var  api = NeoRPC.ForTestNet();
            var  TestNetAccount_KeyPair = new KeyPair(TestNetAccount_PrivateKey.HexToBytes());
            bool response5 = api.CallContract(TestNetAccount_KeyPair, NeoDraw_ContractHash, new object[] { "add", "user", new object[] { encodedPassword, encodedUsername } });

            //Console.WriteLine("response5: " + ((bool)response5).ToString());
            return((bool)response5);
        }
示例#8
0
        public static bool AddPoint(byte[] encodedUsername, UserPoint up)
        {
            //Console.WriteLine("AddPoint:Adding point ( " + up.x.ToString() + ", " + up.y.ToString() + ") for " + encodedUsername.ToHexString());
            var  api = NeoRPC.ForTestNet();
            var  TestNetAccount_KeyPair = new KeyPair(TestNetAccount_PrivateKey.HexToBytes());
            bool response5 = api.CallContract(TestNetAccount_KeyPair, NeoDraw_ContractHash, new object[] { "add", "point", new object[] { up.y, up.x, encodedUsername } });

            //Console.WriteLine("response5: " + ((bool)response5).ToString());
            return((bool)response5);
        }
示例#9
0
        static void Main(string[] args)
        {
            // NOTE - You can also create an API instance for a specific private net
            var api = NeoRPC.ForTestNet();

            // NOTE - Private keys should not be hardcoded in the code, this is just for demonstration purposes!
            var privateKey = "a9e2b5436cab6ff74be2d5c91b8a67053494ab5b454ac2851f872fb0fd30ba5e";

            Console.WriteLine("*Loading NEO address...");
            var keys = new KeyPair(privateKey.HexToBytes());

            Console.WriteLine("Got :" + keys.address);

            // it is possible to optionally obtain also token balances with this method
            Console.WriteLine("*Syncing balances...");
            var balances = api.GetBalancesOf(keys.address, false);

            foreach (var entry in balances)
            {
                Console.WriteLine(entry.Value + " " + entry.Key);
            }

            // TestInvokeScript let's us call a smart contract method and get back a result
            // NEP5 https://github.com/neo-project/proposals/issues/3

            api = NeoRPC.ForMainNet();
            var redPulse = api.GetToken("RPX");

            // you could also create a NEP5 from a contract script hash
            //var redPulse_contractHash = "ecc6b20d3ccac1ee9ef109af5a7cdb85706b1df9";
            //var redPulse = new NEP5(api, redPulse_contractHash);

            Console.WriteLine("*Querying Symbol from RedPulse contract...");
            //var response = api.TestInvokeScript(redPulse_contractHash, "symbol", new object[] { "" });
            //var symbol = System.Text.Encoding.ASCII.GetString((byte[])response.result);
            var symbol = redPulse.Symbol;

            Console.WriteLine(symbol); // should print "RPX"

            // here we get the RedPulse token balance from an address
            Console.WriteLine("*Querying BalanceOf from RedPulse contract...");
            //var balance = api.GetTokenBalance("AVQ6jAQ3Prd32BXU5r2Vb3QL1gYzTpFhaf", "RPX");
            var balance = redPulse.BalanceOf("AVQ6jAQ3Prd32BXU5r2Vb3QL1gYzTpFhaf");

            Console.WriteLine(balance);

            Console.WriteLine("Press any key to quit...");
            Console.ReadKey();
        }
示例#10
0
        /// <summary>
        /// Gets the Neo RPC for the specified network type.  Defaults to Testnet
        /// </summary>
        /// <param name="type">NetworkType - network to use</param>
        /// <returns>NeoRPC - the RPC for the requested network</returns>
        public static NeoRPC GetNeoRPCForType(NetworkType type)
        {
            switch (type)
            {
            case NetworkType.Mainnet:
                return(NeoRPC.ForMainNet());

            case NetworkType.Testnet:
                return(NeoRPC.ForTestNet());

            case NetworkType.CozTestnet:
                throw new Exception("COZ Testnet not implemented yet");

            case NetworkType.Privnet:
                return(NeoRPC.ForPrivateNet());
            }

            return(NeoRPC.ForTestNet());
        }
示例#11
0
        private static NeoRPC BaseRpcInstance()
        {
            if (Configuration["Neo:Network"] == "Main")
            {
                return(NeoRPC.ForMainNet());
            }

            if (Configuration["Neo:Network"] == "Test")
            {
                return(NeoRPC.ForTestNet());
            }

            if (Configuration["Neo:Network"] == "AllCode")
            {
                return(new NeoFluxNeoRPC(Configuration["Neo:DefaultScanUrl"]));
            }

            return(null);
        }
示例#12
0
        static void Main(string[] args)
        {
            string address;

            do
            {
                Console.WriteLine("Write an NEO address to listen:");
                address = Console.ReadLine();
            } while (!address.IsValidAddress());

            var api = NeoRPC.ForTestNet();

            var oldBlockCount = api.GetBlockHeight();

            var targetScriptHash = new UInt160(address.AddressToScriptHash());

            Console.WriteLine("Now listening for transactions...");

            do
            {
                // wait for block generation
                Thread.Sleep(10000);

                var newBlockCount = api.GetBlockHeight();

                if (newBlockCount != oldBlockCount)
                {
                    Console.WriteLine($"Fetching block {newBlockCount}");

                    // retrieve latest block
                    var block = api.GetBlock(newBlockCount);

                    if (block == null)
                    {
                        Console.WriteLine($"Failed...");
                        continue;
                    }

                    oldBlockCount = newBlockCount;

                    // inspect each tx in the block for inputs sent to the target address
                    foreach (var tx in block.transactions)
                    {
                        var amounts = new Dictionary <string, decimal>();

                        foreach (var output in tx.outputs)
                        {
                            if (output.scriptHash.Equals(targetScriptHash))
                            {
                                var asset = NeoAPI.SymbolFromAssetID(output.assetID);

                                if (amounts.ContainsKey(asset))
                                {
                                    amounts[asset] += output.value;
                                }
                                else
                                {
                                    amounts[asset] = output.value;
                                }
                            }
                        }

                        if (amounts.Count > 0)
                        {
                            foreach (var entry in amounts)
                            {
                                Console.WriteLine($"{entry.Value} {entry.Key} was sent to {address}, in tx {tx.Hash}");
                            }
                        }
                    }
                }
            } while (true);
        }
示例#13
0
 public LuxApiExtensions(NeoRPC neoRpc)
 {
     RPC = neoRpc;
 }
示例#14
0
        static void Main(string[] args)
        {
            var api = NeoRPC.ForPrivateNet();

            api.SetLogger(LocalLogger);

            var demoKeys = new KeyPair(demoPrivateKeyHex.HexToBytes());

            Console.WriteLine($"demoPrivateKeyHex.keys:\t{JsonConvert.SerializeObject(demoKeys)}");
            var balances = api.GetAssetBalancesOf(demoKeys.address);

            foreach (var entry in balances)
            {
                Console.WriteLine(entry.Key + "\t" + entry.Value);
            }

            var my0Keys = new KeyPair(my0PrivateKeyHex.HexToBytes());

            Console.WriteLine($"my0PrivateKeyHex.keys:\t{JsonConvert.SerializeObject(my0Keys)}");
            var my1Keys = new KeyPair(my1PrivateKeyHex.HexToBytes());

            Console.WriteLine($"my1PrivateKeyHex.keys:\t{JsonConvert.SerializeObject(my1Keys)}");

            Console.WriteLine();
            Console.WriteLine("Balances:");
            balances = api.GetAssetBalancesOf(my0Keys.address);
            foreach (var entry in balances)
            {
                Console.WriteLine(entry.Key + "\t" + entry.Value);
            }
            balances = api.GetAssetBalancesOf(my1Keys.address);
            foreach (var entry in balances)
            {
                Console.WriteLine(entry.Key + "\t" + entry.Value);
            }

            Console.WriteLine();
            Console.WriteLine("Unspent Balances:");
            var unspentBalances = api.GetUnspent(my0Keys.address);

            foreach (var entry in unspentBalances)
            {
                Console.WriteLine(entry.Key + "\t" + JsonConvert.SerializeObject(entry.Value));
            }
            unspentBalances = api.GetUnspent(my1Keys.address);
            foreach (var entry in unspentBalances)
            {
                Console.WriteLine(entry.Key + "\t" + JsonConvert.SerializeObject(entry.Value));
            }

            Console.WriteLine();
            Console.WriteLine("GetClaimable Balances:");
            decimal amount       = 0;
            var     claimableGas = api.GetClaimable(my0Keys.PublicKeyHash, out amount);

            Console.WriteLine($"GetClaimable:\t{amount}");
            foreach (var entry in claimableGas)
            {
                Console.WriteLine(JsonConvert.SerializeObject(entry));
            }
            claimableGas = api.GetClaimable(my1Keys.PublicKeyHash, out amount);
            Console.WriteLine($"GetClaimable:\t{amount}");
            foreach (var entry in claimableGas)
            {
                Console.WriteLine(JsonConvert.SerializeObject(entry));
            }

            Console.WriteLine();
            Console.WriteLine("AVM:");
            byte[] avmBytes = File.ReadAllBytes(avmFilename);
            Console.WriteLine($"Bytes:\t{avmFilename}\t{avmBytes.Length} bytes");
            Console.WriteLine($"Bytes:\t{avmFilename}\t'{avmBytes.ToHexString()}'");

            Console.WriteLine();
            Console.WriteLine("AVM Script Hash:");
            UInt160 avmScriptHash       = avmBytes.ToScriptHash();
            string  avmScriptHashString = avmBytes.ToScriptHash().ToString();
            string  avmAddress          = avmScriptHash.ToAddress();

            byte[] avmScriptHashBytes    = avmScriptHash.ToArray();
            string avmScriptHashBytesHex = avmScriptHashBytes.ToHexString();

            Console.WriteLine($"avmScriptHash:\t{JsonConvert.SerializeObject(avmScriptHash)}");
            Console.WriteLine($"avmScriptHashString:\t{avmScriptHashString}");
            Console.WriteLine($"avmAddress:\t{avmAddress}");
            Console.WriteLine($"avmScriptHashBytes:\t{JsonConvert.SerializeObject(avmScriptHashBytes)}");
            Console.WriteLine($"avmScriptHashBytesHex:\t{avmScriptHashBytesHex}");

            Console.WriteLine();
            Console.WriteLine("Press EXIT to exit...");
            Console.ReadLine();

            //byte[] parameterTypes = { (byte)ContractParameterType.String, (byte)ContractParameterType.Array };
            //byte returnType = (byte)ContractParameterType.Void;
            //ContractPropertyState properties = ContractPropertyState.NoProperty;
            //Transaction tDeploy = api.DeployContract(my0Keys, avmBytes, parameterTypes, returnType, properties, "Demo AVM", "1.0.0", "Able Baker", "*****@*****.**", "Demonstration AVM");
            //Console.WriteLine($"tDeploy:\t{JsonConvert.SerializeObject(tDeploy)}");
            //File.WriteAllText("tDeploy.json", JsonConvert.SerializeObject(tDeploy));

            //object[] testargs = { "a", "b", "c" };
            //InvokeResult response = api.InvokeScript(avmScriptHash, "testoperation", testargs);
            //Console.WriteLine($"response:\t{JsonConvert.SerializeObject(response)}");
            //Console.WriteLine($"state:\t{response.state}");
            //Console.WriteLine($"stack:\t{JsonConvert.SerializeObject(response.stack)}");
            //Console.WriteLine($"stack[0]:\t{response.stack[0]}");
            ////object obj = response.stack[1];
            ////byte[] stack1Bytes = (byte[])obj;
            ////string stack1String1 = stack1Bytes.ToHexString();
            ////Console.WriteLine($"stack1String1:\t{stack1String1}");
            ////string stack1String2 = stack1Bytes.ByteToHex();
            ////Console.WriteLine($"stack1String2:\t{stack1String2}");

            string testoperation = "testoperation2";

            Console.WriteLine($"{testoperation}\t{ToHex(testoperation)}");
            object[] testargs = new object[] { "a", "b", "c", "d" };
            Console.WriteLine($"{testargs[0]}\t{ToHex((string)testargs[0])}");
            Console.WriteLine($"{testargs[1]}\t{ToHex((string)testargs[1])}");
            Console.WriteLine($"{testargs[2]}\t{ToHex((string)testargs[2])}");
            Console.WriteLine($"{testargs[3]}\t{ToHex((string)testargs[3])}");
            Transaction tResult = api.CallContract(my0Keys, avmScriptHash, testoperation, testargs);

            Console.WriteLine($"tResult:\t{JsonConvert.SerializeObject(tResult)}");
            File.WriteAllText("tResult.json", JsonConvert.SerializeObject(tResult));

            Console.WriteLine();
            Console.WriteLine("Press EXIT to exit...");
            Console.ReadLine();
        }
示例#15
0
        static void Main(string[] args)
        {
            const string demoPrivateKeyHex = "a9e2b5436cab6ff74be2d5c91b8a67053494ab5b454ac2851f872fb0fd30ba5e";

            const string my0Address       = "ALa8ALaySEH4x3Tnar7s1mWroXLnfBpz7c";
            const string my0PublicKey     = "0218c0e56e77a7fdf848da36676e6f296be4d4f17a267d86fd21b81dd31eb8595a";
            const string my0PrivateKeyHex = "a626b73b3eb8e4779c48565bb8831585215a32d086f8cdf79445ef193cfe9cb6";
            const string my0PrivateKeyWIF = "L2ngotEv1KPmTEkMJmxLbQAUp4VfAC2SvXTX1ZQ8juZyqWPkh3BA";

            string deployScriptHashHex = "0xf036ad1b59f21c09e3247fd5acb3bc73669547d2";
            string deployTxHashHex     = "0x67caaed7e4ebdc8dfe1314ad2d31913d0041037efbba5edd129bfc41ec58dadc";
            string invokeTxHashHex     = "0xb32b58c2b662022f237b651a0baf483fb67e479ebf4d23b42f40ba3099b86526";

            //const string my0Address = "AN3LHQcpvwAfJAHk6DvzHyFxHr4KcY5mdA";
            //const string my0PrivateKeyHex = "13c5ae3e47d1e1421c2adb620ee134457590e9ba19f5f891d19c183b0d06d521";
            //const string my0PrivateKeyWIF = "Kwt9PVkXBPA1ZPtTAArBhmtQy2AkcYhs9MZU4YuLdW56Uoy3ddWN";
            //const string my0PublicKey = "02bc19691ee7253b1b48efc189c89d02b8e231ef5d39f45a8eda2d6536853dcded";
            //string deployScriptHashHex = "0xf036ad1b59f21c09e3247fd5acb3bc73669547d2";
            //string deployTxHashHex = "0x416a12bc0eac0b126e258a198702d5637dbe0d7401c62f17fa01f766dbf3f9f8";
            //string invokeTxHashHex = "0x13db6f23f2fc9d582f5a8e03bec0cb9c65c0828372547ba4263aa15906e46c29";

            const string my1Address       = "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y";
            const string my1PrivateKeyHex = "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb";
            const string my1PrivateKeyWIF = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr";
            const string my1PublicKey     = "031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4a";
            // 0xb7743f023b2cbb367f21b26d8da837929f1309f3
            const string avmFilename = @"D:\repos\neo-lux\NEO.mwherman2000.DeployTestSC1\bin\Debug\NEO.mwherman2000.DeployTestSC1.avm";

            _api          = NeoRPC.ForPrivateNet();
            _currentBlock = _api.GetBlockHeight();
            Console.WriteLine($"currentBlock: {_currentBlock}");
            _deployTxBlock = 31163;

            Console.WriteLine($"deployScriptHash: {deployScriptHashHex}");
            Console.WriteLine($"deployTxHash: {deployTxHashHex}");
            _deployTx = _api.GetTransaction(deployTxHashHex.Replace("0x", ""));
            Console.WriteLine($"deployTx: {JsonConvert.SerializeObject(_deployTx)}");
            byte[] deployTxScript       = _deployTx.script;
            int    deployTxScriptLength = deployTxScript.Length;

            Console.WriteLine($"deployTxScriptLength: {deployTxScriptLength}");

            UInt160 deployTxScriptHash = deployTxScript.ToScriptHash();
            string  deployTxSciptToScriptHashString = deployTxScriptHash.ToString();

            Console.WriteLine($"deployTxSciptToScriptHashString: {deployTxSciptToScriptHashString}");

            {
                Console.WriteLine($"invokeTxHashHex: {invokeTxHashHex}");
                Transaction invokeTx = _api.GetTransaction(invokeTxHashHex.Replace("0x", ""));
                Console.WriteLine($"invokeTx: {JsonConvert.SerializeObject(invokeTx)}");
                byte[] invokeTxScript       = invokeTx.script;
                int    invokeTxScriptLength = invokeTxScript.Length;
                Console.WriteLine($"invokeTxScriptLength: {invokeTxScriptLength}");

                UInt160 invokeTxScriptHash = invokeTxScript.ToScriptHash();
                string  invokeTxSciptToScriptHashString = invokeTxScriptHash.ToString();
                Console.WriteLine($"invokeTxSciptToScriptHashString: {invokeTxSciptToScriptHashString}");
            }

            Console.WriteLine("Monitoring: press Enter to start monitoring...");
            Console.ReadLine();

            //var monitor = new NeoEventMonitor1(_api, deployTx, deployTxBlock-5);
            //monitor.Run();
            //Console.WriteLine("Monitoring: press Enter to stop monitoring...");
            //Console.ReadLine();
            //monitor.Stop();

            //Task<bool> monitor = NeoEventMonitor();
            //Console.WriteLine("Monitoring started...");

            var my0Keys = new KeyPair(my0PrivateKeyHex.HexToBytes());

            Console.WriteLine($"my0PrivateKeyHex.keys:\t{JsonConvert.SerializeObject(my0Keys)}");
            var my1Keys = new KeyPair(my1PrivateKeyHex.HexToBytes());

            Console.WriteLine($"my1PrivateKeyHex.keys:\t{JsonConvert.SerializeObject(my1Keys)}");

            Console.WriteLine();
            Console.WriteLine("Balances:");
            var balances = _api.GetAssetBalancesOf(my0Keys.address);

            foreach (var entry in balances)
            {
                Console.WriteLine(entry.Key + "\t" + entry.Value);
            }
            balances = _api.GetAssetBalancesOf(my1Keys.address);
            foreach (var entry in balances)
            {
                Console.WriteLine(entry.Key + "\t" + entry.Value);
            }

            //Console.WriteLine();
            //Console.WriteLine("Unspent Balances:");
            //var unspentBalances = _api.GetUnspent(my0Keys.address);
            //foreach (var entry in unspentBalances)
            //{
            //    Console.WriteLine(entry.Key + "\t" + JsonConvert.SerializeObject(entry.Value));
            //}
            //unspentBalances = _api.GetUnspent(my1Keys.address);
            //foreach (var entry in unspentBalances)
            //{
            //    Console.WriteLine(entry.Key + "\t" + JsonConvert.SerializeObject(entry.Value));
            //}

            //Console.WriteLine();
            //Console.WriteLine("GetClaimable Balances:");
            //decimal amount = 0;
            //var claimableGas = _api.GetClaimable(my0Keys.PublicKeyHash, out amount);
            //Console.WriteLine($"GetClaimable:\t{amount}");
            //foreach (var entry in claimableGas)
            //{
            //    Console.WriteLine(JsonConvert.SerializeObject(entry));
            //}
            //claimableGas = _api.GetClaimable(my1Keys.PublicKeyHash, out amount);
            //Console.WriteLine($"GetClaimable:\t{amount}");
            //foreach (var entry in claimableGas)
            //{
            //    Console.WriteLine(JsonConvert.SerializeObject(entry));
            //}

            for (int time = 0; time < 10; time++)
            {
                var oldLogger = _api.Logger;
                _api.SetLogger(LocalLogger);
                Console.WriteLine($"#### START {time} calltx");
                string      operation = "testcallcontract";
                object[]    callargs  = { 1024 + time, 1024 + time + 1, 1024 + time + 2 };
                Transaction calltx    = _api.CallContract(my0Keys, UInt160.Parse(deployScriptHashHex), operation, callargs);
                Console.WriteLine($"#### END   {time} calltx\t{JsonConvert.SerializeObject(calltx)}");
                _api.SetLogger(oldLogger);
                if (calltx != null)
                {
                    //var oldLogger2 = _api.Logger;
                    //_api.SetLogger(LocalLogger);
                    DateTime dtStart = DateTime.Now;
                    Console.WriteLine($"#### Waiting {time} calltx {dtStart.ToString()}");
                    _api.WaitForTransaction(my0Keys, calltx);
                    DateTime dtEnd = DateTime.Now;
                    Console.WriteLine($"#### Completed {time} calltx {dtEnd.ToString()}");
                    TimeSpan elapsed = (dtEnd.Subtract(dtStart));
                    Console.WriteLine($"#### Completed {time} calltx {elapsed.TotalSeconds}");
                    //_api.SetLogger(oldLogger2);
                }
                else
                {
                    uint blockheight = _api.GetBlockHeight();
                    Console.WriteLine($"blockheight: {blockheight}");
                    while (_api.GetBlock(blockheight) == null)
                    {
                        Console.WriteLine("...waiting..."); Thread.Sleep(10000);
                    }
                    Thread.Sleep(10000);
                    Console.WriteLine($"blockheight: {blockheight} found");
                }
            }

            Console.WriteLine("Waiting for task...");
            //monitor.Wait();

            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }
示例#16
0
 /// <summary>
 /// Facilitates the invoking of the IToldUSo Smart Contract
 /// </summary>
 /// <param name="networkType">Network to use</param>
 public ContractWrapper(NetworkType networkType)
 {
     _api = NetworkHelper.GetNeoRPCForType(networkType);
 }
示例#17
0
 public void Init()
 {
     api   = NeoRPC.ForTestNet();
     token = api.GetToken("RPX");
 }
示例#18
0
        static void Main(string[] args)
        {
            if (args.Length < 5)
            {
                Console.WriteLine("neo-sender <Net> <PrivateKey> <DestAddress> <Symbol> <Amount>");
                Console.WriteLine("Net          Can be Main, Test or custom URL");
                Console.WriteLine("PrivateKey   Can be a full hex private key or a WIF private key");
                Console.WriteLine("DestAddress  Must be a valid Neo address");
                Console.WriteLine("Symbol       Must be Neo, Gas or any support token (eg: RPX, DBC)");
                return;
            }

            var keyStr        = args[1];
            var outputAddress = args[2];

            var symbol = args[3];   //"GAS"
            var amount = decimal.Parse(args[4]);

            var fromKey = keyStr.Length == 52 ? KeyPair.FromWIF(keyStr) : new KeyPair(keyStr.HexToBytes());

            Console.WriteLine($"Sending {amount} {symbol} from {fromKey.address} to {outputAddress}");

            var    net = args[0].ToLowerInvariant();
            NeoAPI api;

            switch (net)
            {
            case "main": api = NeoRPC.ForMainNet(); break;

            case "test": api = NeoRPC.ForTestNet(); break;

            default: api = new NeoRPC(net); break;
            }

            bool result = false;

            try
            {
                if (api.IsToken(symbol))
                {
                    var token = api.GetToken(symbol);
                    result = token.Transfer(fromKey, outputAddress, amount);
                }
                else
                if (api.IsAsset(symbol))
                {
                    result = api.SendAsset(fromKey, outputAddress, symbol, amount);
                }
                else
                {
                    Console.WriteLine("Unknown symbol.");
                    Environment.Exit(-1);
                }
            }
            catch
            {
                Console.WriteLine("Error executing transaction.");
                Environment.Exit(-1);
            }

            Console.WriteLine("Transaction result: " + result);
        }