Closed DimaCantemir closed 2 years ago
could we get a bump on this @gagliardetto ?
Wait, I'm actually not sure what are you trying to do here.
Can you make an example of a scenario? (with data)
You had this function before:
func DataBytesOrJSONFromBase64(stringBase64 string) (*DataBytesOrJSON, error) {
decoded, err := base64.StdEncoding.DecodeString(stringBase64)
if err != nil {
return nil, err
}
return DataBytesOrJSONFromBase64Bytes(decoded)
}
but we are getting a stream of binary encoded Accounts from a Geyser plugin stream and we have the Data field of the Accounts already in a []byte format so to create a DataBytesOrJSON struct we need to encode the bytes into string and then you function above decodes it back. With our PR we introduce a way to avoid this encode decode nonsense and create a DataBytesOrJSON struct directly from a slice of bytes
Which is it:
A) You have plain account binary data (not base64/base58/json encoded).
B) You have account data that's base64-encoded, BUT it's not a string but bytes.
B)
In that case, your PR content won't solve your problem.
Can't you just DataBytesOrJSONFromBase64(string(encodedData))
?
in fact let me give you what you asked for - an example. Here's our code:
dataB64 := base64.StdEncoding.EncodeToString(response.Data)
db, err := solanarpc.DataBytesOrJSONFromBase64(dataB64)
if err != nil {
return nil, fmt.Errorf("could not parse data: %w", err)
}
keyedAccount := &solanarpc.KeyedAccount{
Pubkey: pk,
Account: &solanarpc.Account{
Lamports: response.Lamports,
Owner: ownerPk,
Data: db,
Executable: response.Executable,
RentEpoch: response.RentEpoch,
},
}
In that case you have the A case, and need to create a DataBytesOrJSON
. I see.
this last push should do it. thanks for your time and this package overall
LGTM, just need to address the couple above naming changes.
Done
Still missing the change in the comment.
If you go to the "Files changed" tab, you can commit suggestions directly.
Done. When you merge this could you please tag a new release ? our devOps people are itching to run some performance tests after we integrate this change
No release is scheduled for today.
You can use the latest source with your changes by go get github.com/gagliardetto/solana-go@8bd6977469ecb5bbd8a27488648b82bd1904f5fe
added ability to create DataBytesOrJSON struct directly from base64 bytes. Useful when you receive an account though alternative channels, like Geyser plugin + graph protocol, and need to reconstruct it with as little overhead as possible