Skip to content

Commit

Permalink
fix pointer issues with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Jan 18, 2024
1 parent d64603c commit b2d114e
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 181 deletions.
24 changes: 16 additions & 8 deletions block/fetcher/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,13 @@ func toPbTransactionMeta(meta *rpc.TransactionMeta) (*pbsol.TransactionStatusMet
PreBalances: meta.PreBalances,
PostBalances: meta.PostBalances,
InnerInstructions: innerInstructions,
InnerInstructionsNone: len(innerInstructions) == 0,
LogMessages: meta.LogMessages,
LogMessagesNone: len(meta.LogMessages) == 0,
PreTokenBalances: toPbTokenBalances(meta.PreTokenBalances),
PostTokenBalances: toPbTokenBalances(meta.PostTokenBalances),
Rewards: toPBReward(meta.Rewards),
LoadedWritableAddresses: toPbWritableAddresses(meta.LoadedAddresses.Writable),
LoadedReadonlyAddresses: toPbReadonlyAddresses(meta.LoadedAddresses.ReadOnly),
ReturnData: returnData,
ReturnDataNone: returnData == nil,
ComputeUnitsConsumed: meta.ComputeUnitsConsumed,
}, nil
}
Expand All @@ -285,15 +282,19 @@ func toPbReturnData(data rpc.ReturnData) (*pbsol.ReturnData, error) {
func toPbReadonlyAddresses(readonlyAddresses solana.PublicKeySlice) [][]byte {
var out [][]byte
for _, readonlyAddresse := range readonlyAddresses {
out = append(out, readonlyAddresse[:])
o := make([]byte, len(readonlyAddresse))
copy(o, readonlyAddresse[:])
out = append(out, o)
}
return out
}

func toPbWritableAddresses(writableAddresses solana.PublicKeySlice) [][]byte {
var out [][]byte
for _, writableAddresse := range writableAddresses {
out = append(out, writableAddresse[:])
o := make([]byte, len(writableAddresse))
copy(o, writableAddresse[:])
out = append(out, o)
}
return out
}
Expand Down Expand Up @@ -417,8 +418,11 @@ func toPbInstructions(instructions []solana.CompiledInstruction) []*pbsol.Compil

func toPbAddressTableLookups(addressTableLookups solana.MessageAddressTableLookupSlice) (out []*pbsol.MessageAddressTableLookup) {
for _, addressTableLookup := range addressTableLookups {
o := make([]byte, len(addressTableLookup.AccountKey))
copy(o, addressTableLookup.AccountKey[:])

out = append(out, &pbsol.MessageAddressTableLookup{
AccountKey: addressTableLookup.AccountKey[:],
AccountKey: o,
WritableIndexes: addressTableLookup.WritableIndexes,
ReadonlyIndexes: addressTableLookup.ReadonlyIndexes,
})
Expand All @@ -428,7 +432,8 @@ func toPbAddressTableLookups(addressTableLookups solana.MessageAddressTableLooku

func toPbAccountKeys(accountKeys []solana.PublicKey) (out [][]byte) {
for _, accountKey := range accountKeys {
a := accountKey[:]
a := make([]byte, len(accountKey))
copy(a, accountKey[:])
out = append(out, a)
}
return
Expand All @@ -444,7 +449,10 @@ func toPbMessageHeader(header solana.MessageHeader) *pbsol.MessageHeader {

func toPbSignatures(signatures []solana.Signature) (out [][]byte) {
for _, signature := range signatures {
out = append(out, signature[:])
s := make([]byte, len(signature))
copy(s, signature[:])

out = append(out, s)
}
return
}
Expand Down
17 changes: 17 additions & 0 deletions block/fetcher/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"
"time"

"github.com/gagliardetto/solana-go"

"github.com/gagliardetto/solana-go/rpc"
"github.com/gagliardetto/solana-go/rpc/jsonrpc"
bin "github.com/streamingfast/binary"
Expand Down Expand Up @@ -175,3 +177,18 @@ func Test_InstructionEncode(t *testing.T) {
})
}
}

func Test_toPbAccountKeys(t *testing.T) {
accounts := []solana.PublicKey{
solana.MustPublicKeyFromBase58("EXsJCamTqHJqRqNaB4ZAszGpFw6psMsk9HfjkrrWwJBc"),
solana.MustPublicKeyFromBase58("8F1yhZvTwrFq5SqJ5PH2VLRRwULUGYHju84FjMtDbJPJ"),
solana.MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111"),
}
pbAccounts := toPbAccountKeys(accounts)
expected := [][]byte{
accounts[0][:],
accounts[1][:],
accounts[2][:],
}
require.Equal(t, expected, pbAccounts)
}
6 changes: 3 additions & 3 deletions pb/last_generate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
generate.sh - Mon 31 Jul 2023 14:45:22 EDT - julien
streamingfast/proto revision: c72d870e1203d70e95230b781cff0b5ac40372e8
streamingfast/firehose-solana/proto revision: 5d11c69
generate.sh - Thu Jan 18 11:02:06 EST 2024 - cbillett
streamingfast/proto revision: 132ddccba854a771dab14d874c5ae488e7f812c8
streamingfast/firehose-solana/proto revision: d5ebed8
Loading

0 comments on commit b2d114e

Please sign in to comment.