From 9497cc7d6b61821d6c4276b6856096aa24552c55 Mon Sep 17 00:00:00 2001 From: Hunter Date: Fri, 29 Nov 2024 10:18:40 +0800 Subject: [PATCH] Add field to the accountInfo struct and correct the WebSocket accountInfo definition --- rpc/client_test.go | 4 ++-- rpc/types.go | 3 +++ rpc/ws/accountSubscribe.go | 6 ++---- rpc/ws/client_test.go | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rpc/client_test.go b/rpc/client_test.go index 33c08b17..ff65c26e 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -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) @@ -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) diff --git a/rpc/types.go b/rpc/types.go index 0de139ca..95fd37ac 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -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 { diff --git a/rpc/ws/accountSubscribe.go b/rpc/ws/accountSubscribe.go index 5e65d3a2..fb8577a1 100644 --- a/rpc/ws/accountSubscribe.go +++ b/rpc/ws/accountSubscribe.go @@ -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 diff --git a/rpc/ws/client_test.go b/rpc/ws/client_test.go index 91490441..a3379369 100644 --- a/rpc/ws/client_test.go +++ b/rpc/ws/client_test.go @@ -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 } @@ -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) {