Skip to content

Commit 4b0238f

Browse files
committed
Add decoder for address lookup tables
1 parent 417fd65 commit 4b0238f

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

api/spl/address_lookup_table.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package spl
2+
3+
import (
4+
bin "github.com/gagliardetto/binary"
5+
"github.com/gagliardetto/solana-go"
6+
)
7+
8+
type AddressLookupTableMeta struct {
9+
DeactivationSlot uint64
10+
LastExtendedSlot uint64
11+
LastExtendedSlotStartIndex uint8
12+
Authority []solana.PublicKey
13+
}
14+
15+
type AddressLookupTable struct {
16+
State uint32
17+
Meta AddressLookupTableMeta
18+
Addresses []solana.PublicKey
19+
}
20+
21+
func (inst *AddressLookupTable) UnmarshalWithDecoder(decoder *bin.Decoder) error {
22+
err := decoder.Decode(&inst.State)
23+
if err != nil {
24+
return err
25+
}
26+
err = decoder.Decode(&inst.Meta)
27+
if err != nil {
28+
return err
29+
}
30+
err = decoder.SetPosition(56)
31+
if err != nil {
32+
return err
33+
}
34+
for decoder.HasRemaining() {
35+
pub := &solana.PublicKey{}
36+
err = decoder.Decode(pub)
37+
if err != nil {
38+
return err
39+
}
40+
inst.Addresses = append(inst.Addresses, *pub)
41+
}
42+
return err
43+
}

0 commit comments

Comments
 (0)