Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Solana.Unity.Dex/Orca/Orca/OrcaDex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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());
}
Expand Down
11 changes: 5 additions & 6 deletions src/Solana.Unity.Dex/Orca/SolanaApi/SystemUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -55,10 +56,9 @@ public static async Task<RequestResult<string>> 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));

Expand All @@ -84,10 +84,9 @@ public static async Task<RequestResult<string>> 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,
Expand Down
19 changes: 10 additions & 9 deletions src/Solana.Unity.Dex/Orca/SolanaApi/TokenUtilsTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -33,9 +34,9 @@ public static async Task<Transaction> 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,
Expand Down Expand Up @@ -79,12 +80,12 @@ public static async Task<Transaction> 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,
Expand Down Expand Up @@ -123,9 +124,9 @@ public static async Task<Transaction> 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(
Expand Down Expand Up @@ -167,9 +168,9 @@ public static async Task<Transaction> 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,
Expand Down
9 changes: 5 additions & 4 deletions src/Solana.Unity.Examples/AssociatedTokenAccountsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public async void Run()
#region Create and Initialize a token Mint Account


RequestResult<ResponseValue<BlockHash>> blockHash = await RpcClient.GetRecentBlockHashAsync();

ulong minBalanceForExemptionAcc =
(await RpcClient.GetMinimumBalanceForRentExemptionAsync(TokenProgram.TokenAccountDataSize)).Result;
ulong minBalanceForExemptionMint =
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/Solana.Unity.Examples/HelloWorldExample.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 5 additions & 3 deletions src/Solana.Unity.Examples/InstructionDecoderExample.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 :)"))
Expand Down
Loading
Loading