Skip to content

Commit

Permalink
Add field to the accountInfo struct and correct the WebSocket account…
Browse files Browse the repository at this point in the history
…Info definition
  • Loading branch information
Hunter committed Nov 29, 2024
1 parent da21930 commit 9497cc7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2744,7 +2744,7 @@ func TestClient_GetTokenAccountBalance(t *testing.T) {
}

func TestClient_GetTokenAccountsByDelegate(t *testing.T) {
responseBody := `{"context":{"slot":1114},"value":[{"account":{"data":{"program":"spl-token","parsed":{"accountType":"account","info":{"tokenAmount":{"amount":"1","decimals":1,"uiAmount":0.1,"uiAmountString":"0.1"},"delegate":"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T","delegatedAmount":1,"isInitialized":true,"isNative":false,"mint":"3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E","owner":"CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"}}},"executable":false,"lamports":1726080,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":4},"pubkey":"CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"}]}`
responseBody := `{"context":{"slot":1114},"value":[{"account":{"data":{"program":"spl-token","parsed":{"accountType":"account","info":{"tokenAmount":{"amount":"1","decimals":1,"uiAmount":0.1,"uiAmountString":"0.1"},"delegate":"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T","delegatedAmount":1,"isInitialized":true,"isNative":false,"mint":"3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E","owner":"CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"}}},"executable":false,"lamports":1726080,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":4,"space":0},"pubkey":"CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
client := New(server.URL)
Expand Down Expand Up @@ -2800,7 +2800,7 @@ func TestClient_GetTokenAccountsByDelegate(t *testing.T) {
}

func TestClient_GetTokenAccountsByOwner(t *testing.T) {
responseBody := `{"context":{"slot":1114},"value":[{"account":{"data":{"program":"spl-token","parsed":{"accountType":"account","info":{"tokenAmount":{"amount":"1","decimals":1,"uiAmount":0.1,"uiAmountString":"0.1"},"delegate":null,"delegatedAmount":1,"isInitialized":true,"isNative":false,"mint":"3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E","owner":"4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F"}}},"executable":false,"lamports":1726080,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":4},"pubkey":"CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"}]}`
responseBody := `{"context":{"slot":1114},"value":[{"account":{"data":{"program":"spl-token","parsed":{"accountType":"account","info":{"tokenAmount":{"amount":"1","decimals":1,"uiAmount":0.1,"uiAmountString":"0.1"},"delegate":null,"delegatedAmount":1,"isInitialized":true,"isNative":false,"mint":"3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E","owner":"4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F"}}},"executable":false,"lamports":1726080,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":4,"space":0},"pubkey":"CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
client := New(server.URL)
Expand Down
3 changes: 3 additions & 0 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ type Account struct {

// The epoch at which this account will next owe rent
RentEpoch *big.Int `json:"rentEpoch"`

// The amount of storage space required to store the token account
Space uint64 `json:"space"`
}

type DataBytesOrJSON struct {
Expand Down
6 changes: 2 additions & 4 deletions rpc/ws/accountSubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import (

type AccountResult struct {
Context struct {
Slot uint64
Slot uint64 `json:"slot"`
} `json:"context"`
Value struct {
rpc.Account
} `json:"value"`
Value *rpc.Account `json:"value"`
}

// AccountSubscribe subscribes to an account to receive notifications
Expand Down
8 changes: 4 additions & 4 deletions rpc/ws/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func Test_AccountSubscribe(t *testing.T) {
return
}
text.NewEncoder(os.Stdout).Encode(data, nil)
fmt.Println("OpenOrders: ", data.Value.Account.Owner)
fmt.Println("data: ", data.Value.Account.Data)
fmt.Println("OpenOrders: ", data.Value.Owner)
fmt.Println("data: ", data.Value.Data)
return
}

Expand Down Expand Up @@ -107,8 +107,8 @@ func Test_AccountSubscribeWithHttpHeader(t *testing.T) {
t.Errorf("encoding error: %v", err)
}

t.Log("OpenOrders: ", data.Value.Account.Owner)
t.Log("data: ", data.Value.Account.Data)
t.Log("OpenOrders: ", data.Value.Owner)
t.Log("data: ", data.Value.Data)
}

func Test_ProgramSubscribe(t *testing.T) {
Expand Down

0 comments on commit 9497cc7

Please sign in to comment.