diff --git a/src/Solana.Unity.Dex/Orca/Orca/OrcaDex.cs b/src/Solana.Unity.Dex/Orca/Orca/OrcaDex.cs index a1ce25b5..84a47ec4 100644 --- a/src/Solana.Unity.Dex/Orca/Orca/OrcaDex.cs +++ b/src/Solana.Unity.Dex/Orca/Orca/OrcaDex.cs @@ -22,6 +22,7 @@ using Solana.Unity.Dex.Quotes; using Solana.Unity.Dex.Ticks; using System.Linq; +using Solana.Unity.Rpc.Core.Http; namespace Orca { @@ -1069,7 +1070,8 @@ Commitment commitment ) { tb.SetFeePayer(feePayer); - tb.SetRecentBlockHash((await rpcClient.GetRecentBlockHashAsync(commitment)).Result.Value.Blockhash); + var latestBlockHash = await rpcClient.GetLatestBlockHashAsync(); + tb.SetRecentBlockHash(latestBlockHash.Result.Value.Blockhash); return Transaction.Deserialize(tb.Serialize()); } diff --git a/src/Solana.Unity.Dex/Orca/SolanaApi/SystemUtils.cs b/src/Solana.Unity.Dex/Orca/SolanaApi/SystemUtils.cs index 13cb0683..1262ecb6 100644 --- a/src/Solana.Unity.Dex/Orca/SolanaApi/SystemUtils.cs +++ b/src/Solana.Unity.Dex/Orca/SolanaApi/SystemUtils.cs @@ -7,6 +7,7 @@ using Solana.Unity.Rpc.Types; using Solana.Unity.Rpc.Core.Http; using Solana.Unity.Programs; +using Solana.Unity.Rpc.Models; namespace Solana.Unity.Dex.Orca.SolanaApi { @@ -55,10 +56,9 @@ public static async Task> TransferSolAsync( Commitment commitment = Commitment.Finalized ) { - var recentHash = await ctx.RpcClient.GetRecentBlockHashAsync(); - + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(); var tb = new TransactionBuilder() - .SetRecentBlockHash(recentHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(from.PublicKey) .AddInstruction(SystemProgram.Transfer(from.PublicKey, to, lamports)); @@ -84,10 +84,9 @@ public static async Task> CreateAccountAsync( Commitment commitment = Commitment.Finalized ) { - var recentHash = await ctx.RpcClient.GetRecentBlockHashAsync(); - + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(); var tx = new TransactionBuilder() - .SetRecentBlockHash(recentHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(feePayer) .AddInstruction(SystemProgram.CreateAccount( fromAccount: fromAccount, diff --git a/src/Solana.Unity.Dex/Orca/SolanaApi/TokenUtilsTransaction.cs b/src/Solana.Unity.Dex/Orca/SolanaApi/TokenUtilsTransaction.cs index e9f222b7..09ed0c4a 100644 --- a/src/Solana.Unity.Dex/Orca/SolanaApi/TokenUtilsTransaction.cs +++ b/src/Solana.Unity.Dex/Orca/SolanaApi/TokenUtilsTransaction.cs @@ -10,6 +10,7 @@ using Solana.Unity.Rpc; using Solana.Unity.Rpc.Models; using Solana.Unity.Rpc.Types; +using Solana.Unity.Rpc.Core.Http; namespace Solana.Unity.Dex.Orca.SolanaApi { @@ -33,9 +34,9 @@ public static async Task CreateMint( { ulong minBalanceForExemptionMint = (await rpc.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; - - var blockHash = await rpc.GetRecentBlockHashAsync(); - byte[] tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + + var latestBlockHashItem = await rpc.GetLatestBlockHashAsync(); + byte[] tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(authority) .AddInstruction(SystemProgram.CreateAccount( fromAccount: authority, @@ -79,12 +80,12 @@ public static async Task CreateAndMintToAssociatedTokenAccount ( ulong rentExemptionMin = (await rpc.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; - var blockHash = await rpc.GetRecentBlockHashAsync(); var tempAccount = new Account(); var sta = AssociatedTokenAccountProgram.DeriveAssociatedTokenAccount(tempAccount, mint); + var latestBlockHashItem = await rpc.GetLatestBlockHashAsync(); var trxBuild= new TransactionBuilder() .SetFeePayer(feePayer.PublicKey) - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .AddInstruction(SystemProgram.CreateAccount( feePayer, tempAccount, @@ -123,9 +124,9 @@ public static async Task CreateAndMintToAssociatedTokenAccount ( } else { - var blockHash = await rpc.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpc.GetLatestBlockHashAsync(); var txBuilder = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(feePayer.PublicKey) .AddInstruction( AssociatedTokenAccountProgram.CreateAssociatedTokenAccount( @@ -167,9 +168,9 @@ public static async Task MintToByAuthority( Account feePayer ) { - var blockHash = await rpc.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpc.GetLatestBlockHashAsync(); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(feePayer.PublicKey) .AddInstruction(TokenProgram.MintTo( mint, diff --git a/src/Solana.Unity.Examples/AssociatedTokenAccountsExample.cs b/src/Solana.Unity.Examples/AssociatedTokenAccountsExample.cs index 50e510b7..e4e18905 100644 --- a/src/Solana.Unity.Examples/AssociatedTokenAccountsExample.cs +++ b/src/Solana.Unity.Examples/AssociatedTokenAccountsExample.cs @@ -33,8 +33,6 @@ public async void Run() #region Create and Initialize a token Mint Account - RequestResult> blockHash = await RpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionAcc = (await RpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; ulong minBalanceForExemptionMint = @@ -50,8 +48,11 @@ public async void Run() Console.WriteLine($"MintAccount: {mintAccount}"); Console.WriteLine($"InitialAccount: {initialAccount}"); + var latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; + byte[] createAndInitializeMintToTx = new TransactionBuilder(). - SetRecentBlockHash(blockHash.Result.Value.Blockhash). + SetRecentBlockHash(latestBlockHash). SetFeePayer(ownerAccount). AddInstruction(SystemProgram.CreateAccount( ownerAccount, @@ -104,7 +105,7 @@ public async void Run() Console.WriteLine($"AssociatedTokenAccount: {associatedTokenAccount}"); byte[] createAssociatedTokenAccountTx = new TransactionBuilder(). - SetRecentBlockHash(blockHash.Result.Value.Blockhash). + SetRecentBlockHash(latestBlockHash). SetFeePayer(ownerAccount). AddInstruction(AssociatedTokenAccountProgram.CreateAssociatedTokenAccount( ownerAccount, diff --git a/src/Solana.Unity.Examples/HelloWorldExample.cs b/src/Solana.Unity.Examples/HelloWorldExample.cs index 575a4e29..207b57bc 100644 --- a/src/Solana.Unity.Examples/HelloWorldExample.cs +++ b/src/Solana.Unity.Examples/HelloWorldExample.cs @@ -1,6 +1,8 @@ using Solana.Unity.Programs; using Solana.Unity.Rpc; using Solana.Unity.Rpc.Builders; +using Solana.Unity.Rpc.Core.Http; +using Solana.Unity.Rpc.Models; using Solana.Unity.Wallet; using Solana.Unity.Wallet.Bip39; using System; @@ -43,10 +45,10 @@ public async void Run() var memoInstruction = MemoProgram.NewMemoV2("Hello Solana World, using Solana.Unity :)"); - var recentHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); var tx = new TransactionBuilder().AddInstruction(memoInstruction).SetFeePayer(wallet.Account) - .SetRecentBlockHash(recentHash.Result.Value.Blockhash).Build(wallet.Account); + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash).Build(wallet.Account); var txHash = await rpcClient.SendTransactionAsync(tx); diff --git a/src/Solana.Unity.Examples/InstructionDecoderExample.cs b/src/Solana.Unity.Examples/InstructionDecoderExample.cs index 113ce493..e295e36d 100644 --- a/src/Solana.Unity.Examples/InstructionDecoderExample.cs +++ b/src/Solana.Unity.Examples/InstructionDecoderExample.cs @@ -1,6 +1,7 @@ using Solana.Unity.Programs; using Solana.Unity.Rpc; using Solana.Unity.Rpc.Builders; +using Solana.Unity.Rpc.Core.Http; using Solana.Unity.Rpc.Models; using System; using System.IO; @@ -24,11 +25,12 @@ public async void Run() var fromAccount = wallet.GetAccount(10); var toAccount = wallet.GetAccount(8); - var blockHash = await rpcClient.GetRecentBlockHashAsync(); - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; + Console.WriteLine($"BlockHash >> {latestBlockHash}"); var msgBytes = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(SystemProgram.Transfer(fromAccount.PublicKey, toAccount.PublicKey, 10000000)) .AddInstruction(MemoProgram.NewMemo(fromAccount.PublicKey, "Hello from Sol.Net :)")) diff --git a/src/Solana.Unity.Examples/MultisigExamples.cs b/src/Solana.Unity.Examples/MultisigExamples.cs index 49adb626..42323ea4 100644 --- a/src/Solana.Unity.Examples/MultisigExamples.cs +++ b/src/Solana.Unity.Examples/MultisigExamples.cs @@ -27,8 +27,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption MultiSig >> {minBalanceForExemptionMultiSig}"); @@ -51,7 +49,8 @@ public async void Run() Account signerAccount4 = wallet.GetAccount(25103); Account signerAccount5 = wallet.GetAccount(25104); - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -92,9 +91,8 @@ public async void Run() string createMultiSigAndMintSignature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(createMultiSigAndMintSignature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount, @@ -155,8 +153,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption MultiSig >> {minBalanceForExemptionMultiSig}"); @@ -177,7 +173,8 @@ public async void Run() Account signerAccount2 = wallet.GetAccount(25101); Account signerAccount4 = wallet.GetAccount(25103); - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.MintToChecked( mintAccount.PublicKey, @@ -228,7 +225,8 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; @@ -257,7 +255,7 @@ public async void Run() // First we create a multi sig account to use as the token account authority // In this same transaction we transfer tokens using TransferChecked from the initialAccount in the example above // to the same token account we just finished creating - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -312,7 +310,7 @@ public async void Run() // After the previous transaction is confirmed we use TransferChecked to transfer tokens using the // multi sig account back to the initial account - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.Transfer( tokenAccountWithMultisigOwner, @@ -360,8 +358,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption MultiSig >> {minBalanceForExemptionMultiSig}"); @@ -393,7 +389,8 @@ public async void Run() Account freezeSigner5 = wallet.GetAccount(25414); // First we create a multi sig account to use as the token's freeze authority - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount, @@ -428,12 +425,10 @@ public async void Run() string signature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(signature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - - // Then we create an account which will be the token's mint authority // In this same transaction we initialize the token mint with said authorities - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount, @@ -480,10 +475,9 @@ public async void Run() signature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(signature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - // Here we mint tokens to an account using the mint authority multi sig - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount, @@ -527,11 +521,10 @@ public async void Run() signature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(signature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - // After doing this, we freeze the account to which we just minted tokens // Notice how the signers used are different, because the `freezeAuthority` has different signers - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.FreezeAccount( initialAccount, @@ -564,10 +557,9 @@ public async void Run() signature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(signature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - // Because we're actually cool people, we now thaw that same account and then set the authority to nothing - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.ThawAccount( initialAccount, @@ -628,8 +620,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption MultiSig >> {minBalanceForExemptionMultiSig}"); @@ -667,7 +657,8 @@ public async void Run() Account tokenAccountSigner4 = wallet.GetAccount(25493); Account tokenAccountSigner5 = wallet.GetAccount(25494); - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -704,9 +695,8 @@ public async void Run() string signature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(signature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -750,9 +740,8 @@ public async void Run() signature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(signature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.ApproveChecked( tokenAccountWithMultisigOwner, @@ -787,10 +776,8 @@ public async void Run() signature = await Examples.SubmitTxSendAndLog(txBytes); Examples.PollConfirmedTx(signature); - blockHash = await rpcClient.GetRecentBlockHashAsync(); - - - msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.TransferChecked( tokenAccountWithMultisigOwner, @@ -846,8 +833,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption MultiSig >> {minBalanceForExemptionMultiSig}"); @@ -880,7 +865,8 @@ public async void Run() Account tokenAccountSigner4 = wallet.GetAccount(25493); Account tokenAccountSigner5 = wallet.GetAccount(25494); - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.MintToChecked( mintAccount, @@ -947,8 +933,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption MultiSig >> {minBalanceForExemptionMultiSig}"); @@ -975,7 +959,8 @@ public async void Run() Console.WriteLine($"Account Balance >> {balance.Result.Value.UiAmountString}"); - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.BurnChecked( mintAccount, diff --git a/src/Solana.Unity.Examples/NameServiceProgramExamples.cs b/src/Solana.Unity.Examples/NameServiceProgramExamples.cs index 1c8c2ae1..7a6477b8 100644 --- a/src/Solana.Unity.Examples/NameServiceProgramExamples.cs +++ b/src/Solana.Unity.Examples/NameServiceProgramExamples.cs @@ -1,6 +1,8 @@ using Solana.Unity.Programs; using Solana.Unity.Rpc; using Solana.Unity.Rpc.Builders; +using Solana.Unity.Rpc.Core.Http; +using Solana.Unity.Rpc.Models; using Solana.Unity.Wallet; using System; using System.Threading.Tasks; @@ -53,7 +55,6 @@ public async void Run() { var wallet = new Wallet.Wallet(MnemonicWords); - var blockHash = await rpcClient.GetRecentBlockHashAsync(); var minBalanceForExemptionNameAcc = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(NameServiceProgram.NameAccountSize + 96)).Result; @@ -76,7 +77,8 @@ public async void Run() var reverseRegistry = GetReverseRegistryKey(ownerAccount.PublicKey.Key); Console.WriteLine($"ReverseRegistryKey: {reverseRegistry.Key}"); - var tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + var tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(payerAccount).AddInstruction( NameServiceProgram.CreateNameRegistry( twitterHandleRegistry, diff --git a/src/Solana.Unity.Examples/StakeExample.cs b/src/Solana.Unity.Examples/StakeExample.cs index 0032cc92..b84e7ed6 100644 --- a/src/Solana.Unity.Examples/StakeExample.cs +++ b/src/Solana.Unity.Examples/StakeExample.cs @@ -24,14 +24,15 @@ public async void Run() { var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords)); await rpcClient.RequestAirdropAsync(wallet.Account.PublicKey, 100_000_000); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; ulong minBalance = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(StakeProgram.StakeAccountDataSize)).Result; Account fromAccount = wallet.Account; PublicKey.TryCreateWithSeed(fromAccount.PublicKey, "yrdy1", StakeProgram.ProgramIdKey, out PublicKey stakeAccount); - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + Console.WriteLine($"BlockHash >> {latestBlockHash}"); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(SystemProgram.CreateAccountWithSeed( fromAccount, @@ -64,17 +65,18 @@ public async void Run() var b58 = new Base58Encoder(); string f = b58.EncodeData(seed); rpcClient.RequestAirdropAsync(wallet.Account.PublicKey, 100_000_000); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; ulong minbalanceforexception = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(StakeProgram.StakeAccountDataSize)).Result; Account fromAccount = wallet.Account; Account toAccount = wallet.GetAccount(1); rpcClient.RequestAirdropAsync(toAccount.PublicKey, 100_000_000); PublicKey.TryCreateWithSeed(fromAccount.PublicKey, "dog5", StakeProgram.ProgramIdKey, out PublicKey stakeAccount); - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + Console.WriteLine($"BlockHash >> {latestBlockHash}"); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(StakeProgram.AuthorizeWithSeed( stakeAccount, @@ -105,16 +107,17 @@ public async void Run() { var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords)); rpcClient.RequestAirdropAsync(wallet.Account.PublicKey, 100_000_000); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; Account fromAccount = wallet.Account; Account toAccount = wallet.GetAccount(1); PublicKey.TryCreateWithSeed(fromAccount.PublicKey, "dog1", StakeProgram.ProgramIdKey, out PublicKey stakeAccount); - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + Console.WriteLine($"BlockHash >> {latestBlockHash}"); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(StakeProgram.Authorize( stakeAccount, @@ -142,7 +145,8 @@ public async void Run() { var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords)); rpcClient.RequestAirdropAsync(wallet.Account.PublicKey, 100_000_000); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; ulong minbalanceforexception = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(StakeProgram.StakeAccountDataSize)).Result; Account fromAccount = wallet.Account; PublicKey.TryCreateWithSeed(fromAccount.PublicKey, "dog5", StakeProgram.ProgramIdKey, out PublicKey stakeAccount); @@ -158,10 +162,10 @@ public async void Run() UnixTimestamp = 0 }; - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + Console.WriteLine($"BlockHash >> {latestBlockHash}"); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(SystemProgram.CreateAccountWithSeed( fromAccount.PublicKey, @@ -197,7 +201,8 @@ public async void Run() { var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords)); rpcClient.RequestAirdropAsync(wallet.Account.PublicKey, 100_000_000); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; ulong minbalanceforexception = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(StakeProgram.StakeAccountDataSize)).Result; Account fromAccount = wallet.Account; Account stakeAccount = wallet.GetAccount(22); @@ -214,10 +219,10 @@ public async void Run() UnixTimestamp = 0 }; - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + Console.WriteLine($"BlockHash >> {latestBlockHash}"); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(SystemProgram.CreateAccount( fromAccount.PublicKey, @@ -250,7 +255,8 @@ public async void Run() { var wallet = new Wallet.Wallet(new Mnemonic(MnemonicWords)); rpcClient.RequestAirdropAsync(wallet.Account.PublicKey, 100_000_000); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; ulong minBalance = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(StakeProgram.StakeAccountDataSize)).Result; Account a6 = wallet.GetAccount(6); @@ -258,10 +264,10 @@ public async void Run() Account a4 = wallet.GetAccount(4); Account a3 = wallet.GetAccount(3); - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + Console.WriteLine($"BlockHash >> {latestBlockHash}"); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(a6) .AddInstruction(SystemProgram.CreateAccountWithSeed( a6.PublicKey, diff --git a/src/Solana.Unity.Examples/TokenSwapExample.cs b/src/Solana.Unity.Examples/TokenSwapExample.cs index afb25caf..90cf82e3 100644 --- a/src/Solana.Unity.Examples/TokenSwapExample.cs +++ b/src/Solana.Unity.Examples/TokenSwapExample.cs @@ -35,10 +35,11 @@ public async void Run() var tokenBMint = new Account(); var tokenBUserAccount = new Account(); + var latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //setup some mints and tokens owned by wallet - RequestResult> blockHash = await RpcClient.GetRecentBlockHashAsync(); var tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(SystemProgram.CreateAccount( wallet.Account, @@ -111,10 +112,11 @@ public async void Run() var swapTokenAAccount= new Account(); var swapTokenBAccount = new Account(); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //init the swap authority's token accounts - blockHash = await RpcClient.GetRecentBlockHashAsync(); tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(SystemProgram.CreateAccount( wallet.Account, @@ -160,10 +162,11 @@ public async void Run() var poolUserAccount = new Account(); var poolFeeAccount = new Account(); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //create the pool mint and the user and fee pool token accounts - blockHash = await RpcClient.GetRecentBlockHashAsync();; tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(SystemProgram.CreateAccount( wallet.Account, @@ -205,10 +208,11 @@ public async void Run() txSig = await Examples.SubmitTxSendAndLog(tx); Examples.PollConfirmedTx(txSig); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //create the swap - blockHash = await RpcClient.GetRecentBlockHashAsync();; tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(SystemProgram.CreateAccount( wallet.Account, @@ -246,10 +250,11 @@ public async void Run() txSig = await Examples.SubmitTxSendAndLog(tx); Examples.PollConfirmedTx(txSig); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //now a user can swap in the pool - blockHash = await RpcClient.GetRecentBlockHashAsync();; tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(program.Swap( swap, @@ -267,10 +272,11 @@ public async void Run() txSig = await Examples.SubmitTxSendAndLog(tx); Examples.PollConfirmedTx(txSig); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //user can add liq - blockHash = await RpcClient.GetRecentBlockHashAsync();; tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(program.DepositAllTokenTypes( swap, @@ -288,10 +294,11 @@ public async void Run() txSig = await Examples.SubmitTxSendAndLog(tx); Examples.PollConfirmedTx(txSig); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //user can remove liq - blockHash = await RpcClient.GetRecentBlockHashAsync();; tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(program.WithdrawAllTokenTypes( swap, @@ -310,10 +317,11 @@ public async void Run() txSig = await Examples.SubmitTxSendAndLog(tx); Examples.PollConfirmedTx(txSig); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //user can deposit single - blockHash = await RpcClient.GetRecentBlockHashAsync();; tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(program.DepositSingleTokenTypeExactAmountIn( swap, @@ -329,10 +337,11 @@ public async void Run() txSig = await Examples.SubmitTxSendAndLog(tx); Examples.PollConfirmedTx(txSig); + latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + //user can withdraw single - blockHash = await RpcClient.GetRecentBlockHashAsync();; tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(wallet.Account) .AddInstruction(program.WithdrawSingleTokenTypeExactAmountOut( swap, diff --git a/src/Solana.Unity.Examples/TransactionBuilderExample.cs b/src/Solana.Unity.Examples/TransactionBuilderExample.cs index 047b7735..72886e01 100644 --- a/src/Solana.Unity.Examples/TransactionBuilderExample.cs +++ b/src/Solana.Unity.Examples/TransactionBuilderExample.cs @@ -27,11 +27,12 @@ public async void Run() Account fromAccount = wallet.GetAccount(10); Account toAccount = wallet.GetAccount(8); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; + Console.WriteLine($"BlockHash >> {latestBlockHash}"); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(SystemProgram.Transfer(fromAccount.PublicKey, toAccount.PublicKey, 10000000)) .AddInstruction(MemoProgram.NewMemo(fromAccount.PublicKey, "Hello from Sol.Net :)")) @@ -58,7 +59,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); ulong minBalanceForExemptionAcc = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption Account >> {minBalanceForExemptionAcc}"); @@ -74,7 +74,9 @@ public async void Run() Account initialAccount = wallet.GetAccount(3333); Console.WriteLine($"InitialAccount: {initialAccount}"); - byte[] tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + + byte[] tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -128,7 +130,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); ulong minBalanceForExemptionAcc = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption Account >> {minBalanceForExemptionAcc}"); @@ -144,7 +145,9 @@ public async void Run() Account initialAccount = wallet.GetAccount(26); Console.WriteLine($"InitialAccount: {initialAccount}"); - byte[] tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + + byte[] tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.MintTo( mintAccount.PublicKey, @@ -177,7 +180,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); ulong minBalanceForExemptionAcc = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption Account >> {minBalanceForExemptionAcc}"); @@ -190,7 +192,9 @@ public async void Run() Account newAccount = wallet.GetAccount(33); Console.WriteLine($"NewAccount: {newAccount}"); - byte[] tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + + byte[] tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -233,7 +237,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); ulong minBalanceForExemptionAcc = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption Account >> {minBalanceForExemptionAcc}"); @@ -247,8 +250,10 @@ public async void Run() Account newAccount = wallet.GetAccount(27); Console.WriteLine($"NewAccount: {newAccount}"); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -294,7 +299,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); ulong minBalanceForExemptionAcc = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(NonceAccount.AccountDataSize)).Result; @@ -305,8 +309,10 @@ public async void Run() Account newAuthority = wallet.GetAccount(1129); Console.WriteLine($"NewAuthority: {newAuthority}"); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( ownerAccount.PublicKey, @@ -399,8 +405,6 @@ public async void Run() { Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - ulong minBalanceForExemptionMultiSig = (await rpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.MultisigAccountDataSize)).Result; Console.WriteLine($"MinBalanceForRentExemption MultiSig >> {minBalanceForExemptionMultiSig}"); @@ -415,7 +419,9 @@ public async void Run() Account mintAccount = wallet.GetAccount(21); Account initialAccount = wallet.GetAccount(26); - byte[] msgData = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + + byte[] msgData = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.Burn( initialAccount.PublicKey, @@ -453,11 +459,12 @@ public async void Run() Account fromAccount = wallet.GetAccount(10); Account toAccount = wallet.GetAccount(8); - RequestResult> blockHash = await rpcClient.GetRecentBlockHashAsync(); - Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}"); + var latestBlockHashItem = await rpcClient.GetLatestBlockHashAsync(); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; + Console.WriteLine($"BlockHash >> {latestBlockHash}"); TransactionBuilder txBuilder = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(fromAccount) .AddInstruction(SystemProgram.Transfer(fromAccount.PublicKey, toAccount.PublicKey, 10000000)) .AddInstruction(MemoProgram.NewMemo(fromAccount.PublicKey, "Hello from Sol.Net :)")); diff --git a/src/Solana.Unity.Examples/TransactionDecodingExample.cs b/src/Solana.Unity.Examples/TransactionDecodingExample.cs index 7bca53da..46848385 100644 --- a/src/Solana.Unity.Examples/TransactionDecodingExample.cs +++ b/src/Solana.Unity.Examples/TransactionDecodingExample.cs @@ -27,7 +27,6 @@ public async void Run() { var wallet = new Wallet.Wallet(MnemonicWords); - RequestResult> blockHash = await RpcClient.GetRecentBlockHashAsync(); ulong minBalanceForExemptionAcc = (await RpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; ulong minBalanceForExemptionMint = @@ -43,8 +42,10 @@ public async void Run() Console.WriteLine($"MintAccount: {mintAccount}"); Console.WriteLine($"InitialAccount: {initialAccount}"); + var latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); + byte[] msgData = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.InitializeMint( mintAccount.PublicKey, diff --git a/src/Solana.Unity.Programs/Abstract/TransactionalBaseClient.cs b/src/Solana.Unity.Programs/Abstract/TransactionalBaseClient.cs index ce460aa3..d9d1b2ec 100644 --- a/src/Solana.Unity.Programs/Abstract/TransactionalBaseClient.cs +++ b/src/Solana.Unity.Programs/Abstract/TransactionalBaseClient.cs @@ -54,12 +54,10 @@ protected TransactionalBaseClient(IRpcClient rpcClient, IStreamingRpcClient stre protected async Task> SignAndSendTransaction(TransactionInstruction instruction, PublicKey feePayer, Func signingCallback, Commitment commitment = Commitment.Finalized) { + var latestBlockHashItem = await RpcClient.GetLatestBlockHashAsync(); TransactionBuilder tb = new TransactionBuilder(); tb.AddInstruction(instruction); - - var recentHash = await RpcClient.GetRecentBlockHashAsync(); - - tb.SetRecentBlockHash(recentHash.Result.Value.Blockhash); + tb.SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash); tb.SetFeePayer(feePayer); var wireFmt = tb.CompileMessage(); diff --git a/test/Solana.Unity.Dex.Test/Orca/Integration/IncreaseLiquidityTests.cs b/test/Solana.Unity.Dex.Test/Orca/Integration/IncreaseLiquidityTests.cs index a020161b..1aa43fd8 100644 --- a/test/Solana.Unity.Dex.Test/Orca/Integration/IncreaseLiquidityTests.cs +++ b/test/Solana.Unity.Dex.Test/Orca/Integration/IncreaseLiquidityTests.cs @@ -16,6 +16,8 @@ using Solana.Unity.Dex.Orca.Core.Errors; using Solana.Unity.Dex.Orca.Core.Accounts; using Solana.Unity.Dex.Ticks; +using Solana.Unity.Rpc.Core.Http; +using Solana.Unity.Rpc.Models; namespace Solana.Unity.Dex.Test.Orca.Integration { @@ -287,9 +289,10 @@ public static async Task InitializeIncreaseLiquiditySingleTransaction() ); //initialize tick array, open position, and increase liquidity in one transaction - var blockHash = await _context.RpcClient.GetRecentBlockHashAsync(_context.WhirlpoolClient.DefaultCommitment); + var latestBlockHashItem = await _context.RpcClient.GetLatestBlockHashAsync(_context.WhirlpoolClient.DefaultCommitment); + string latestBlockHash = latestBlockHashItem.Result.Value.Blockhash; byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHash) .SetFeePayer(openPositionParams.Accounts.Funder) .AddInstruction(WhirlpoolProgram.InitializeTickArray( programId: _context.ProgramId, diff --git a/test/Solana.Unity.Dex.Test/Orca/Utils/LiquidityTestUtils.cs b/test/Solana.Unity.Dex.Test/Orca/Utils/LiquidityTestUtils.cs index 14887d71..1a6a96fc 100644 --- a/test/Solana.Unity.Dex.Test/Orca/Utils/LiquidityTestUtils.cs +++ b/test/Solana.Unity.Dex.Test/Orca/Utils/LiquidityTestUtils.cs @@ -12,6 +12,7 @@ using Solana.Unity.Rpc; using Solana.Unity.Rpc.Builders; using Solana.Unity.Rpc.Types; +using Solana.Unity.Rpc.Models; namespace Solana.Unity.Dex.Test.Orca.Utils { @@ -302,12 +303,12 @@ public static async Task CreateAssociatedTokenAccountInstructionIfNotExtant(Publ bool exists = await TokenUtilsTransaction.TokenAccountExists( rpc, ata, commitment ); - var recentHash = await rpc.GetRecentBlockHashAsync(commitment); if (!exists) { + var latestBlockHashItem = await rpc.GetLatestBlockHashAsync(); TransactionBuilder builder = new(); builder.SetFeePayer(feePayer); - builder.SetRecentBlockHash(recentHash.Result.Value.Blockhash); + builder.SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash); builder.AddInstruction( AssociatedTokenAccountProgram.CreateAssociatedTokenAccount( feePayer, owner, mintAddress, idempotent: true diff --git a/test/Solana.Unity.Dex.Test/Orca/Utils/TokenUtils.cs b/test/Solana.Unity.Dex.Test/Orca/Utils/TokenUtils.cs index 4dd2be11..7041781a 100644 --- a/test/Solana.Unity.Dex.Test/Orca/Utils/TokenUtils.cs +++ b/test/Solana.Unity.Dex.Test/Orca/Utils/TokenUtils.cs @@ -45,8 +45,8 @@ public static async Task CreateMintAsync( mintAccount = (mintAccount == null) ? new Account() : mintAccount; Account ownerAccount = authority; - var blockHash = await ctx.RpcClient.GetRecentBlockHashAsync(commitment); - byte[] tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(commitment); + byte[] tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(authority) .AddInstruction(SystemProgram.CreateAccount( fromAccount: ownerAccount.PublicKey, @@ -85,9 +85,9 @@ public static async Task CreateTokenAccountAsync( ulong minBalanceForExemption = (await ctx.RpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; - var blockHash = await ctx.RpcClient.GetRecentBlockHashAsync(commitment); + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(commitment); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(SystemProgram.CreateAccount( fromAccount: ownerAccount, @@ -131,9 +131,9 @@ public static async Task CreateAndMintToTokenAccountAsync( ulong minBalanceForExemption = (await ctx.RpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result; - var blockHash = await ctx.RpcClient.GetRecentBlockHashAsync(commitment); + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(fromAccount) .AddInstruction(SystemProgram.CreateAccount( //create account fromAccount: fromAccount, @@ -179,9 +179,8 @@ public static async Task> ApproveTokenAsync( Commitment commitment = Commitment.Finalized ) { - var blockHash = await ctx.RpcClient.GetRecentBlockHashAsync(commitment); - - byte[] tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(commitment); + byte[] tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ownerAccount) .AddInstruction(TokenProgram.Approve( source: tokenAccount, @@ -212,9 +211,8 @@ public static async Task> SetAuthorityAsync( Commitment commitment = Commitment.Finalized ) { - var blockHash = await ctx.RpcClient.GetRecentBlockHashAsync(commitment); - - byte[] tx = new TransactionBuilder().SetRecentBlockHash(blockHash.Result.Value.Blockhash) + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(); + byte[] tx = new TransactionBuilder().SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(authorityAccount) .AddInstruction(TokenProgram.SetAuthority( account: tokenAccount, @@ -248,9 +246,9 @@ public static async Task> MintToByAuthorityAsync( Commitment commitment = Commitment.Finalized ) { - var blockHash = await ctx.RpcClient.GetRecentBlockHashAsync(commitment); + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(commitment); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(feePayer.PublicKey) .AddInstruction(TokenProgram.MintTo( mint, @@ -281,9 +279,9 @@ public static async Task> TransferTokensAsync( Commitment commitment = Commitment.Finalized ) { - var blockHash = await ctx.RpcClient.GetRecentBlockHashAsync(commitment); + var latestBlockHashItem = await ctx.RpcClient.GetLatestBlockHashAsync(commitment); byte[] tx = new TransactionBuilder() - .SetRecentBlockHash(blockHash.Result.Value.Blockhash) + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash) .SetFeePayer(ctx.WalletPubKey) .AddInstruction( TokenProgram.Transfer( @@ -353,11 +351,11 @@ public static async Task CloseAta(IRpcClient rpc, PublicKey mint, Account author balance = (await rpc.GetTokenBalanceByOwnerAsync( authority.PublicKey, mint)).Result.Value.AmountUlong; } - var blockHash = await rpc.GetRecentBlockHashAsync(commitment: Commitment.Finalized); + var latestBlockHashItem = await rpc.GetLatestBlockHashAsync(commitment: Commitment.Finalized); TransactionBuilder txb = new(); txb .SetFeePayer(authority) - .SetRecentBlockHash(blockHash.Result.Value.Blockhash); + .SetRecentBlockHash(latestBlockHashItem.Result.Value.Blockhash); if (balance > 0) { // Send the balance to a random ATA, close fails if balance is not 0 for not native tokens