Просмотр исходного кода

Encode seeds with u64 string prefixes (#8)

Loris Leiva 1 год назад
Родитель
Сommit
dadadc18a2

+ 10 - 0
Cargo.lock

@@ -1944,6 +1944,15 @@ dependencies = [
  "serde_json",
 ]
 
+[[package]]
+name = "kaigan"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6dd100976df9dd59d0c3fecf6f9ad3f161a087374d1b2a77ebb4ad8920f11bb"
+dependencies = [
+ "borsh 0.10.3",
+]
+
 [[package]]
 name = "keccak"
 version = "0.1.5"
@@ -3168,6 +3177,7 @@ version = "0.1.0"
 dependencies = [
  "assert_matches",
  "borsh 0.10.3",
+ "kaigan",
  "num-derive 0.3.3",
  "num-traits",
  "serde",

+ 2 - 2
clients/js/src/generated/instructions/allocateWithSeed.ts

@@ -77,7 +77,7 @@ export function getAllocateWithSeedInstructionDataEncoder(): Encoder<AllocateWit
     getStructEncoder([
       ['discriminator', getU32Encoder()],
       ['base', getAddressEncoder()],
-      ['seed', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
+      ['seed', addEncoderSizePrefix(getUtf8Encoder(), getU64Encoder())],
       ['space', getU64Encoder()],
       ['programAddress', getAddressEncoder()],
     ]),
@@ -89,7 +89,7 @@ export function getAllocateWithSeedInstructionDataDecoder(): Decoder<AllocateWit
   return getStructDecoder([
     ['discriminator', getU32Decoder()],
     ['base', getAddressDecoder()],
-    ['seed', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
+    ['seed', addDecoderSizePrefix(getUtf8Decoder(), getU64Decoder())],
     ['space', getU64Decoder()],
     ['programAddress', getAddressDecoder()],
   ]);

+ 4 - 2
clients/js/src/generated/instructions/assignWithSeed.ts

@@ -28,6 +28,8 @@ import {
   getStructEncoder,
   getU32Decoder,
   getU32Encoder,
+  getU64Decoder,
+  getU64Encoder,
   getUtf8Decoder,
   getUtf8Encoder,
   transformEncoder,
@@ -73,7 +75,7 @@ export function getAssignWithSeedInstructionDataEncoder(): Encoder<AssignWithSee
     getStructEncoder([
       ['discriminator', getU32Encoder()],
       ['base', getAddressEncoder()],
-      ['seed', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
+      ['seed', addEncoderSizePrefix(getUtf8Encoder(), getU64Encoder())],
       ['programAddress', getAddressEncoder()],
     ]),
     (value) => ({ ...value, discriminator: 10 })
@@ -84,7 +86,7 @@ export function getAssignWithSeedInstructionDataDecoder(): Decoder<AssignWithSee
   return getStructDecoder([
     ['discriminator', getU32Decoder()],
     ['base', getAddressDecoder()],
-    ['seed', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
+    ['seed', addDecoderSizePrefix(getUtf8Decoder(), getU64Decoder())],
     ['programAddress', getAddressDecoder()],
   ]);
 }

+ 2 - 2
clients/js/src/generated/instructions/createAccountWithSeed.ts

@@ -85,7 +85,7 @@ export function getCreateAccountWithSeedInstructionDataEncoder(): Encoder<Create
     getStructEncoder([
       ['discriminator', getU32Encoder()],
       ['base', getAddressEncoder()],
-      ['seed', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
+      ['seed', addEncoderSizePrefix(getUtf8Encoder(), getU64Encoder())],
       ['amount', getU64Encoder()],
       ['space', getU64Encoder()],
       ['programAddress', getAddressEncoder()],
@@ -98,7 +98,7 @@ export function getCreateAccountWithSeedInstructionDataDecoder(): Decoder<Create
   return getStructDecoder([
     ['discriminator', getU32Decoder()],
     ['base', getAddressDecoder()],
-    ['seed', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
+    ['seed', addDecoderSizePrefix(getUtf8Decoder(), getU64Decoder())],
     ['amount', getU64Decoder()],
     ['space', getU64Decoder()],
     ['programAddress', getAddressDecoder()],

+ 2 - 2
clients/js/src/generated/instructions/transferSolWithSeed.ts

@@ -79,7 +79,7 @@ export function getTransferSolWithSeedInstructionDataEncoder(): Encoder<Transfer
     getStructEncoder([
       ['discriminator', getU32Encoder()],
       ['amount', getU64Encoder()],
-      ['fromSeed', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
+      ['fromSeed', addEncoderSizePrefix(getUtf8Encoder(), getU64Encoder())],
       ['fromOwner', getAddressEncoder()],
     ]),
     (value) => ({ ...value, discriminator: 11 })
@@ -90,7 +90,7 @@ export function getTransferSolWithSeedInstructionDataDecoder(): Decoder<Transfer
   return getStructDecoder([
     ['discriminator', getU32Decoder()],
     ['amount', getU64Decoder()],
-    ['fromSeed', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
+    ['fromSeed', addDecoderSizePrefix(getUtf8Decoder(), getU64Decoder())],
     ['fromOwner', getAddressDecoder()],
   ]);
 }

+ 1 - 0
clients/rust/Cargo.toml

@@ -11,6 +11,7 @@ serde = ["dep:serde", "dep:serde_with"]
 
 [dependencies]
 borsh = "^0.10"
+kaigan = "^0.2"
 num-derive = "^0.3"
 num-traits = "^0.2"
 serde = { version = "^1.0", features = ["derive"], optional = true }

+ 6 - 5
clients/rust/src/generated/instructions/allocate_with_seed.rs

@@ -7,6 +7,7 @@
 
 use borsh::BorshDeserialize;
 use borsh::BorshSerialize;
+use kaigan::types::U64PrefixString;
 use solana_program::pubkey::Pubkey;
 
 /// Accounts.
@@ -66,7 +67,7 @@ impl AllocateWithSeedInstructionData {
 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct AllocateWithSeedInstructionArgs {
     pub base: Pubkey,
-    pub seed: String,
+    pub seed: U64PrefixString,
     pub space: u64,
     pub program_address: Pubkey,
 }
@@ -82,7 +83,7 @@ pub struct AllocateWithSeedBuilder {
     new_account: Option<solana_program::pubkey::Pubkey>,
     base_account: Option<solana_program::pubkey::Pubkey>,
     base: Option<Pubkey>,
-    seed: Option<String>,
+    seed: Option<U64PrefixString>,
     space: Option<u64>,
     program_address: Option<Pubkey>,
     __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
@@ -108,7 +109,7 @@ impl AllocateWithSeedBuilder {
         self
     }
     #[inline(always)]
-    pub fn seed(&mut self, seed: String) -> &mut Self {
+    pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
         self.seed = Some(seed);
         self
     }
@@ -313,7 +314,7 @@ impl<'a, 'b> AllocateWithSeedCpiBuilder<'a, 'b> {
         self
     }
     #[inline(always)]
-    pub fn seed(&mut self, seed: String) -> &mut Self {
+    pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
         self.instruction.seed = Some(seed);
         self
     }
@@ -405,7 +406,7 @@ struct AllocateWithSeedCpiBuilderInstruction<'a, 'b> {
     new_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     base: Option<Pubkey>,
-    seed: Option<String>,
+    seed: Option<U64PrefixString>,
     space: Option<u64>,
     program_address: Option<Pubkey>,
     /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.

+ 6 - 5
clients/rust/src/generated/instructions/assign_with_seed.rs

@@ -7,6 +7,7 @@
 
 use borsh::BorshDeserialize;
 use borsh::BorshSerialize;
+use kaigan::types::U64PrefixString;
 use solana_program::pubkey::Pubkey;
 
 /// Accounts.
@@ -66,7 +67,7 @@ impl AssignWithSeedInstructionData {
 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct AssignWithSeedInstructionArgs {
     pub base: Pubkey,
-    pub seed: String,
+    pub seed: U64PrefixString,
     pub program_address: Pubkey,
 }
 
@@ -81,7 +82,7 @@ pub struct AssignWithSeedBuilder {
     account: Option<solana_program::pubkey::Pubkey>,
     base_account: Option<solana_program::pubkey::Pubkey>,
     base: Option<Pubkey>,
-    seed: Option<String>,
+    seed: Option<U64PrefixString>,
     program_address: Option<Pubkey>,
     __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
 }
@@ -106,7 +107,7 @@ impl AssignWithSeedBuilder {
         self
     }
     #[inline(always)]
-    pub fn seed(&mut self, seed: String) -> &mut Self {
+    pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
         self.seed = Some(seed);
         self
     }
@@ -304,7 +305,7 @@ impl<'a, 'b> AssignWithSeedCpiBuilder<'a, 'b> {
         self
     }
     #[inline(always)]
-    pub fn seed(&mut self, seed: String) -> &mut Self {
+    pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
         self.instruction.seed = Some(seed);
         self
     }
@@ -387,7 +388,7 @@ struct AssignWithSeedCpiBuilderInstruction<'a, 'b> {
     account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     base: Option<Pubkey>,
-    seed: Option<String>,
+    seed: Option<U64PrefixString>,
     program_address: Option<Pubkey>,
     /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
     __remaining_accounts: Vec<(

+ 6 - 5
clients/rust/src/generated/instructions/create_account_with_seed.rs

@@ -7,6 +7,7 @@
 
 use borsh::BorshDeserialize;
 use borsh::BorshSerialize;
+use kaigan::types::U64PrefixString;
 use solana_program::pubkey::Pubkey;
 
 /// Accounts.
@@ -73,7 +74,7 @@ impl CreateAccountWithSeedInstructionData {
 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct CreateAccountWithSeedInstructionArgs {
     pub base: Pubkey,
-    pub seed: String,
+    pub seed: U64PrefixString,
     pub amount: u64,
     pub space: u64,
     pub program_address: Pubkey,
@@ -92,7 +93,7 @@ pub struct CreateAccountWithSeedBuilder {
     new_account: Option<solana_program::pubkey::Pubkey>,
     base_account: Option<solana_program::pubkey::Pubkey>,
     base: Option<Pubkey>,
-    seed: Option<String>,
+    seed: Option<U64PrefixString>,
     amount: Option<u64>,
     space: Option<u64>,
     program_address: Option<Pubkey>,
@@ -124,7 +125,7 @@ impl CreateAccountWithSeedBuilder {
         self
     }
     #[inline(always)]
-    pub fn seed(&mut self, seed: String) -> &mut Self {
+    pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
         self.seed = Some(seed);
         self
     }
@@ -356,7 +357,7 @@ impl<'a, 'b> CreateAccountWithSeedCpiBuilder<'a, 'b> {
         self
     }
     #[inline(always)]
-    pub fn seed(&mut self, seed: String) -> &mut Self {
+    pub fn seed(&mut self, seed: U64PrefixString) -> &mut Self {
         self.instruction.seed = Some(seed);
         self
     }
@@ -457,7 +458,7 @@ struct CreateAccountWithSeedCpiBuilderInstruction<'a, 'b> {
     new_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     base: Option<Pubkey>,
-    seed: Option<String>,
+    seed: Option<U64PrefixString>,
     amount: Option<u64>,
     space: Option<u64>,
     program_address: Option<Pubkey>,

+ 6 - 5
clients/rust/src/generated/instructions/transfer_sol_with_seed.rs

@@ -7,6 +7,7 @@
 
 use borsh::BorshDeserialize;
 use borsh::BorshSerialize;
+use kaigan::types::U64PrefixString;
 use solana_program::pubkey::Pubkey;
 
 /// Accounts.
@@ -74,7 +75,7 @@ impl TransferSolWithSeedInstructionData {
 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct TransferSolWithSeedInstructionArgs {
     pub amount: u64,
-    pub from_seed: String,
+    pub from_seed: U64PrefixString,
     pub from_owner: Pubkey,
 }
 
@@ -91,7 +92,7 @@ pub struct TransferSolWithSeedBuilder {
     base_account: Option<solana_program::pubkey::Pubkey>,
     destination: Option<solana_program::pubkey::Pubkey>,
     amount: Option<u64>,
-    from_seed: Option<String>,
+    from_seed: Option<U64PrefixString>,
     from_owner: Option<Pubkey>,
     __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
 }
@@ -121,7 +122,7 @@ impl TransferSolWithSeedBuilder {
         self
     }
     #[inline(always)]
-    pub fn from_seed(&mut self, from_seed: String) -> &mut Self {
+    pub fn from_seed(&mut self, from_seed: U64PrefixString) -> &mut Self {
         self.from_seed = Some(from_seed);
         self
     }
@@ -339,7 +340,7 @@ impl<'a, 'b> TransferSolWithSeedCpiBuilder<'a, 'b> {
         self
     }
     #[inline(always)]
-    pub fn from_seed(&mut self, from_seed: String) -> &mut Self {
+    pub fn from_seed(&mut self, from_seed: U64PrefixString) -> &mut Self {
         self.instruction.from_seed = Some(from_seed);
         self
     }
@@ -432,7 +433,7 @@ struct TransferSolWithSeedCpiBuilderInstruction<'a, 'b> {
     base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     destination: Option<&'b solana_program::account_info::AccountInfo<'a>>,
     amount: Option<u64>,
-    from_seed: Option<String>,
+    from_seed: Option<U64PrefixString>,
     from_owner: Option<Pubkey>,
     /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
     __remaining_accounts: Vec<(

+ 4 - 4
program/idl.json

@@ -288,7 +288,7 @@
               "type": { "kind": "stringTypeNode", "encoding": "utf8" },
               "prefix": {
                 "kind": "numberTypeNode",
-                "format": "u32",
+                "format": "u64",
                 "endian": "le"
               }
             },
@@ -694,7 +694,7 @@
               "type": { "kind": "stringTypeNode", "encoding": "utf8" },
               "prefix": {
                 "kind": "numberTypeNode",
-                "format": "u32",
+                "format": "u64",
                 "endian": "le"
               }
             },
@@ -776,7 +776,7 @@
               "type": { "kind": "stringTypeNode", "encoding": "utf8" },
               "prefix": {
                 "kind": "numberTypeNode",
-                "format": "u32",
+                "format": "u64",
                 "endian": "le"
               }
             },
@@ -860,7 +860,7 @@
               "type": { "kind": "stringTypeNode", "encoding": "utf8" },
               "prefix": {
                 "kind": "numberTypeNode",
-                "format": "u32",
+                "format": "u64",
                 "endian": "le"
               }
             },