fix entry parse
This commit is contained in:
@@ -29,9 +29,8 @@ func (wr *wrapperReader) Skip(n int) error {
|
||||
func (wr *wrapperReader) ReadCompactU16() (uint16, error) {
|
||||
ln := 0
|
||||
size := 0
|
||||
|
||||
var buf [1]byte
|
||||
for i := 0; i < 3; i++ {
|
||||
var buf [1]byte
|
||||
_, err := io.ReadFull(wr, buf[:])
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("unable to decode compact u16 at %d: %w", i, err)
|
||||
@@ -61,11 +60,11 @@ func (wr *wrapperReader) ReadByte() (uint8, error) {
|
||||
return buf[0], nil
|
||||
}
|
||||
|
||||
func ResizeSlice[T any](slice []T, newSize int) {
|
||||
func ResizeSlice[T any](slice []T, newSize int) []T {
|
||||
if cap(slice) < newSize {
|
||||
slice = append(slice, make([]T, newSize-len(slice))...)
|
||||
}
|
||||
slice = slice[:newSize]
|
||||
return slice[:newSize]
|
||||
}
|
||||
|
||||
// entriesToVersionedTransaction converts raw entry bytes to versioned transactions.
|
||||
@@ -84,7 +83,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
// return nil, nil
|
||||
//}
|
||||
if entriesNum > 2048 {
|
||||
return fmt.Errorf("entries num is too large: %d > %d", entriesNum, 1024)
|
||||
return fmt.Errorf("entries num is too large: %d > %d", entriesNum, 2048)
|
||||
}
|
||||
|
||||
for i := uint64(0); i < entriesNum; i++ {
|
||||
@@ -113,7 +112,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
versioned := VersionedTransaction{}
|
||||
versioned.Block = slot
|
||||
versioned.Time = time.Now()
|
||||
ResizeSlice(versioned.Signatures, int(numSignatures))
|
||||
versioned.Signatures = ResizeSlice(versioned.Signatures, int(numSignatures))
|
||||
for k := 0; k < int(numSignatures); k++ {
|
||||
_, err = io.ReadFull(b, versioned.Signatures[k][:])
|
||||
if err != nil {
|
||||
@@ -151,7 +150,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
return fmt.Errorf("numAccountKeys %d exceeds maximum in entry %d, txn %d", numAccountKeys, i, j)
|
||||
}
|
||||
|
||||
ResizeSlice(versioned.StaticAccountKeys, int(numAccountKeys))
|
||||
versioned.StaticAccountKeys = ResizeSlice(versioned.StaticAccountKeys, int(numAccountKeys))
|
||||
|
||||
for k := 0; k < int(numAccountKeys); k++ {
|
||||
_, err = io.ReadFull(b, versioned.StaticAccountKeys[k][:])
|
||||
@@ -176,7 +175,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
if numInstructions >= 256 {
|
||||
return fmt.Errorf("numInstructions %d exceeds maximum in entry %d, txn %d, txHash: %s", numInstructions, i, j, versioned.GetSignature())
|
||||
}
|
||||
ResizeSlice(versioned.Instructions, int(numInstructions))
|
||||
versioned.Instructions = ResizeSlice(versioned.Instructions, int(numInstructions))
|
||||
for k := 0; k < int(numInstructions); k++ {
|
||||
versioned.Instructions[k].ProgramIDIndex, err = b.ReadByte()
|
||||
if err != nil {
|
||||
@@ -191,7 +190,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
if numAccounts >= 256 {
|
||||
return fmt.Errorf("numAccounts %d exceeds maximum for ix[%d] in entry %d, txn %d", numAccounts, k, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.Instructions[k].Accounts, int(numAccounts))
|
||||
versioned.Instructions[k].Accounts = ResizeSlice(versioned.Instructions[k].Accounts, int(numAccounts))
|
||||
|
||||
//.AccountsLen = int(numAccounts)
|
||||
if numAccounts != 0 {
|
||||
@@ -208,7 +207,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
if dataLen > 2048 {
|
||||
return fmt.Errorf("mx.Instructions[%d].Data length %d exceeds maximum in entry %d, txn %d, txHash: %s", k, dataLen, i, j, versioned.GetSignature())
|
||||
}
|
||||
ResizeSlice(versioned.Instructions[k].Accounts, int(numAccounts))
|
||||
versioned.Instructions[k].Data = ResizeSlice(versioned.Instructions[k].Data, int(dataLen))
|
||||
if dataLen > 0 {
|
||||
_, err = io.ReadFull(b, versioned.Instructions[k].Data)
|
||||
if err != nil {
|
||||
@@ -226,7 +225,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
if numLookups >= 32 {
|
||||
return fmt.Errorf("numLookups %d exceeds maximum in entry %d, txn %d", numLookups, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.AddressTableLookups, int(numLookups))
|
||||
versioned.AddressTableLookups = ResizeSlice(versioned.AddressTableLookups, int(numLookups))
|
||||
for k := uint8(0); k < numLookups; k++ {
|
||||
_, err = io.ReadFull(b, versioned.AddressTableLookups[k].AccountKey[:])
|
||||
if err != nil {
|
||||
@@ -240,7 +239,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
if numWritable >= 256 {
|
||||
return fmt.Errorf("numWritableIndexes %d exceeds maximum for lookup[%d] in entry %d, txn %d", numWritable, k, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.AddressTableLookups[k].WritableIndexes, int(numWritable))
|
||||
versioned.AddressTableLookups[k].WritableIndexes = ResizeSlice(versioned.AddressTableLookups[k].WritableIndexes, int(numWritable))
|
||||
if numWritable > 0 {
|
||||
_, err = io.ReadFull(b, versioned.AddressTableLookups[k].WritableIndexes)
|
||||
if err != nil {
|
||||
@@ -256,7 +255,7 @@ func entriesToVersionedTransaction(slot uint64, data io.Reader, callback func(tx
|
||||
if numReadonly > 256 {
|
||||
return fmt.Errorf("numReadonlyIndexes %d exceeds maximum for lookup[%d] in entry %d, txn %d", numReadonly, k, i, j)
|
||||
}
|
||||
ResizeSlice(versioned.AddressTableLookups[k].ReadonlyIndexes, int(numReadonly))
|
||||
versioned.AddressTableLookups[k].ReadonlyIndexes = ResizeSlice(versioned.AddressTableLookups[k].ReadonlyIndexes, int(numReadonly))
|
||||
if numReadonly > 0 {
|
||||
_, err = io.ReadFull(b, versioned.AddressTableLookups[k].ReadonlyIndexes)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user