Esempio n. 1
0
        public ITransactionSendResult txGetSendingResult(string txid)
        {
            Transaction  transactionLoad = null;
            BytesMessage txidByteMessage = GetByteMessageFromString(txid);

            try
            {
                transactionLoad = _walletClient.GetTransactionByIdAsync(txidByteMessage).GetAwaiter().GetResult();
            }
            catch (Exception exception)
            {
                return(new TransactionSendResult(TransactionStatus.Error, exception.Message, null));
            }

            if (transactionLoad == null)
            {
                return(new TransactionSendResult(TransactionStatus.Error, "Транзакция по txid не найдена.", null));
            }

            Block block = _walletClient.GetBlockByIdAsync(txidByteMessage).GetAwaiter().GetResult();

            ByteString rawDataData = transactionLoad.RawData.Data;

            //	var bigInteger = new BigInteger(rawDataData.ToByteArray());
            //	Info info = new Info(txid, transactionLoad.RawData.ToByteString().ToBase64(), DateTime.Now);
            return(new TransactionSendResult(TransactionStatus.Sent, null, null));
        }
Esempio n. 2
0
        public void MainTest()
        {
            Wallet.WalletClient wallet = GetMainNetWalletClient;

            string privateStrFrom = "D95611A9AF2A2A45359106222ED1AFED48853D9A44DEFF8DC7913F5CBA727366";
            //TJCnKsPa7y5okkXvQAidZBzqx3QyQ6sxMW

            KeyTriple keyTripleFrom = new KeyTriple(privateStrFrom);
            string    encode        = Base58.Encode(keyTripleFrom.GetAddressWallet(TypeNet.Main));
            string    encode1       = Base58.Encode(keyTripleFrom.GetAddressWallet(TypeNet.Test));


            string privateStrTo = "443A94E9EA11A10FB9E40E239ACD005F6FC4FFC43F302484281F804A76EB9419";
            //TYJ6pQuVDYc7ZFDf2xDjmUNidDeEEmXgBP
            KeyTriple keyTripleTo = new KeyTriple(privateStrTo);

            byte[] decode   = Base58.Decode("TPwJS5eC5BPGyMGtYTHNhPTB89sUWjDSSu");
            byte[] subArray = decode.SubArray(0, 21);
            subArray[0] = 160;

            Account account = new Account();

            //	account.a
            //	account.Address = ByteString.CopyFrom(keyTripleFrom.GetAddressWallet(TypeNet.Test).SubArray(0,21));
            //	account.Address = ByteString.CopyFrom(keyTripleFrom.GetAddressWallet(TypeNet.Main));
            account.Address = ByteString.CopyFrom(keyTripleFrom.GetAddressWallet(TypeNet.Main).SubArray(0, 21));
            //	account.Address = ByteString.CopyFrom(subArray);

            TaskAwaiter <Account> taskAwaiter   = wallet.GetAccountAsync(account).GetAwaiter();
            Account           result            = taskAwaiter.GetResult();
            AccountNetMessage accountNetMessage = wallet.GetAccountNetAsync(account).GetAwaiter().GetResult();
            BytesMessage      bytesMessage1     = new BytesMessage();

            bytesMessage1.Value = ByteString.CopyFrom(BitConverter.GetBytes(43586L));
            Block block = wallet.GetBlockByIdAsync(bytesMessage1).GetAwaiter().GetResult();


            byte[] privateBytes = keyTripleFrom.PrivateKey;
            byte[] fromBytes    = keyTripleFrom.GetAddressWallet(TypeNet.Main).SubArray(1, 20);
            byte[] toBytes      = keyTripleTo.GetAddressWallet(TypeNet.Main).SubArray(1, 20);
            long   amount       = 24071978L;     //100 TRX, api only receive trx in drop, and 1 trx = 1000000 drop

            Transaction transaction = CreateTransaction(wallet, fromBytes, toBytes, amount);

            byte[] transactionBytes = transaction.ToByteArray();


            //sign a transaction
            Transaction transaction1 = Sign(transaction, keyTripleFrom);

            //get byte transaction
            byte[] transaction2 = transaction1.ToByteArray();
            Console.WriteLine("transaction2 ::::: " + transaction2.ToHexString2());

            //sign a transaction in byte format and return a Transaction object
            var transaction3 = signTransaction2Object(transactionBytes, keyTripleFrom);

            Console.WriteLine("transaction3 ::::: " + transaction3.ToByteArray().ToHexString2());


            //sign a transaction in byte format and return a Transaction in byte format
            var transaction4 = signTransaction2Byte(transactionBytes, keyTripleFrom);

            Console.WriteLine("transaction4 ::::: " + transaction4.ToHexString2());
            //	Transaction transactionSigned =
            //		Wallet.WalletClient.signTransactionByApi(transaction, ecKey.getPrivKeyBytes());
            //	byte[]
            //		transaction5 = transactionSigned.toByteArray();
            //	Console.WriteLine("transaction5 ::::: " + ByteArray.toHexString(transaction5));
            //	if (!Arrays.equals(transaction4, transaction5))
            //		Console.WriteLine("transaction4 is not equals to transaction5 !!!!!");

            //	boolean result = broadcast(transaction4);

            //	Console.WriteLine(result);
            broadcast(wallet, transaction1);
        }