예제 #1
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++;
                }
            }
        }
예제 #2
0
파일: EosPay.cs 프로젝트: pjc0247/epy
        private async Task CheckActions()
        {
            var info = await eos.GetInfo();

            var actions = await eos.GetActions(accountName, -1, -10);

            foreach (var action in actions.Actions)
            {
                var jobj = action.ActionTrace.Act.Data as JObject;

                if (IsTransferAction(jobj))
                {
                    var from     = jobj.Value <string>("from");
                    var to       = jobj.Value <string>("to");
                    var memo     = jobj.Value <string>("memo");
                    var quantity = jobj.Value <string>("quantity");

                    if (pendingPayments.ContainsKey(memo) == false)
                    {
                        continue;
                    }
                    if (to != accountName)
                    {
                        continue;
                    }

                    var req = pendingPayments[memo];

                    if (CompareQuantity(quantity, req.token, req.value))
                    {
                        onPaymentVisible?.Invoke(req);
                        pendingPayments.Remove(memo);

                        req.visibleAt = action.BlockNum.Value;
                        dbPendingPayments.Delete(x => x.memo == memo);
                        dbVisiblePayments.Insert(req);
                    }
                }
            }

            foreach (var p in visiblePayments)
            {
                if (p.Key >= info.LastIrreversibleBlockNum)
                {
                    onPaymentComplete?.Invoke(p.Value);
                }
                else
                {
                    break;
                }
            }
            while (visiblePayments.Count > 0)
            {
                var p = visiblePayments.First();
                if (p.Key >= info.LastIrreversibleBlockNum)
                {
                    visiblePayments.RemoveAt(0);
                }
            }
        }
예제 #3
0
        public void SyncActions(IConfiguration config, SSPContext db, ILogger logger)
        {
            var action_pos_Row = db.Constants.FirstOrDefault(x => x.Id == "action_pos");
            var seq            = Convert.ToInt32(action_pos_Row.Value);
            //logger.LogInfo($"Current seq is " + seq);

            var actionsResult = eos.GetActions("signature.bp", seq + 1, 1 - 1).Result;

            if (actionsResult.actions != null && actionsResult.actions.Count() != 0)
            {
                for (var i = 0; i < actionsResult.actions.Count; i++)
                {
                    var act = actionsResult.actions[i];

                    try
                    {
                        switch (act.action_trace.act.name)
                        {
                        case "publish":
                        {
                            var tb_rows_pos_Row = db.Constants.FirstOrDefault(x => x.Id == "tb_rows_pos");
                            var tbRowsSeq       = Convert.ToInt32(tb_rows_pos_Row.Value);

                            var rowsResult = eos.GetTableRows <PublishRow>(new EosSharp.Core.Api.v1.GetTableRowsRequest()
                                {
                                    code        = "signature.bp",
                                    scope       = "signature.bp",
                                    table       = "signs",
                                    lower_bound = tbRowsSeq.ToString(),
                                    limit       = 1,
                                    json        = true
                                }).Result;

                            var dbRow      = db.Ariticle.FirstOrDefault(x => x.TransactionId == act.action_trace.trx_id);
                            var chainTbRow = rowsResult.rows.FirstOrDefault();

                            if (dbRow == null)
                            {
                                if (act.block_time <= DateTime.UtcNow.AddMinutes(-1))
                                {
                                    action_pos_Row.Value  = act.account_action_seq.ToString();
                                    tb_rows_pos_Row.Value = (++tbRowsSeq).ToString();
                                }
                            }
                            else
                            {
                                dbRow.SignId        = chainTbRow.id.ToString();
                                dbRow.State         = 1;
                                dbRow.FissionFactor = chainTbRow.fission_factor;

                                action_pos_Row.Value  = act.account_action_seq.ToString();
                                tb_rows_pos_Row.Value = (++tbRowsSeq).ToString();
                            }
                        }
                        break;

                        default:
                        {
                            action_pos_Row.Value = act.account_action_seq.ToString();
                        }
                        break;
                        }
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex.ToString());
                    }
                }
            }
        }