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()); }
public void CreateTest() { //1B7229DC6A062904C0D2B9D9A5795D4E555F5D1FEBC4A37B63EEB0FF4BC82D60 Passw0rdTRON TYYgwqYU9U8PT19bVDYjJckGrEnJoQKGUX // hash tran 6e712f3c4a50945973b655fbcaa503369ec4977a294d697823070026ba539110 // test wallet 2E77481EA8344FF43D5301D55F500CA45A4FEE62AFCDEFF3E8D4F2A4465C8CB2 TMmjx5RbjDwS4JoqKgujbsoa617b7DwfJq //D8414F1EFEC490358FEF9C8F6AE3980BD7F4323E0D2F2DE0DB9D590935D12F72 // String privateStr = "D95611A9AF2A2A45359106222ED1AFED48853D9A44DEFF8DC7913F5CBA727366"; String privateKeyHex = "750EB0343C49C9958387737108FB41EB53B6FD1FC074700F30082A7F9D4CC823"; //тестовая сеть TLWY31TNNkqENXNcSctb2mqH1qvRdwbjFL // String privateKeyHex = "74767E0ACC92FF6ED8E6A8C6CDDD61E27AEF20ACA3EC3E6492098C8B96CA23DB"; String toAddressWalletHes = "TPwJS5eC5BPGyMGtYTHNhPTB89sUWjDSSu"; // String toAddressWalletHes = "TSSrETcLX7ZaWuXRF652R4AJhXDWRX6JuV"; KeyTriple keyTriple = new KeyTriple(privateKeyHex); byte[] fromAddressWallet = keyTriple.GetAddressWallet(TypeNet.Main); String base58AddressWallet = Base58.Encode(fromAddressWallet); long amount = 231L; //100 TRX, api only receive trx in drop, and 1 trx = 1000000 drop Wallet.WalletClient wallet = GetMainNetWalletClient; // byte[] hashTransaction = StringHelper.HexStringToByteArray("f5eea816a16b1907f8b5c6394e133f285001585ce07f657240701511436ba836"); // BytesMessage bytesMessage = new BytesMessage(); // bytesMessage.Value=ByteString.CopyFrom(hashTransaction); // Transaction transactionLoad = wallet.GetTransactionByIdAsync(bytesMessage).GetAwaiter().GetResult(); /* * TransferContract transferContract = TransferContract.Parser.ParseFrom(transactionLoad.RawData.Contract[0].Parameter.Value.ToByteArray()); * String ownerAddress = Base58Check.Base58CheckEncoding.Encode(transferContract.OwnerAddress.ToByteArray()); * String toAddress = Base58Check.Base58CheckEncoding.Encode(transferContract.ToAddress.ToByteArray()); * String ownerAddress64 = transferContract.OwnerAddress.ToBase64(); */ // string sign11 = Base64.ToBase64String(Sha256.Hash(transactionLoad.RawData.ToByteArray())); // NodeList nodeList = wallet.ListNodesAsync().GetAwaiter().GetResult(); Transaction transaction = createTransaction(wallet, fromAddressWallet, Base58.Decode(toAddressWalletHes), amount); byte[] transactionBytes = transaction.ToByteArray(); Transaction transaction1 = sign(transaction, keyTriple); //get byte transaction byte[] transaction2 = transaction1.ToByteArray(); Console.WriteLine("transaction2 ::::: " + Base58.Encode(transaction2)); //sign a transaction in byte format and return a Transaction object // Transaction transaction3 = Transaction.Parser.ParseFrom(signTransaction2Byte(transactionBytes, keyTriple.PrivateKey)); // Console.WriteLine("transaction3 ::::: " + Base58Check.Base58CheckEncoding.Encode(transaction3.ToByteArray())); // wallet.CreateTransactionAsync() Return result1 = wallet.BroadcastTransactionAsync(transaction1).GetAwaiter().GetResult(); // Return result3 = wallet.BroadcastTransactionAsync(transaction3).GetAwaiter().GetResult(); }
public void TestAddressECKeyTest(string privateKeyHex, string publicKeyHes, TypeNet typeNet, string address) { KeyTriple keyTriple = new KeyTriple(privateKeyHex); byte[] addressWallet = keyTriple.GetAddressWallet(typeNet); if (!string.IsNullOrEmpty(publicKeyHes)) { string publicKeyBase58 = keyTriple.PublicKey.ToHexString2(); Assert.IsTrue(String.Equals(publicKeyHes, publicKeyBase58, StringComparison.CurrentCultureIgnoreCase)); } string base58 = Base58.Encode(addressWallet); Assert.IsTrue(String.Equals(address, base58, StringComparison.CurrentCultureIgnoreCase)); }
public void Main2Test() { WalletExtension.WalletExtensionClient walletExtension = GetMainNetWalletExtensionClient; var keyTriple = new KeyTriple("B7E85CA5910922C49DCCB92EE48DFEC13A60674845CB7152C86B88F31DA6DC67"); AccountPaginated accountPaginated = new AccountPaginated(); Account account = new Account(); account.Address = ByteString.CopyFrom(keyTriple.GetAddressWallet(TypeNet.Main).SubArray(0, 21)); accountPaginated.Account = account; accountPaginated.Offset = 0; accountPaginated.Limit = 10; TransactionList transactionList = walletExtension.GetTransactionsFromThisAsync(accountPaginated).GetAwaiter().GetResult(); }
public static bool isBelongsPublicKeyToPrivateKey(string privateKey, string publicKey) { KeyTriple keyTriple = new KeyTriple(privateKey); bool isValidPublicAddress = TronAddress.ValidateAddress(publicKey); if (!isValidPublicAddress) { return(false); } TronAddress tronAddress = TronAddress.CreateTronAddress(publicKey); string addressFromPublickKeyBase58 = tronAddress.AddressBase58; string addressFromPrivateKeyBase58 = Base58.Encode(keyTriple.GetAddressWallet(TypeNet.Main)); if (addressFromPublickKeyBase58 != addressFromPrivateKeyBase58) { return(false); } return(true); }
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); }