@@ -3,11 +3,17 @@ package client
33import (
44 "context"
55
6+ "github.com/blocto/solana-go-sdk/common"
67 "github.com/blocto/solana-go-sdk/program/token"
78 "github.com/blocto/solana-go-sdk/rpc"
89)
910
10- func (c * Client ) GetTokenAccountsByOwnerByMint (ctx context.Context , owner , mintAddr string ) ([]token.TokenAccount , error ) {
11+ type TokenAccount struct {
12+ token.TokenAccount
13+ PublicKey common.PublicKey
14+ }
15+
16+ func (c * Client ) GetTokenAccountsByOwnerByMint (ctx context.Context , owner , mintAddr string ) ([]TokenAccount , error ) {
1117 return process (
1218 func () (rpc.JsonRpcResponse [rpc.ValueWithContext [rpc.GetProgramAccounts ]], error ) {
1319 return c .RpcClient .GetTokenAccountsByOwnerWithConfig (
@@ -25,7 +31,7 @@ func (c *Client) GetTokenAccountsByOwnerByMint(ctx context.Context, owner, mintA
2531 )
2632}
2733
28- func (c * Client ) GetTokenAccountsByOwnerByProgram (ctx context.Context , owner , programId string ) ([]token. TokenAccount , error ) {
34+ func (c * Client ) GetTokenAccountsByOwnerByProgram (ctx context.Context , owner , programId string ) ([]TokenAccount , error ) {
2935 return process (
3036 func () (rpc.JsonRpcResponse [rpc.ValueWithContext [rpc.GetProgramAccounts ]], error ) {
3137 return c .RpcClient .GetTokenAccountsByOwnerWithConfig (
@@ -43,7 +49,7 @@ func (c *Client) GetTokenAccountsByOwnerByProgram(ctx context.Context, owner, pr
4349 )
4450}
4551
46- func (c * Client ) GetTokenAccountsByOwnerWithContextByMint (ctx context.Context , owner , mintAddr string ) (rpc.ValueWithContext [[]token. TokenAccount ], error ) {
52+ func (c * Client ) GetTokenAccountsByOwnerWithContextByMint (ctx context.Context , owner , mintAddr string ) (rpc.ValueWithContext [[]TokenAccount ], error ) {
4753 return process (
4854 func () (rpc.JsonRpcResponse [rpc.ValueWithContext [rpc.GetProgramAccounts ]], error ) {
4955 return c .RpcClient .GetTokenAccountsByOwnerWithConfig (
@@ -61,7 +67,7 @@ func (c *Client) GetTokenAccountsByOwnerWithContextByMint(ctx context.Context, o
6167 )
6268}
6369
64- func (c * Client ) GetTokenAccountsByOwnerWithContextByProgram (ctx context.Context , owner , programId string ) (rpc.ValueWithContext [[]token. TokenAccount ], error ) {
70+ func (c * Client ) GetTokenAccountsByOwnerWithContextByProgram (ctx context.Context , owner , programId string ) (rpc.ValueWithContext [[]TokenAccount ], error ) {
6571 return process (
6672 func () (rpc.JsonRpcResponse [rpc.ValueWithContext [rpc.GetProgramAccounts ]], error ) {
6773 return c .RpcClient .GetTokenAccountsByOwnerWithConfig (
@@ -79,8 +85,8 @@ func (c *Client) GetTokenAccountsByOwnerWithContextByProgram(ctx context.Context
7985 )
8086}
8187
82- func convertGetTokenAccountsByOwner (v rpc.ValueWithContext [rpc.GetProgramAccounts ]) ([]token. TokenAccount , error ) {
83- tokenAccounts := make ([]token. TokenAccount , 0 , len (v .Value ))
88+ func convertGetTokenAccountsByOwner (v rpc.ValueWithContext [rpc.GetProgramAccounts ]) ([]TokenAccount , error ) {
89+ tokenAccounts := make ([]TokenAccount , 0 , len (v .Value ))
8490 for _ , v := range v .Value {
8591 accountInfo , err := convertAccountInfo (v .Account )
8692 if err != nil {
@@ -90,17 +96,20 @@ func convertGetTokenAccountsByOwner(v rpc.ValueWithContext[rpc.GetProgramAccount
9096 if err != nil {
9197 return nil , err
9298 }
93- tokenAccounts = append (tokenAccounts , tokenAccount )
99+ tokenAccounts = append (tokenAccounts , TokenAccount {
100+ TokenAccount : tokenAccount ,
101+ PublicKey : common .PublicKeyFromString (v .Pubkey ),
102+ })
94103 }
95104 return tokenAccounts , nil
96105}
97106
98- func convertGetTokenAccountsByOwnerAndContext (v rpc.ValueWithContext [rpc.GetProgramAccounts ]) (rpc.ValueWithContext [[]token. TokenAccount ], error ) {
107+ func convertGetTokenAccountsByOwnerAndContext (v rpc.ValueWithContext [rpc.GetProgramAccounts ]) (rpc.ValueWithContext [[]TokenAccount ], error ) {
99108 tokenAccounts , err := convertGetTokenAccountsByOwner (v )
100109 if err != nil {
101- return rpc.ValueWithContext [[]token. TokenAccount ]{}, err
110+ return rpc.ValueWithContext [[]TokenAccount ]{}, err
102111 }
103- return rpc.ValueWithContext [[]token. TokenAccount ]{
112+ return rpc.ValueWithContext [[]TokenAccount ]{
104113 Context : v .Context ,
105114 Value : tokenAccounts ,
106115 }, nil
0 commit comments