Skip to content

Commit bf0cf12

Browse files
committed
♻️ TS&C# Unified Buffer & Component delegation instruction
1 parent 466b0b2 commit bf0cf12

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

clients/csharp/Solana.Unity.Bolt.Test/AccelerationTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public static async Task InitializePositionComponentOnAccelerationEntity(Framewo
4343

4444
public static async Task DelegateComponent(Framework framework) {
4545
var delegateComponent = await Bolt.World.DelegateComponent(framework.Wallet.Account.PublicKey, framework.AccelerationEntityPda, framework.ExampleComponentPosition);
46-
await framework.SendAndConfirmInstruction(delegateComponent.gTransaction);
47-
var delegateBuffer = await Bolt.World.DelegateBuffer();
46+
await framework.SendAndConfirmInstruction(delegateComponent.Instruction);
4847
}
4948

5049
public static async Task ApplySimpleMovementSystemOnAccelerator(Framework framework) {

clients/csharp/Solana.Unity.Bolt/WorldProgram/Bolt/DelegateComponent.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ public class DelegateComponentInstruction {
2020
}
2121

2222
public static async Task<DelegateComponentInstruction> DelegateComponent(PublicKey payer, PublicKey entity, PublicKey componentId, string seed = "") {
23-
var account = WorldProgram.FindComponentPda(componentId, entity, seed);
24-
var bufferPda = WorldProgram.FindBufferPda(account, componentId);
25-
var delegationRecord = WorldProgram.FindDelegationProgramPda("delegation", account);
26-
var delegationMetadata = WorldProgram.FindDelegationProgramPda("delegation-metadata", account);
23+
var componentPda = WorldProgram.FindComponentPda(componentId, entity, seed);
24+
var componentBuffer = WorldProgram.FindBufferPda(componentPda);
2725

28-
byte[] discriminator = new byte[] { 90, 147, 75, 178, 85, 88, 4, 137 };
26+
var componentDelegationRecord = WorldProgram.FindDelegationProgramPda("delegation", componentPda);
27+
var componentDelegationMetadata = WorldProgram.FindDelegationProgramPda("delegation-metadata", componentPda);
28+
29+
var worldProgram = new PublicKey(WorldProgram.ID);
30+
var bufferDelegationRecord = WorldProgram.FindDelegationProgramPda("delegation", componentBuffer);
31+
var bufferDelegationMetadata = WorldProgram.FindDelegationProgramPda("delegation-metadata", componentBuffer);
32+
var bufferBuffer = WorldProgram.FindBufferPda(componentBuffer, worldProgram);
33+
34+
byte[] discriminator = new byte[] { 191, 212, 179, 193, 178, 94, 119, 93 };
2935
uint commitFrequencyMs = 0;
3036
byte[] commitFrequencyBytes = BitConverter.GetBytes(commitFrequencyMs);
3137
if (!BitConverter.IsLittleEndian) Array.Reverse(commitFrequencyBytes);
@@ -38,22 +44,27 @@ public static async Task<DelegateComponentInstruction> DelegateComponent(PublicK
3844
Array.Copy(validator, 0, data, discriminator.Length + commitFrequencyBytes.Length, validator.Length);
3945

4046
TransactionInstruction instruction = new TransactionInstruction() {
41-
ProgramId = componentId,
47+
ProgramId = new PublicKey(WorldProgram.ID),
4248
Keys = new List<AccountMeta>() {
43-
AccountMeta.ReadOnly(payer, true),
44-
AccountMeta.ReadOnly(entity, false),
45-
AccountMeta.Writable(account, false),
49+
AccountMeta.Writable(payer, true),
50+
AccountMeta.Writable(componentPda, false),
51+
AccountMeta.Writable(componentBuffer, false),
4652
AccountMeta.ReadOnly(componentId, false),
47-
AccountMeta.Writable(bufferPda, false),
48-
AccountMeta.Writable(delegationRecord, false),
49-
AccountMeta.Writable(delegationMetadata, false),
53+
AccountMeta.Writable(WorldProgram.FindBufferPda(componentPda, componentId), false),
54+
AccountMeta.Writable(componentDelegationRecord, false),
55+
AccountMeta.Writable(componentDelegationMetadata, false),
5056
AccountMeta.ReadOnly(WorldProgram.DelegationProgram, false),
5157
AccountMeta.ReadOnly(SystemProgram.ProgramIdKey, false),
58+
AccountMeta.ReadOnly(entity, false),
59+
AccountMeta.ReadOnly(worldProgram, false),
60+
AccountMeta.Writable(bufferBuffer, false),
61+
AccountMeta.Writable(bufferDelegationRecord, false),
62+
AccountMeta.Writable(bufferDelegationMetadata, false),
5263
},
5364
Data = data,
5465
};
5566
return new DelegateComponentInstruction() {
56-
Pda = WorldProgram.FindDelegationProgramPda(seed, entity),
67+
Pda = componentPda,
5768
Instruction = instruction,
5869
};
5970
}

tests/script.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ sleep 5
88
echo "Running TypeScript tests..."
99
yarn run ts-mocha -p ./tsconfig.json -t 1000000 clients/typescript/test/main.ts
1010

11-
# echo "Running C# tests..."
12-
# cd clients/csharp/Solana.Unity.Bolt.Test
13-
# dotnet run --configuration Release
11+
echo "Running C# tests..."
12+
cd clients/csharp/Solana.Unity.Bolt.Test
13+
dotnet run --configuration Release
1414

1515
echo "Tests completed."

0 commit comments

Comments
 (0)