public async Task <IdentityAccount> GetAccount()
    {
        try
        {
            ScatterSharp.Core.Api.Network network = new ScatterSharp.Core.Api.Network()
            {
                blockchain = ScatterConstants.Blockchains.EOSIO,
                host       = "jungle3.cryptolions.io",
                port       = 443,
                chainId    = "2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840"
            };

            var fileStorage = new FileStorageProvider(Application.persistentDataPath + "/scatterapp.dat");
            using (var scatter = new Scatter(new ScatterConfigurator()
            {
                AppName = "UNITY-PC-SCATTER",
                Network = network,
                StorageProvider = fileStorage
            }, this))
            {
                await scatter.Connect();

                await scatter.GetIdentity(new IdentityRequiredFields()
                {
                    accounts = new List <ScatterSharp.Core.Api.Network>()
                    {
                        network
                    },
                    location = new List <LocationFields>(),
                    personal = new List <PersonalFields>()
                });

                var eos = new Eos(new EosSharp.Core.EosConfigurator()
                {
                    ChainId      = network.chainId,
                    HttpEndpoint = network.GetHttpEndpoint(),
                    SignProvider = new ScatterSignatureProvider(scatter)
                });

                var account = scatter.Identity.accounts.First();

                return(account);
            }
        }
        catch (ApiErrorException ex)
        {
            print(JsonConvert.SerializeObject(ex.error));
            return(null);
        }
        catch (ApiException ex)
        {
            print(ex.Content);
            return(null);
        }
        catch (Exception ex)
        {
            print(JsonConvert.SerializeObject(ex));
            return(null);
        }
    }
        public async Task PushTransaction()
        {
            try
            {
                await Scatter.Connect();

                await Scatter.GetIdentity(new IdentityRequiredFields()
                {
                    accounts = new List <ScatterSharp.Core.Api.Network>()
                    {
                        network
                    },
                    location = new List <LocationFields>(),
                    personal = new List <PersonalFields>()
                });

                var eos = new Eos(new EosSharp.Core.EosConfigurator()
                {
                    ChainId      = network.chainId,
                    HttpEndpoint = network.GetHttpEndpoint(),
                    SignProvider = new ScatterSignatureProvider(Scatter)
                });

                var account = Scatter.Identity.accounts.First();

                var result = await eos.CreateTransaction(new EosSharp.Core.Api.v1.Transaction()
                {
                    actions = new List <EosSharp.Core.Api.v1.Action>()
                    {
                        new EosSharp.Core.Api.v1.Action()
                        {
                            account       = "eosio.token",
                            authorization = new List <PermissionLevel>()
                            {
                                new PermissionLevel()
                                {
                                    actor = account.name, permission = account.authority
                                }
                            },
                            name = "transfer",
                            data = new Dictionary <string, string>()
                            {
                                { "from", account.name },
                                { "to", "auaglobalts5" },
                                { "quantity", "0.1000 EOS" },
                                { "memo", "" }
                            }
                        }
                    }
                });

                Console.WriteLine(JsonConvert.SerializeObject(result));
            }
            catch (Exception ex)
            {
                Console.WriteLine(JsonConvert.SerializeObject(ex));
                Assert.Fail();
            }
        }
示例#3
0
        public EosAdminTideAuthentication(Settings settings, ITideLogger logger)
        {
            _settings = settings;
            _logger   = logger;

            _eos = new Eos(new EosConfigurator {
                HttpEndpoint  = _settings.BlockchainEndpoint,
                ChainId       = _settings.BlockchainChainId,
                ExpireSeconds = 60,
                SignProvider  = new DefaultSignProvider(_settings.EosPrivateKey)
            });
        }
示例#4
0
文件: Form1.cs 项目: agjsoft/p3
        private void Work()
        {
            string account = "agj4navercom";
            var    eos     = new Eos(new EosConfigurator()
            {
                HttpEndpoint  = "https://nodes.get-scatter.com:443",
                ChainId       = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
                ExpireSeconds = 60000,
                //SignProvider = new DefaultSignProvider( "myprivatekey")
            });

            var a0        = Wait(eos.GetActions(account));
            int actionSeq = (int)a0.Actions.Last().AccountActionSeq + 1;

            while (true)
            {
                var a2 = Wait(eos.GetActions(account, actionSeq, 0));
                if (null == a2)
                {
                    Thread.Sleep(1100);
                }
                else if (0 == a2.Actions.Count)
                {
                    Thread.Sleep(200);
                }
                else
                {
                    foreach (var action in a2.Actions)
                    {
                        if (action.ActionTrace.Act.Account != "eosio.token")
                        {
                            continue;
                        }

                        if (action.ActionTrace.Act.Name != "transfer")
                        {
                            continue;
                        }

                        var body = JsonConvert.DeserializeObject <TransferBody>(action.ActionTrace.Act.Data.ToString());
                        if (body.to != account)
                        {
                            continue;
                        }

                        string quantity = body.quantity.Split(' ')[0];
                        RecvEOSQueue.Enqueue($"From:{body.from}, Quantity:{quantity}, Memo:{body.memo}");
                    }
                    actionSeq++;
                }
            }
        }
示例#5
0
        public StressUnitTests()
        {
            Eos = new Eos(new EosConfigurator()
            {
                SignProvider = new DefaultSignProvider("5K57oSZLpfzePvQNpsLS6NfKXLhhRARNU13q6u2ZPQCGHgKLbTA"),

                HttpEndpoint = "https://api.eossweden.se", //Mainnet
                ChainId      = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906"

                               //HttpEndpoint = "https://nodeos01.btuga.io",
                               //ChainId = "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f"
            });
        }
示例#6
0
        public async Task CheckAsync()
        {
            Eos eos = new Eos(new EosConfigurator()
            {
                HttpEndpoint  = "https://nodes.eos42.io", //Mainnet
                ChainId       = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
                ExpireSeconds = 60,
                SignProvider  = new DefaultSignProvider("myprivatekey")
            });

            var result = await eos.GetInfo();

            Result = result.ToString();
        }
示例#7
0
文件: EosPay.cs 项目: pjc0247/epy
        public void Run()
        {
            InitializeDB();
            ExpireOldRequests();
            SyncWithDB();

            eos = new Eos(new EosConfigurator()
            {
                HttpEndpoint  = endpoint, //Mainnet
                ChainId       = chain,
                ExpireSeconds = 60
            });

            sentinel = new Thread(() => { Sentinel(); });
            sentinel.Start();
        }
        /// <summary>
        /// Calls BuyTicket cleos function
        /// </summary>
        /// <param name="req"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public APIGatewayProxyResponse BuyTicket(APIGatewayProxyRequest req, ILambdaContext context)
        {
            string httpEndpoint;
            int    drawNo, totalTickets;
            string contract, buyer, message;

            if (req.StageVariables != null && req.StageVariables.ContainsKey("httpEndpoint"))
            {
                httpEndpoint = req.StageVariables["httpEndpoint"];
            }
            else
            {
                httpEndpoint = Constants.EOS.endPoint;
            }

            if (req.QueryStringParameters == null || !req.QueryStringParameters.ContainsKey("drawno") ||
                !req.QueryStringParameters.ContainsKey("totaltickets") || !req.QueryStringParameters.ContainsKey("contract") ||
                !req.QueryStringParameters.ContainsKey("buyer"))
            {
                message = "Missing input query params. Mandatory params : drawno, totaltickets, contract, buyer";
            }
            else
            {
                Int32.TryParse(req.QueryStringParameters["drawno"], out drawNo);
                Int32.TryParse(req.QueryStringParameters["totaltickets"], out totalTickets);
                contract = req.QueryStringParameters["contract"];
                buyer    = req.QueryStringParameters["buyer"];

                Eos eos = new Eos(new EosConfigurator()
                {
                    HttpEndpoint  = httpEndpoint,
                    ExpireSeconds = 60,
                    SignProvider  = new DefaultSignProvider(Constants.EOS.privateKey),
                    blocksBehind  = 3
                });

                RunPurchaseTicketSim(eos, drawNo, totalTickets, contract, buyer);

                message = $"Initiated {totalTickets} tickets purchase for draw: {drawNo}, contract: {contract}, buyer: {buyer} @endpoint {httpEndpoint}, RequestId: {context.AwsRequestId}";
            }


            return(new APIGatewayProxyResponse()
            {
                StatusCode = 200, Body = message
            });
        }
        private void RunPurchaseTicketSim(Eos eos, int drawNumber, int totalTickets, string contract, string buyer)
        {
            DateTime     startTime = DateTime.Now;
            List <Task>  tasks     = new List <Task>();
            TicketHelper ticket    = new TicketHelper();

            for (int i = 1; i <= totalTickets; i++)
            {
                var task = ticket.PurchaseTicket(eos, drawNumber, ticket.GenerateRandomTicket(),
                                                 contract, buyer, buyer);
                tasks.Add(task);
            }

            Console.WriteLine($"Published {totalTickets} tickets. Total Time {(DateTime.Now - startTime).TotalMilliseconds} ms.");
            Task.WaitAll(tasks.ToArray());
            Console.WriteLine($"Tasks Completed in Total Time {(DateTime.Now - startTime).TotalMilliseconds} ms.");
        }
    public async void PushTransaction()
    {
        try
        {
            ScatterSharp.Core.Api.Network network = new ScatterSharp.Core.Api.Network()
            {
                blockchain = ScatterConstants.Blockchains.EOSIO,
                host       = "nodes.eos42.io",
                port       = 443,
                chainId    = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906"
            };

            var fileStorage = new FileStorageProvider(Application.persistentDataPath + "/scatterapp.dat");

            using (var scatter = new Scatter(new ScatterConfigurator()
            {
                AppName = "UNITY-WEBGL-SCATTER",
                Network = network,
                StorageProvider = fileStorage
            }, this))
            {
                await scatter.Connect();

                await scatter.GetIdentity(new IdentityRequiredFields()
                {
                    accounts = new List <ScatterSharp.Core.Api.Network>()
                    {
                        network
                    },
                    location = new List <LocationFields>(),
                    personal = new List <PersonalFields>()
                });

                var eos = new Eos(new EosSharp.Core.EosConfigurator()
                {
                    ChainId      = network.chainId,
                    HttpEndpoint = network.GetHttpEndpoint(),
                    SignProvider = new ScatterSignatureProvider(scatter)
                });

                var account = scatter.Identity.accounts.First();

                var result = await eos.CreateTransaction(new EosSharp.Core.Api.v1.Transaction()
                {
                    actions = new List <EosSharp.Core.Api.v1.Action>()
                    {
                        new EosSharp.Core.Api.v1.Action()
                        {
                            account       = "eosio.token",
                            authorization = new List <PermissionLevel>()
                            {
                                new PermissionLevel()
                                {
                                    actor = account.name, permission = account.authority
                                }
                            },
                            name = "transfer",
                            data = new Dictionary <string, object>()
                            {
                                { "from", account.name },
                                { "to", "eosio" },
                                { "quantity", "0.0001 EOS" },
                                { "memo", "Unity3D WEBGL hello crypto world!" }
                            }
                        }
                    }
                });

                print(result);
            }
        }
        catch (Exception ex)
        {
            print(JsonConvert.SerializeObject(ex));
        }
    }
    public async void PushTransaction()
    {
        try
        {
            ScatterSharp.Core.Api.Network network = new ScatterSharp.Core.Api.Network()
            {
                blockchain = ScatterConstants.Blockchains.EOSIO,
                host       = "jungle3.cryptolions.io",
                port       = 443,
                chainId    = "2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840"
            };

            var fileStorage = new FileStorageProvider(Application.persistentDataPath + "/scatterapp.dat");
            using (var scatter = new Scatter(new ScatterConfigurator()
            {
                AppName = "UNITY-PC-SCATTER",
                Network = network,
                StorageProvider = fileStorage
            }, this))
            {
                await scatter.Connect();

                await scatter.GetIdentity(new IdentityRequiredFields()
                {
                    accounts = new List <ScatterSharp.Core.Api.Network>()
                    {
                        network
                    },
                    location = new List <LocationFields>(),
                    personal = new List <PersonalFields>()
                });

                var eos = new Eos(new EosSharp.Core.EosConfigurator()
                {
                    ChainId      = network.chainId,
                    HttpEndpoint = network.GetHttpEndpoint(),
                    SignProvider = new ScatterSignatureProvider(scatter)
                });

                var account = scatter.Identity.accounts.First();

                var result = await eos.CreateTransaction(new EosSharp.Core.Api.v1.Transaction()
                {
                    actions = new List <EosSharp.Core.Api.v1.Action>()
                    {
                        new EosSharp.Core.Api.v1.Action()
                        {
                            account       = "eosio.token",
                            authorization = new List <PermissionLevel>()
                            {
                                new PermissionLevel()
                                {
                                    actor = account.name, permission = account.authority
                                }
                            },
                            name = "transfer",
                            data = new Dictionary <string, object>()
                            {
                                { "from", account.name },
                                { "to", "eosio" },
                                { "quantity", "0.0001 EOS" },
                                { "memo", "Unity3D WEBGL hello crypto world!" }
                            }
                        }
                    }
                });

                print(result);
            }
        }
        catch (ApiErrorException ex)
        {
            print(JsonConvert.SerializeObject(ex.error));
        }
        catch (ApiException ex)
        {
            print(ex.Content);
        }
        catch (Exception ex)
        {
            print(JsonConvert.SerializeObject(ex));
        }
    }
示例#12
0
        public async Task <string> PurchaseTicket(Eos eos, int drawNumber, int[] ticket, string actionAccount, string actor, string ticketPurchaser)
        {
            string result  = "";
            int    attempt = 1;

            while (string.IsNullOrEmpty(result))
            {
                try
                {
                    result = await eos.CreateTransaction(new Transaction()
                    {
                        actions = new List <EosSharp.Core.Api.v1.Action>()
                        {
                            new EosSharp.Core.Api.v1.Action()
                            {
                                account       = actionAccount,
                                authorization = new List <PermissionLevel>()
                                {
                                    new PermissionLevel()
                                    {
                                        actor = actor, permission = "active"
                                    }
                                },
                                name = "createticket",
                                data = new
                                {
                                    purchaser    = ticketPurchaser,
                                    drawnumber   = drawNumber,
                                    entrynumbers = ticket,
                                    genreward    = false,
                                }
                            }
                        }
                    });

                    if (SendLogToConsole)
                    {
                        Console.WriteLine($"Attempt {attempt}, CreateTicket -> Thread Id : {Thread.CurrentThread.ManagedThreadId}, Transaction Id : {result}");
                    }
                }
                catch (ApiErrorException ex)
                {
                    if (SendLogToConsole)
                    {
                        Console.WriteLine($"Error.Name: {ex.error.name}, Error.What {ex.error.what}, Ticket {TicketAsString(ticket)}");
                        foreach (var err in ex.error.details)
                        {
                            Console.WriteLine($"Message: {err.message}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (SendLogToConsole)
                    {
                        Console.WriteLine($"{ex.Message}. Ticket {TicketAsString(ticket)}, Inner Exception {ex.InnerException}");
                    }
                }
                if (++attempt > MaxAttempts)
                {
                    break;
                }
            }

            return(result);
        }