コード例 #1
0
        public static bool OnGetBlockByLimitNext(JToken id, string method, JArray parameters, out JToken result)
        {
            result = new JObject();

            if (parameters == null || parameters.Count != 1)
            {
                result = RpcMessage.CreateErrorResult(id, RpcMessage.INVALID_PARAMS, "Invalid parameters");
                return(false);
            }

            try
            {
                BlockLimit         limit  = BlockLimit.Parser.ParseFrom(parameters[0].ToObject <byte[]>());
                BlockListExtention blocks = new BlockListExtention();
                Manager.Instance.DBManager.Block.GetLimitNumber(limit.StartNum, limit.EndNum - limit.StartNum).ForEach(block =>
                {
                    blocks.Block.Add(RpcApiService.CreateBlockExtention(block));
                });

                result = JToken.FromObject(blocks.ToByteArray());
            }
            catch (System.Exception e)
            {
                result = RpcMessage.CreateErrorResult(id, RpcMessage.UNKNOWN_ERROR, e.Message);
                return(false);
            }

            return(true);
        }
コード例 #2
0
        private List <TransactionAtom> GetTransactionByRangeBlocks(long startBlockId, long endBlockId)
        {
            List <TransactionAtom> transferContractList = new List <TransactionAtom>();

            long startPosition = 1;
            long endPosition   = 1600000;
            long step          = 100;

            long currentPosition = startBlockId;

            while (currentPosition <= endBlockId)
            {
                long currentStartPosition = currentPosition;
                long currentEndPosition   = currentStartPosition + step;

                var blocklimit = new BlockLimit
                {
                    StartNum = currentStartPosition,
                    EndNum   = currentEndPosition
                };
                BlockList qqqq = _walletClient.GetBlockByLimitNext(blocklimit);

                foreach (Block block1 in qqqq.Block)
                {
                    foreach (Transaction transaction in block1.Transactions)
                    {
                        foreach (Transaction.Types.Contract contract1 in transaction.RawData.Contract)
                        {
                            if (contract1.Type == Transaction.Types.Contract.Types.ContractType.TransferContract)
                            {
                                ByteString       parameterValue   = contract1.Parameter.Value;
                                TransferContract transferContract =
                                    TransferContract.Parser.ParseFrom(parameterValue.ToByteArray());

                                TronAddress     fromAccount = new TronAddress(transferContract.OwnerAddress.ToByteArray());
                                TronAddress     toAccount   = new TronAddress(transferContract.ToAddress.ToByteArray());
                                TransactionAtom ta          = new TransactionAtom(transferContract.OwnerAddress.ToByteArray(), transferContract.ToAddress.ToByteArray(),
                                                                                  transferContract.Amount,
                                                                                  transaction.RawData);

                                transferContractList.Add(ta);
                            }
                        }
                    }
                }

                currentPosition = currentEndPosition;
            }

            return(transferContractList);
        }
コード例 #3
0
        public static RpcApiResult GetBlockByLimitNext(long start, long end, out BlockListExtention blocks)
        {
            blocks = null;

            BlockLimit limit = new BlockLimit();

            limit.StartNum = start;
            limit.EndNum   = end;

            JObject receive = SendCommand(RpcCommand.Block.GetBlockByLimitNext, new JArray()
            {
                limit.ToByteArray()
            });

            if (receive.TryGetValue("error", out JToken value))
            {
                return(new RpcApiResult(false, value["code"].ToObject <int>(), value["message"].ToObject <string>()));
            }

            blocks = BlockListExtention.Parser.ParseFrom(receive["result"].ToObject <byte[]>());

            return(RpcApiResult.Success);
        }
コード例 #4
0
        //    [DataRow("TMy3cNNSZHY5d6F39BUbwUExJR93QDpGeh", StringType.Base58, TypeNet.Main)]
        public void DockerConnectTest(string addressBase58, StringType stringType, TypeNet typeNet)
        {
            //  ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(typeNet, "172.17.0.2", 50051);
            // ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(typeNet);
            //  ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(typeNet, "10.0.75.1", 50041);
            ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(typeNet, "10.0.75.1", 50051);

            //  ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(typeNet, "18.184.238.21", 50051);


            Wallet.WalletClient walletClient = new Latoken.CurrencyProvider.Protocol.Tron.Grpc.Api.Wallet.WalletClient(protocolConfiguration.Channel);
            NodeList            listNodes    = walletClient.ListNodes(new EmptyMessage());


            CurrencyProvider.Protocol.Tron.CurrencyProvider currencyProvider = new CurrencyProvider.Protocol.Tron.CurrencyProvider(protocolConfiguration);

            var rr  = BitConverter.GetBytes(152948);
            var ddd = rr.ToHexString2();

            BytesMessage numberMessa = new BytesMessage();

            numberMessa.Value = Google.Protobuf.ByteString.CopyFrom(ddd.FromHexToByteArray2());
            var dd = walletClient.GetBlockById(numberMessa);


            var block = walletClient.GetNowBlock(new EmptyMessage());

            //    long balance = currencyProvider.balanceByAddress(addressBase58);
            //   Console.WriteLine($"{addressBase58}:{balance}");
            //  Assert.IsTrue(balance > 0);
            List <TransactionAtom> transferContractList = new List <TransactionAtom>();

            int startPosition   = 1;
            int endPosition     = 1600000;
            int step            = 100;
            int currentPosition = startPosition;

            while (currentPosition <= endPosition)
            {
                int currentStartPosition = currentPosition;
                int currentEndPosition   = currentStartPosition + step;

                var blocklimit = new BlockLimit();
                blocklimit.StartNum = currentStartPosition;
                blocklimit.EndNum   = currentEndPosition;
                BlockList qqqq = walletClient.GetBlockByLimitNext(blocklimit);

                foreach (Block block1 in qqqq.Block)
                {
                    foreach (Transaction transaction in block1.Transactions)
                    {
                        foreach (Transaction.Types.Contract contract1 in transaction.RawData.Contract)
                        {
                            if (contract1.Type == Transaction.Types.Contract.Types.ContractType.TransferContract)
                            {
                                ByteString       parameterValue   = contract1.Parameter.Value;
                                TransferContract transferContract = TransferContract.Parser.ParseFrom(parameterValue.ToByteArray());

                                TronAddress     fromAccount = new TronAddress(transferContract.OwnerAddress.ToByteArray());
                                TronAddress     toAccount   = new TronAddress(transferContract.ToAddress.ToByteArray());
                                TransactionAtom ta          = new TransactionAtom(fromAccount, toAccount, transferContract.Amount, new TransactionHelper().GetTransactionHash(transaction));

                                transferContractList.Add(ta);
                            }
                        }
                    }
                }

                currentPosition = currentEndPosition;
            }

            //          var eeede = qqqq.Block[0].Transactions[0];
            //        var contract = eeede.RawData.Contract[0].Parameter;
        }
コード例 #5
0
 public async Task <BlockListExtention> GetBlockByLimitNextAsync(BlockLimit blockLimit)
 {
     return(await _grpcClient.GetBlockByLimitNext2Async(blockLimit));
 }
コード例 #6
0
        public async Task <BlockList> GetBlockByLimitNextAsync(BlockLimit blockLimit, CancellationToken token = default)
        {
            var wallet = GetWallet();

            return(await wallet.GetBlockByLimitNextAsync(blockLimit, _configuration.GetCallOptions(token)));
        }