Upgrade github.com/gagliardetto/binary to v0.5.1

This commit is contained in:
gagliardetto 2022-01-05 17:56:05 +01:00
parent 1ff3e1e5ec
commit 73311b0b87
7 changed files with 27 additions and 54 deletions

2
go.mod
View File

@ -17,7 +17,7 @@ require (
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1
github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70
github.com/fatih/color v1.7.0 github.com/fatih/color v1.7.0
github.com/gagliardetto/binary v0.5.0 github.com/gagliardetto/binary v0.5.1
github.com/gagliardetto/gofuzz v1.2.2 github.com/gagliardetto/gofuzz v1.2.2
github.com/gagliardetto/treeout v0.1.4 github.com/gagliardetto/treeout v0.1.4
github.com/google/go-cmp v0.5.1 github.com/google/go-cmp v0.5.1

4
go.sum
View File

@ -89,8 +89,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gagliardetto/binary v0.5.0 h1:fLVIbMEQp5zbW0SFtg0z/WHy2iUw/SMeuakzfa5ayhI= github.com/gagliardetto/binary v0.5.1 h1:iNEy3p7r/DK352CRO7pp+3zNITGZKk8hwkH3BpaGFeo=
github.com/gagliardetto/binary v0.5.0/go.mod h1:peJR9PvwamL4YOh1nHWCPLry2VEfeeD1ADvewka7HnQ= github.com/gagliardetto/binary v0.5.1/go.mod h1:peJR9PvwamL4YOh1nHWCPLry2VEfeeD1ADvewka7HnQ=
github.com/gagliardetto/gofuzz v1.2.2 h1:XL/8qDMzcgvR4+CyRQW9UGdwPRPMHVJfqQ/uMvSUuQw= github.com/gagliardetto/gofuzz v1.2.2 h1:XL/8qDMzcgvR4+CyRQW9UGdwPRPMHVJfqQ/uMvSUuQw=
github.com/gagliardetto/gofuzz v1.2.2/go.mod h1:bkH/3hYLZrMLbfYWA0pWzXmi5TTRZnu4pMGZBkqMKvY= github.com/gagliardetto/gofuzz v1.2.2/go.mod h1:bkH/3hYLZrMLbfYWA0pWzXmi5TTRZnu4pMGZBkqMKvY=
github.com/gagliardetto/treeout v0.1.4 h1:ozeYerrLCmCubo1TcIjFiOWTTGteOOHND1twdFpgwaw= github.com/gagliardetto/treeout v0.1.4 h1:ozeYerrLCmCubo1TcIjFiOWTTGteOOHND1twdFpgwaw=

View File

@ -177,11 +177,7 @@ func (inst AllocateWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) erro
} }
// Serialize `Seed` param: // Serialize `Seed` param:
{ {
err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian) err := encoder.WriteRustString(*inst.Seed)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.Seed), false)
if err != nil { if err != nil {
return err return err
} }
@ -213,15 +209,10 @@ func (inst *AllocateWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) e
} }
// Deserialize `Seed` param: // Deserialize `Seed` param:
{ {
length, err := decoder.ReadUint64(binary.LittleEndian) value, err := decoder.ReadRustString()
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.Seed = &value inst.Seed = &value
} }
// Deserialize `Space` param: // Deserialize `Space` param:

View File

@ -164,11 +164,7 @@ func (inst AssignWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) error
} }
// Serialize `Seed` param: // Serialize `Seed` param:
{ {
err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian) err := encoder.WriteRustString(*inst.Seed)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.Seed), false)
if err != nil { if err != nil {
return err return err
} }
@ -193,15 +189,10 @@ func (inst *AssignWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) err
} }
// Deserialize `Seed` param: // Deserialize `Seed` param:
{ {
length, err := decoder.ReadUint64(binary.LittleEndian) value, err := decoder.ReadRustString()
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.Seed = &value inst.Seed = &value
} }
// Deserialize `Owner` param: // Deserialize `Owner` param:

View File

@ -212,11 +212,7 @@ func (inst CreateAccountWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder)
} }
// Serialize `Seed` param: // Serialize `Seed` param:
{ {
err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian) err := encoder.WriteRustString(*inst.Seed)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.Seed), false)
if err != nil { if err != nil {
return err return err
} }
@ -255,15 +251,10 @@ func (inst *CreateAccountWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decod
} }
// Deserialize `Seed` param: // Deserialize `Seed` param:
{ {
length, err := decoder.ReadUint64(binary.LittleEndian) value, err := decoder.ReadRustString()
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.Seed = &value inst.Seed = &value
} }
// Deserialize `Lamports` param: // Deserialize `Lamports` param:

View File

@ -178,11 +178,7 @@ func (inst TransferWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) erro
} }
// Serialize `FromSeed` param: // Serialize `FromSeed` param:
{ {
err := encoder.WriteUint64(uint64(len(*inst.FromSeed)), binary.LittleEndian) err := encoder.WriteRustString(*inst.FromSeed)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.FromSeed), false)
if err != nil { if err != nil {
return err return err
} }
@ -207,15 +203,10 @@ func (inst *TransferWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) e
} }
// Deserialize `FromSeed` param: // Deserialize `FromSeed` param:
{ {
length, err := decoder.ReadUint64(binary.LittleEndian) value, err := decoder.ReadRustString()
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.FromSeed = &value inst.FromSeed = &value
} }
// Deserialize `FromOwner` param: // Deserialize `FromOwner` param:

View File

@ -4,19 +4,28 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/davecgh/go-spew/spew"
bin "github.com/gagliardetto/binary" bin "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestMint(t *testing.T) { func TestMint(t *testing.T) {
account := []byte{1, 0, 0, 0, 5, 234, 156, 241, 108, 228, 17, 152, 241, 164, 153, 55, 200, 140, 55, 10, 148, 212, 175, 255, 137, 181, 186, 203, 142, 244, 94, 99, 36, 187, 120, 247, 9, 169, 49, 235, 241, 182, 6, 0, 6, 1, 1, 0, 0, 0, 5, 234, 156, 241, 108, 228, 17, 152, 241, 164, 153, 55, 200, 140, 55, 10, 148, 212, 175, 255, 137, 181, 186, 203, 142, 244, 94, 99, 36, 187, 120, 247} account := []byte{
1, 0, 0, 0,
5, 234, 156, 241, 108, 228, 17, 152, 241, 164, 153, 55, 200, 140, 55, 10, 148, 212, 175, 255, 137, 181, 186, 203, 142, 244, 94, 99, 36, 187, 120, 247,
9, 169, 49, 235, 241, 182, 6, 0,
6,
1,
1, 0, 0, 0,
5, 234, 156, 241, 108, 228, 17, 152, 241, 164, 153, 55, 200, 140, 55, 10, 148, 212, 175, 255, 137, 181, 186, 203, 142, 244, 94, 99, 36, 187, 120, 247,
}
{ {
dec := bin.NewBorshDecoder(account) dec := bin.NewBinDecoder(account)
mint := new(Mint) mint := Mint{}
err := mint.UnmarshalWithDecoder(dec) err := dec.Decode(&mint)
require.NoError(t, err) require.NoError(t, err, spew.Sdump(mint))
require.Equal(t, require.Equal(t,
&Mint{ &Mint{
@ -26,12 +35,12 @@ func TestMint(t *testing.T) {
IsInitialized: true, IsInitialized: true,
FreezeAuthority: solana.MustPublicKeyFromBase58("Q6XprfkF8RQQKoQVG33xT88H7wi8Uk1B1CC7YAs69Gi").ToPointer(), FreezeAuthority: solana.MustPublicKeyFromBase58("Q6XprfkF8RQQKoQVG33xT88H7wi8Uk1B1CC7YAs69Gi").ToPointer(),
}, },
mint, &mint,
) )
{ {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
err := mint.MarshalWithEncoder(bin.NewBinEncoder(buf)) err := bin.NewBinEncoder(buf).Encode(mint)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, account, buf.Bytes()) require.Equal(t, account, buf.Bytes())
} }