Exemplo n.º 1
0
        private Transaction CreateTransaction(Wallet.WalletClient wallet, byte[] fromBytes, byte[] toBytes, long amount)
        {
            Transaction transactionBuilder = new Transaction();
            Block       newestBlock        = wallet.GetNowBlockAsync(GetEmptyMessage).GetAwaiter().GetResult();

            Transaction.Types.Contract contractBuilder         = new Transaction.Types.Contract();
            TransferContract           transferContractBuilder = new TransferContract();

            transferContractBuilder.Amount       = amount;
            transferContractBuilder.ToAddress    = ByteString.CopyFrom(toBytes);
            transferContractBuilder.OwnerAddress = ByteString.CopyFrom(fromBytes);
            try
            {
                Any any = Any.Pack(transferContractBuilder.Clone());
                contractBuilder.Parameter = any;
            }
            catch (Exception)
            {
                return(null);
            }

            contractBuilder.Type       = Transaction.Types.Contract.Types.ContractType.TransferContract;
            transactionBuilder.RawData = new Transaction.Types.raw();
            transactionBuilder.RawData.Contract.Add(contractBuilder);
            transactionBuilder.RawData.Timestamp  = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            transactionBuilder.RawData.Expiration = newestBlock.BlockHeader.RawData.Timestamp + 10 * 60 * 60 * 1000;

            Transaction transaction    = transactionBuilder.Clone();
            var         refTransaction = SetReference(transaction, newestBlock);

            return(refTransaction);
        }
        public void getTransactionFromTestNetTesst()
        {
            Wallet.WalletClient wallet = GetMainNetWalletClient;

            //	wallet.tra

            byte[]       hashTransaction = StringHelper.HexStringToByteArray("d2e635f7c2d85cbcd343721047447b122a3c19e86f30651d8ec6ee76f744d065");
            BytesMessage bytesMessage    = new BytesMessage();

            bytesMessage.Value = ByteString.CopyFrom(hashTransaction);
            //				Transaction transactionLoad = wallet.GetTransactionByIdAsync(bytesMessage).GetAwaiter().GetResult();
            //				Transaction transactionLoad = wallet.GetTransactionByIdAsync(bytesMessage).GetAwaiter().GetResult();
            NodeList nodeList = wallet.ListNodes(GetEmptyMessage);
            Block    result   = wallet.GetNowBlockAsync(GetEmptyMessage).GetAwaiter().GetResult();
            //TK4BAeF72P3gop24RsoqPJynWgBBDv9fXX
            var keyTriple = new KeyTriple("B7E85CA5910922C49DCCB92EE48DFEC13A60674845CB7152C86B88F31DA6DC67");

            byte[]  addressWallet = keyTriple.GetAddressWallet(TypeNet.Main);
            string  encode        = Base58.Encode(addressWallet);
            Account account       = new Account();

            account.Address = ByteString.CopyFrom(addressWallet);
            Account account1 = wallet.GetAccountAsync(account).GetAwaiter().GetResult();

            //	new WalletExtension



            byte[]       hashTransaction1 = StringHelper.HexStringToByteArray("a7e974c6e69fb7741bf5e08de8a2d8f6617826c59422b440de22e0612b03c393");
            BytesMessage bytesMessage1    = new BytesMessage();

            bytesMessage1.Value = ByteString.CopyFrom(hashTransaction1);
            Transaction      transactionLoad1 = wallet.GetTransactionByIdAsync(bytesMessage1).GetAwaiter().GetResult();
            TransferContract transferContract = TransferContract.Parser.ParseFrom(transactionLoad1.RawData.Contract[0].Parameter.Value.ToByteArray());
        }
Exemplo n.º 3
0
        public void CanNotTransferFreeAgent()
        {
            var arsenal = new Team("Arsenal");
            var contract = new TransferContract(null, arsenal);

            Assert.Throws<NullReferenceException>(() => contract.Transfer(messi));
        }
Exemplo n.º 4
0
        public void Main4Test()
        {
            Wallet.WalletClient wallet = GetMainNetWalletClient;

            var keyTriple = new KeyTriple("B7E85CA5910922C49DCCB92EE48DFEC13A60674845CB7152C86B88F31DA6DC67");

            byte[]       hashTransaction1 = StringHelper.HexStringToByteArray("a7e974c6e69fb7741bf5e08de8a2d8f6617826c59422b440de22e0612b03c393");
            BytesMessage bytesMessage1    = new BytesMessage();

            bytesMessage1.Value = ByteString.CopyFrom(hashTransaction1);
            Transaction transactionLoad1 = wallet.GetTransactionByIdAsync(bytesMessage1).GetAwaiter().GetResult();

            Transaction.Types.Contract contract         = transactionLoad1.RawData.Contract[0];
            TransferContract           transferContract = TransferContract.Parser.ParseFrom(contract.Parameter.Value.ToByteArray());

            byte[] publicKeyOwner = transferContract.OwnerAddress.ToByteArray();
            string encode         = Base58.Encode(publicKeyOwner);

            byte[] transactionRaw = transactionLoad1.RawData.ToByteArray();
            byte[] hash           = Sha256.Hash(transactionRaw);
            string signBase64     = transactionLoad1.Signature[0].ToBase64();

            byte[] byteArray = transactionLoad1.Signature[0].ToByteArray();
            bool   isSignatureValidFromBytes = new ECSigner().IsSignatureValidFromBytes(hash, byteArray, publicKeyOwner);
        }
Exemplo n.º 5
0
        public void CanNotTransferFreeAgent()
        {
            var arsenal  = new Team("team2");
            var contract = new TransferContract(null, arsenal);

            Assert.Throws <NullReferenceException>(() => contract.Transfer(_player));
        }
Exemplo n.º 6
0
        public void CanNotTransferFreeAgentWithFalsifiedContract()
        {
            var vardar   = new Team("Vardar");
            var contract = new TransferContract(_team, vardar);

            Assert.Throws <Exception>(() => contract.Transfer(_player));
        }
Exemplo n.º 7
0
        private async Task <TransactionExtention> CreateTransactionAsync(string from, string to, long amount)
        {
            var fromAddress = Base58Encoder.DecodeFromBase58Check(from);
            var toAddress   = Base58Encoder.DecodeFromBase58Check(to);

            var transferContract = new TransferContract
            {
                OwnerAddress = ByteString.CopyFrom(fromAddress),
                ToAddress    = ByteString.CopyFrom(toAddress),
                Amount       = amount
            };

            var transaction = new Transaction();

            var contract = new Transaction.Types.Contract();

            try
            {
                contract.Parameter = Google.Protobuf.WellKnownTypes.Any.Pack(transferContract);
            }
            catch (Exception)
            {
                return(new TransactionExtention
                {
                    Result = new Return {
                        Result = false, Code = Return.Types.response_code.OtherError
                    },
                });
            }
            var newestBlock = await _wallet.GetNowBlock2Async(new EmptyMessage());

            contract.Type       = Transaction.Types.Contract.Types.ContractType.TransferContract;
            transaction.RawData = new Transaction.Types.raw();
            transaction.RawData.Contract.Add(contract);
            transaction.RawData.Timestamp  = DateTime.Now.Ticks;
            transaction.RawData.Expiration = newestBlock.BlockHeader.RawData.Timestamp + 10 * 60 * 60 * 1000;
            var blockHeight = newestBlock.BlockHeader.RawData.Number;
            var blockHash   = Sha256Sm3Hash.Of(newestBlock.BlockHeader.RawData.ToByteArray()).GetBytes();

            var bb = ByteBuffer.Allocate(8);

            bb.PutLong(blockHeight);

            var refBlockNum = bb.ToArray();

            transaction.RawData.RefBlockHash  = ByteString.CopyFrom(blockHash.SubArray(8, 8));
            transaction.RawData.RefBlockBytes = ByteString.CopyFrom(refBlockNum.SubArray(6, 2));

            var transactionExtension = new TransactionExtention
            {
                Transaction = transaction,
                Txid        = ByteString.CopyFromUtf8(transaction.GetTxid()),
                Result      = new Return {
                    Result = true, Code = Return.Types.response_code.Success
                },
            };

            return(transactionExtension);
        }
Exemplo n.º 8
0
        public void CanNotTransferFreeAgentWithFalsifiedContract()
        {
            var vardar = new Team("Vardar");
            var contract = new TransferContract(vardar, barcelona);

            var contractId = contract.Transfer(messi);

            Assert.Equal(0, contractId);
        }
Exemplo n.º 9
0
        public override bool Execute(TransactionResultCapsule result)
        {
            long fee = CalcFee();

            try
            {
                TransferContract transfer_contract = this.contract.Unpack <TransferContract>();
                long             amount            = transfer_contract.Amount;
                byte[]           to_address        = transfer_contract.ToAddress.ToByteArray();
                byte[]           owner_address     = transfer_contract.OwnerAddress.ToByteArray();

                AccountCapsule to_account = this.db_manager.Account.Get(to_address);
                if (to_account == null)
                {
                    bool default_permission = this.db_manager.DynamicProperties.GetAllowMultiSign() == 1;

                    to_account = new AccountCapsule(ByteString.CopyFrom(to_address),
                                                    AccountType.Normal,
                                                    this.db_manager.GetHeadBlockTimestamp(),
                                                    default_permission,
                                                    this.db_manager);

                    this.db_manager.Account.Put(to_address, to_account);
                    fee = fee + this.db_manager.DynamicProperties.GetCreateNewAccountFeeInSystemContract();
                }

                this.db_manager.AdjustBalance(owner_address, -fee);
                this.db_manager.AdjustBalance(this.db_manager.Account.GetBlackHole().CreateDatabaseKey(), fee);

                result.SetStatus(fee, code.Sucess);

                this.db_manager.AdjustBalance(owner_address, -amount);
                this.db_manager.AdjustBalance(to_address, amount);
            }
            catch (BalanceInsufficientException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }
            catch (ArithmeticException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }
            catch (InvalidProtocolBufferException e)
            {
                Logger.Debug(e.Message);
                result.SetStatus(fee, code.Failed);
                throw new ContractExeException(e.Message);
            }

            return(true);
        }
Exemplo n.º 10
0
        public TransactionCapsule(TransferContract contract, AccountStore account_store)
        {
            AccountCapsule account = account_store.Get(contract.OwnerAddress.ToByteArray());

            if (account == null || account.Balance < contract.Amount)
            {
                return;
            }

            CreateTransaction(contract, Transaction.Types.Contract.Types.ContractType.TransferContract);
        }
Exemplo n.º 11
0
        public static RpcApiResult CreateTransaferContract(byte[] owner_address,
                                                           byte[] to_address,
                                                           long amount, out TransferContract contract)
        {
            contract              = new TransferContract();
            contract.ToAddress    = ByteString.CopyFrom(to_address);
            contract.OwnerAddress = ByteString.CopyFrom(owner_address);
            contract.Amount       = amount;

            return(RpcApiResult.Success);
        }
Exemplo n.º 12
0
        public void Main3Test()
        {
            Wallet.WalletClient wallet = GetMainNetWalletClient;

            var keyTriple = new KeyTriple("B7E85CA5910922C49DCCB92EE48DFEC13A60674845CB7152C86B88F31DA6DC67");

            byte[]       hashTransaction1 = StringHelper.HexStringToByteArray("a7e974c6e69fb7741bf5e08de8a2d8f6617826c59422b440de22e0612b03c393");
            BytesMessage bytesMessage1    = new BytesMessage();

            bytesMessage1.Value = ByteString.CopyFrom(hashTransaction1);
            Transaction      transactionLoad1 = wallet.GetTransactionByIdAsync(bytesMessage1).GetAwaiter().GetResult();
            TransferContract transferContract = TransferContract.Parser.ParseFrom(transactionLoad1.RawData.Contract[0].Parameter.Value.ToByteArray());;
        }
Exemplo n.º 13
0
        public void TransferPlayerToNewTeam()
        {
            //Arrange = GIVEN
            barcelona.SignContract(messi);
            var arsenal = new Team("Arsenal");
            var contract = new TransferContract(barcelona, arsenal);

            //Act = WHEN
            var contractId = contract.Transfer(messi);

            //Assert = THEN
            Assert.NotEqual(0, contractId);
        }
Exemplo n.º 14
0
        public void TransferPlayerToNewTeam()
        {
            //Arrange = GIVEN
            _team.SignContract(_player);
            var arsenal  = new Team("team2");
            var contract = new TransferContract(_team, arsenal);

            //Act = WHEN
            var contractId = contract.Transfer(_player);

            //Assert = THEN
            Assert.NotEqual(0, contractId);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public static Transaction NewGenesisTransaction(byte[] key, long value)
        {
            if (!Wallet.IsValidAddress(key))
            {
                throw new ArgumentException("Invalid address");
            }
            TransferContract contract = new TransferContract();

            contract.Amount       = value;
            contract.OwnerAddress = ByteString.CopyFrom(Encoding.UTF8.GetBytes("0x0000000000000000000"));
            contract.ToAddress    = ByteString.CopyFrom(key);

            return(new TransactionCapsule(contract, Contract.Types.ContractType.TransferContract).Instance);
        }
Exemplo n.º 17
0
        public void ValidateTransactionTest()
        {
            Wallet.WalletClient wallet = GetMainNetWalletClient;

            byte[] hashTransaction1 =
                StringHelper.HexStringToByteArray("a7e974c6e69fb7741bf5e08de8a2d8f6617826c59422b440de22e0612b03c393");
            BytesMessage bytesMessage1 = new BytesMessage();

            bytesMessage1.Value = ByteString.CopyFrom(hashTransaction1);
            Transaction signedTransaction = wallet.GetTransactionByIdAsync(bytesMessage1).GetAwaiter().GetResult();

            Assert.IsTrue(signedTransaction.Signature.Count == signedTransaction.RawData.Contract.Count);

            RepeatedField <Transaction.Types.Contract> listContract = signedTransaction.RawData.Contract;

            byte[] hash  = Sha256.Hash(signedTransaction.RawData.ToByteArray());
            int    count = signedTransaction.Signature.Count;

            if (count == 0)
            {
                Assert.Fail();
            }

            for (int i = 0; i < count; ++i)
            {
                try
                {
                    Transaction.Types.Contract contract         = listContract[i];
                    TransferContract           transferContract = TransferContract.Parser.ParseFrom(signedTransaction.RawData.Contract[i].Parameter.Value.ToByteArray());


                    byte[] owner = transferContract.OwnerAddress.ToByteArray();
                    signedTransaction.Signature[i].ToByteArray();

                    string signatureBase64 = Base64.ToBase64String(signedTransaction.Signature[i].ToByteArray());
                    byte[] address         = signatureToAddress(hash, signatureBase64);
                    if (!Arrays.AreEqual(owner, address))
                    {
                        Assert.Fail();
                    }
                }
                catch (Exception e)
                {
                    e.ToString();
                    Assert.Fail();
                }
            }

            Assert.IsTrue(true);
        }
Exemplo n.º 18
0
        private void btnAddHavale_Click(object sender, RoutedEventArgs e)
        {
            if (ucAccountFirst.selectedAccountContract.AccountOwnerId < 0)
            {
                MessageBox.Show("Havale yapılacak hesabı seçiniz.", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (ucAccountSecond.selectedAccountContract.AccountOwnerId < 0)
            {
                MessageBox.Show("Havale yapılacak hesabı seçiniz.", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (ucAccountFirst.selectedAccountContract.AccountOwnerId == ucAccountSecond.selectedAccountContract.AccountOwnerId)
            {
                MessageBox.Show("İki hesapta aynı kişiye ait. Virman ekranına geçiniz.", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (ucAccountFirst.selectedAccountContract.FECId != ucAccountSecond.selectedAccountContract.FECId)
            {
                MessageBox.Show("Seçilen hesapların dövizleri aynı değil.", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (txtTransferAmount.Text == "")
            {
                MessageBox.Show("Tutar girilmedi", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
                txtTransferAmount.Focus();
                return;
            }
            else if (Convert.ToDecimal(txtTransferAmount.Text) > ucAccountFirst.selectedAccountContract.Balance)
            {
                MessageBox.Show("Hesapta yeterli bakiye yok.", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
                txtTransferAmount.Focus();
                return;
            }
            TransferContract transferContract = new TransferContract();

            transferContract.AccountFirstId  = ucAccountFirst.selectedAccountContract.Id;
            transferContract.AccountSecondId = ucAccountSecond.selectedAccountContract.Id;
            transferContract.Date            = dpTransferDate.SelectedDate.Value;
            transferContract.Amount          = Convert.ToDecimal(txtTransferAmount.Text);
            transferContract.Description     = txtTransferDesc.Text;
            AddTransfer(transferContract);
        }
Exemplo n.º 19
0
        private bool AddTransfer(TransferContract transferContract)
        {
            var connect = new Connector.Banking.GenericConnect <TransferResponse>();
            var request = new Types.Banking.TransferRequest();

            request.transferContract = transferContract;
            request.MethodName       = "AddTransfer";

            var response = connect.Execute(request);

            if (response.IsSuccess == true)
            {
                MessageBox.Show("Havale işlemi başarılı", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
                return(true);
            }
            else
            {
                MessageBox.Show("Havale işlemi hatalı", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
        public static Transaction createTransaction(Wallet.WalletClient wallet, byte[] from, byte[] to, long amount)
        {
            Transaction transactionBuilder = new Transaction();

            transactionBuilder.RawData = new Transaction.Types.raw();

            Block newestBlock = wallet.GetNowBlockAsync(new EmptyMessage()).GetAwaiter().GetResult();

            TransferContract transferContract = new TransferContract
            {
                Amount       = amount,
                OwnerAddress = ByteString.CopyFrom(@from),
                ToAddress    = ByteString.CopyFrom(to)
            };

            //	Transaction transactionNet = wallet.CreateTransactionAsync(transferContract).GetAwaiter().GetResult();


            Transaction.Types.Contract contract = new Transaction.Types.Contract();
            try
            {
                Any any = Any.Pack(transferContract);
                contract.Parameter = any;
            }
            catch (Exception)
            {
                return(null);
            }


            contract.Type = Transaction.Types.Contract.Types.ContractType.TransferContract;

            transactionBuilder.RawData.Contract.Add(contract);
            transactionBuilder.RawData.Timestamp  = DateTime.Now.Ticks;
            transactionBuilder.RawData.Expiration = newestBlock.BlockHeader.RawData.Timestamp + 10 * 60 * 60 * 1000;

            Transaction refTransaction = setReference(transactionBuilder, newestBlock);

            return(refTransaction);
        }
Exemplo n.º 21
0
 public static ServiceDescriptor SetTransferContract(this ServiceDescriptor descriptor, TransferContract contract)
 {
     descriptor.Metadatas["TContract"] = contract;
     return(descriptor);
 }
Exemplo n.º 22
0
        public async Task <Transaction> CreateTransactionAsync(TransferContract contract, CancellationToken token = default)
        {
            var wallet = GetWallet();

            return(await wallet.CreateTransactionAsync(contract, _configuration.GetCallOptions(token)));
        }
Exemplo n.º 23
0
        public override bool Validate()
        {
            if (this.contract == null)
            {
                throw new ContractValidateException("No contract");
            }

            if (this.db_manager == null)
            {
                throw new ContractValidateException("No DB Manager");
            }

            if (this.contract.Is(TransferContract.Descriptor))
            {
                long             fee = CalcFee();
                TransferContract transfer_contract = null;
                try
                {
                    transfer_contract = contract.Unpack <TransferContract>();
                }
                catch (InvalidProtocolBufferException e)
                {
                    Logger.Debug(e.Message);
                    throw new ContractValidateException(e.Message);
                }

                byte[] to_address    = transfer_contract.ToAddress.ToByteArray();
                byte[] owner_address = transfer_contract.OwnerAddress.ToByteArray();
                long   amount        = transfer_contract.Amount;

                if (!Wallet.IsValidAddress(owner_address))
                {
                    throw new ContractValidateException("Invalid ownerAddress");
                }

                if (!Wallet.IsValidAddress(to_address))
                {
                    throw new ContractValidateException("Invalid toAddress");
                }

                if (to_address.SequenceEqual(owner_address))
                {
                    throw new ContractValidateException("Cannot transfer trx to yourself.");
                }

                AccountCapsule owner_account = this.db_manager.Account.Get(owner_address);
                if (owner_account == null)
                {
                    throw new ContractValidateException("Validate TransferContract error, no OwnerAccount.");
                }

                long balance = owner_account.Balance;

                if (amount <= 0)
                {
                    throw new ContractValidateException("Amount must greater than 0.");
                }

                try
                {
                    AccountCapsule to_account = this.db_manager.Account.Get(to_address);
                    if (to_account == null)
                    {
                        fee = fee + this.db_manager.DynamicProperties.GetCreateNewAccountFeeInSystemContract();
                    }

                    if (balance < amount + fee)
                    {
                        throw new ContractValidateException(
                                  "Validate TransferContract error, balance is not sufficient.");
                    }
                }
                catch (ArithmeticException e)
                {
                    Logger.Debug(e.Message);
                    throw new ContractValidateException(e.Message);
                }
            }
            else
            {
                throw new ContractValidateException(
                          "contract type error,expected type [TransferContract],real type[" + this.contract.GetType().Name + "]");
            }

            return(true);
        }
Exemplo n.º 24
0
        public bool AddTransfer(TransferContract transferContract)
        {
            int index = 0;

            SqlParameter[] sqlParameters = new SqlParameter[5];
            SqlParameter   sqlParameter;

            if (transferContract.AccountFirstId == 0)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@AccountFirstId";
                sqlParameter.Value         = DBNull.Value;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            else if (transferContract.AccountFirstId != 0)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@AccountFirstId";
                sqlParameter.Value         = transferContract.AccountFirstId;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            if (transferContract.AccountSecondId == 0)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@AccountSecondId";
                sqlParameter.Value         = DBNull.Value;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            else if (transferContract.AccountSecondId != 0)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@AccountSecondId";
                sqlParameter.Value         = transferContract.AccountSecondId;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            if (transferContract.Description == "")
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@Description";
                sqlParameter.Value         = "";
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            else if (transferContract.Description != "")
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@Description";
                sqlParameter.Value         = transferContract.Description;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            if (transferContract.Amount == 0)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@Amount";
                sqlParameter.Value         = DBNull.Value;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            else if (transferContract.Amount != 0)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@Amount";
                sqlParameter.Value         = transferContract.Amount;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            if (transferContract.Date == null)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@Date";
                sqlParameter.Value         = DBNull.Value;
                sqlParameters[index]       = sqlParameter;
                index++;
            }
            else if (transferContract.Date != null)
            {
                sqlParameter = new SqlParameter();
                sqlParameter.ParameterName = "@Date";
                sqlParameter.Value         = transferContract.Date;
                sqlParameters[index]       = sqlParameter;
                index++;
            }

            SqlDataReader dr;

            dr = dbOperation.SpGetData("acc.ins_transfer", sqlParameters);

            if (dr.RecordsAffected == -1)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 25
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;
        }
Exemplo n.º 26
0
 public async Task <TransactionExtention> TransferAsync(TransferContract contract)
 {
     return(await _grpcClient.CreateTransaction2Async(contract));
 }