Skip to content

Commit 78c2b46

Browse files
committed
refactor: move systemProgram-related typedefs to systemProgram pkg
1 parent 3e1209c commit 78c2b46

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

solana/parser_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func TestSystemProgramTransfer(t *testing.T) {
233233
}
234234
results, _ := Parser(byteValue)
235235
action := results[0].Actions[1]
236-
if transferAction, ok := action.(*types.SystemProgramTransferAction); ok {
236+
if transferAction, ok := action.(*systemProgram.TransferAction); ok {
237237
assert.Equal(t, transferAction.ProgramID, systemProgram.Program)
238238
assert.Equal(t, transferAction.ProgramName, systemProgram.ProgramName)
239239
assert.Equal(t, transferAction.InstructionName, "Transfer")
@@ -252,7 +252,7 @@ func TestSystemProgramCreateAccountWithSeed(t *testing.T) {
252252
}
253253
results, _ := Parser(byteValue)
254254
action := results[0].Actions[2]
255-
if transferAction, ok := action.(*types.SystemProgramCreateAccountWithSeedAction); ok {
255+
if transferAction, ok := action.(*systemProgram.CreateAccountWithSeedAction); ok {
256256
assert.Equal(t, transferAction.ProgramID, systemProgram.Program)
257257
assert.Equal(t, transferAction.ProgramName, systemProgram.ProgramName)
258258
assert.Equal(t, transferAction.InstructionName, "CreateAccountWithSeed")

solana/programs/OKXDEXAggregationRouterV2/parsers/commissionSolSwapParser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func CommissionSolSwap2Parser(result *types.ParsedResult, instruction types.Inst
5252
continue
5353
}
5454
switch p := parsedData.(type) {
55-
case *types.SystemProgramTransferAction:
55+
case *systemProgram.TransferAction:
5656
if p.From == fromTokenAccount {
5757
fromTokenAmount += p.Lamports
5858
}

solana/programs/OKXDEXAggregationRouterV2/parsers/commissionSplProxySwap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func CommissionSplProxySwapParser(result *types.ParsedResult, instruction types.
5252
continue
5353
}
5454
switch p := parsedData.(type) {
55-
case *types.SystemProgramTransferAction:
55+
case *systemProgram.TransferAction:
5656
if p.From == fromTokenAccount {
5757
fromTokenAmount += p.Lamports
5858
}

solana/programs/OKXDEXAggregationRouterV2/parsers/swap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func SwapParser(result *types.ParsedResult, instruction types.Instruction, decod
4646
continue
4747
}
4848
switch p := parsedData.(type) {
49-
case *types.SystemProgramTransferAction:
49+
case *systemProgram.TransferAction:
5050
if p.To == toTokenAccount {
5151
toTokenAmount += p.Lamports
5252
}

solana/programs/jupiterAggregatorV6/parsers/route.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func RouteParser(result *types.ParsedResult, instruction types.Instruction) (*ty
5151
continue
5252
}
5353
switch p := parsedData.(type) {
54-
case *types.SystemProgramTransferAction:
54+
case *systemProgram.TransferAction:
5555
if p.From == fromTokenAccount {
5656
fromTokenAmount += p.Lamports
5757
}

solana/programs/jupiterAggregatorV6/parsers/sharedAccountsRoute.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func SharedAccountsRouteParser(result *types.ParsedResult, instruction types.Ins
4444
continue
4545
}
4646
switch p := parsedData.(type) {
47-
case *types.SystemProgramTransferAction:
47+
case *systemProgram.TransferAction:
4848
if p.From == fromTokenAccount {
4949
fromTokenAmount += p.Lamports
5050
}

solana/programs/systemProgram/parsers/createAccountWithSeed.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
solanago "github.com/gagliardetto/solana-go"
88
)
99

10-
func CreateAccountWithSeedParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*types.SystemProgramCreateAccountWithSeedAction, error) {
10+
func CreateAccountWithSeedParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*systemProgram.CreateAccountWithSeedAction, error) {
1111
basePubKey := solanago.PublicKeyFromBytes(decodedData[4:36])
1212
seedLength := binary.LittleEndian.Uint64(decodedData[36:44])
1313
seed := string(decodedData[44 : 44+seedLength])
1414
lamports := binary.LittleEndian.Uint64(decodedData[44+seedLength : 44+seedLength+8])
1515
space := binary.LittleEndian.Uint64(decodedData[44+seedLength+8 : 44+seedLength+16])
1616
ownerPubKey := solanago.PublicKeyFromBytes(decodedData[44+seedLength+16 : 44+seedLength+16+32])
1717

18-
action := types.SystemProgramCreateAccountWithSeedAction{
18+
action := systemProgram.CreateAccountWithSeedAction{
1919
BaseAction: types.BaseAction{
2020
ProgramID: result.AccountList[instruction.ProgramIDIndex],
2121
ProgramName: systemProgram.ProgramName,

solana/programs/systemProgram/parsers/transfer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ type TransferData struct {
1111
Lamports uint64
1212
}
1313

14-
func TransferParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*types.SystemProgramTransferAction, error) {
14+
func TransferParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*systemProgram.TransferAction, error) {
1515
var data TransferData
1616
err := borsh.Deserialize(&data, decodedData)
1717
if err != nil {
1818
return nil, err
1919
}
2020

21-
action := types.SystemProgramTransferAction{
21+
action := systemProgram.TransferAction{
2222
BaseAction: types.BaseAction{
2323
ProgramID: result.AccountList[instruction.ProgramIDIndex],
2424
ProgramName: systemProgram.ProgramName,

solana/types/systemProgramAction.go renamed to solana/programs/systemProgram/types.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
package types
1+
package systemProgram
22

3-
type SystemProgramTransferAction struct {
4-
BaseAction
3+
import "github.com/0xjeffro/tx-parser/solana/types"
4+
5+
type TransferAction struct {
6+
types.BaseAction
57
From string `json:"from"`
68
To string `json:"to"`
79
Lamports uint64 `json:"lamports"`
810
}
911

10-
type SystemProgramCreateAccountWithSeedAction struct {
11-
BaseAction
12+
type CreateAccountWithSeedAction struct {
13+
types.BaseAction
1214
Who string `json:"who"`
1315
NewAccount string `json:"newAccount"`
1416
Base string `json:"base"`

0 commit comments

Comments
 (0)