From 843d863a52562739a20dbfba59e082c55365dd4a Mon Sep 17 00:00:00 2001 From: gagliardetto Date: Fri, 24 Dec 2021 14:55:23 +0100 Subject: [PATCH] Fix string len encoding --- programs/system/AllocateWithSeed.go | 14 ++++++++++++-- programs/system/AssignWithSeed.go | 14 ++++++++++++-- programs/system/CreateAccountWithSeed.go | 14 ++++++++++++-- programs/system/TransferWithSeed.go | 14 ++++++++++++-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/programs/system/AllocateWithSeed.go b/programs/system/AllocateWithSeed.go index 5a4cba0..86d05d3 100644 --- a/programs/system/AllocateWithSeed.go +++ b/programs/system/AllocateWithSeed.go @@ -177,7 +177,11 @@ func (inst AllocateWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) erro } // Serialize `Seed` param: { - err := encoder.Encode(*inst.Seed) + err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian) + if err != nil { + return err + } + err = encoder.WriteBytes([]byte(*inst.Seed), false) if err != nil { return err } @@ -209,10 +213,16 @@ func (inst *AllocateWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) e } // Deserialize `Seed` param: { - err := decoder.Decode(&inst.Seed) + length, err := decoder.ReadUint64(binary.LittleEndian) if err != nil { return err } + bytes, err := decoder.ReadNBytes(int(length)) + if err != nil { + return err + } + value := string(bytes) + inst.Seed = &value } // Deserialize `Space` param: { diff --git a/programs/system/AssignWithSeed.go b/programs/system/AssignWithSeed.go index 6dafdc6..76b2860 100644 --- a/programs/system/AssignWithSeed.go +++ b/programs/system/AssignWithSeed.go @@ -164,7 +164,11 @@ func (inst AssignWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) error } // Serialize `Seed` param: { - err := encoder.Encode(*inst.Seed) + err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian) + if err != nil { + return err + } + err = encoder.WriteBytes([]byte(*inst.Seed), false) if err != nil { return err } @@ -189,10 +193,16 @@ func (inst *AssignWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) err } // Deserialize `Seed` param: { - err := decoder.Decode(&inst.Seed) + length, err := decoder.ReadUint64(binary.LittleEndian) if err != nil { return err } + bytes, err := decoder.ReadNBytes(int(length)) + if err != nil { + return err + } + value := string(bytes) + inst.Seed = &value } // Deserialize `Owner` param: { diff --git a/programs/system/CreateAccountWithSeed.go b/programs/system/CreateAccountWithSeed.go index e3700f3..b11ef62 100644 --- a/programs/system/CreateAccountWithSeed.go +++ b/programs/system/CreateAccountWithSeed.go @@ -212,7 +212,11 @@ func (inst CreateAccountWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) } // Serialize `Seed` param: { - err := encoder.Encode(*inst.Seed) + err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian) + if err != nil { + return err + } + err = encoder.WriteBytes([]byte(*inst.Seed), false) if err != nil { return err } @@ -251,10 +255,16 @@ func (inst *CreateAccountWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decod } // Deserialize `Seed` param: { - err := decoder.Decode(&inst.Seed) + length, err := decoder.ReadUint64(binary.LittleEndian) if err != nil { return err } + bytes, err := decoder.ReadNBytes(int(length)) + if err != nil { + return err + } + value := string(bytes) + inst.Seed = &value } // Deserialize `Lamports` param: { diff --git a/programs/system/TransferWithSeed.go b/programs/system/TransferWithSeed.go index 9102c84..5c23b9c 100644 --- a/programs/system/TransferWithSeed.go +++ b/programs/system/TransferWithSeed.go @@ -178,7 +178,11 @@ func (inst TransferWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) erro } // Serialize `FromSeed` param: { - err := encoder.Encode(*inst.FromSeed) + err := encoder.WriteUint64(uint64(len(*inst.FromSeed)), binary.LittleEndian) + if err != nil { + return err + } + err = encoder.WriteBytes([]byte(*inst.FromSeed), false) if err != nil { return err } @@ -203,10 +207,16 @@ func (inst *TransferWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) e } // Deserialize `FromSeed` param: { - err := decoder.Decode(&inst.FromSeed) + length, err := decoder.ReadUint64(binary.LittleEndian) if err != nil { return err } + bytes, err := decoder.ReadNBytes(int(length)) + if err != nil { + return err + } + value := string(bytes) + inst.FromSeed = &value } // Deserialize `FromOwner` param: {