@@ -149,14 +149,14 @@ func (c *Client) request(query string, variables map[string]any, queryName strin
149149// -- Queries --
150150
151151// GetSyncStatus returns the node's sync status.
152- // Returns one of: CONNECTING, LISTENING, OFFLINE, BOOTSTRAP, SYNCED, CATCHUP .
153- func (c * Client ) GetSyncStatus () (string , error ) {
152+ // Returns one of the SyncStatus constants (SyncStatusSynced, SyncStatusBootstrap, ...) .
153+ func (c * Client ) GetSyncStatus () (SyncStatus , error ) {
154154 data , err := c .request (querySyncStatus , nil , "get_sync_status" )
155155 if err != nil {
156156 return "" , err
157157 }
158158 var result struct {
159- SyncStatus string `json:"syncStatus"`
159+ SyncStatus SyncStatus `json:"syncStatus"`
160160 }
161161 if err := json .Unmarshal (data , & result ); err != nil {
162162 return "" , err
@@ -172,12 +172,12 @@ func (c *Client) GetDaemonStatus() (*DaemonStatus, error) {
172172 }
173173 var result struct {
174174 DaemonStatus struct {
175- SyncStatus string `json:"syncStatus"`
176- BlockchainLength * int `json:"blockchainLength"`
177- HighestBlockLengthReceived * int `json:"highestBlockLengthReceived"`
178- UptimeSecs * int `json:"uptimeSecs"`
179- StateHash string `json:"stateHash"`
180- CommitID string `json:"commitId"`
175+ SyncStatus SyncStatus `json:"syncStatus"`
176+ BlockchainLength * int `json:"blockchainLength"`
177+ HighestBlockLengthReceived * int `json:"highestBlockLengthReceived"`
178+ UptimeSecs * int `json:"uptimeSecs"`
179+ StateHash string `json:"stateHash"`
180+ CommitID string `json:"commitId"`
181181 Peers []struct {
182182 PeerID string `json:"peerId"`
183183 Host string `json:"host"`
@@ -224,13 +224,15 @@ func (c *Client) GetNetworkID() (string, error) {
224224// GetAccount returns account data for a public key.
225225// Pass an empty tokenID to use the default MINA token.
226226func (c * Client ) GetAccount (publicKey , tokenID string ) (* AccountData , error ) {
227- var data json.RawMessage
228- var err error
227+ // tokenID is optional: a non-empty value scopes the query to that token,
228+ // while leaving it unset omits the $token variable so the daemon resolves
229+ // the default MINA token. A single query serves both cases.
230+ vars := map [string ]any {"publicKey" : publicKey }
229231 if tokenID != "" {
230- data , err = c .request (queryGetAccountWithToken , map [string ]any {"publicKey" : publicKey , "token" : tokenID }, "get_account" )
231- } else {
232- data , err = c .request (queryGetAccount , map [string ]any {"publicKey" : publicKey }, "get_account" )
232+ vars ["token" ] = tokenID
233233 }
234+
235+ data , err := c .request (queryGetAccount , vars , "get_account" )
234236 if err != nil {
235237 return nil , err
236238 }
@@ -290,6 +292,7 @@ func (c *Client) GetAccount(publicKey, tokenID string) (*AccountData, error) {
290292// GetBestChain returns blocks from the best chain.
291293// Pass 0 for maxLength to use the daemon's default.
292294func (c * Client ) GetBestChain (maxLength int ) ([]BlockInfo , error ) {
295+ // maxLength <= 0 omits the argument, letting the daemon apply its default.
293296 var vars map [string ]any
294297 if maxLength > 0 {
295298 vars = map [string ]any {"maxLength" : maxLength }
@@ -305,7 +308,7 @@ func (c *Client) GetBestChain(maxLength int) ([]BlockInfo, error) {
305308 StateHash string `json:"stateHash"`
306309 CommandTransactionCount int `json:"commandTransactionCount"`
307310 CreatorAccount struct {
308- PublicKey any `json:"publicKey"`
311+ PublicKey string `json:"publicKey"`
309312 } `json:"creatorAccount"`
310313 ProtocolState struct {
311314 ConsensusState struct {
@@ -329,9 +332,11 @@ func (c *Client) GetBestChain(maxLength int) ([]BlockInfo, error) {
329332 slotGenesis , _ := strconv .Atoi (b .ProtocolState .ConsensusState .SlotSinceGenesis )
330333 slotFork , _ := strconv .Atoi (b .ProtocolState .ConsensusState .Slot )
331334
332- creatorPK := "unknown"
333- if v , ok := b .CreatorAccount .PublicKey .(string ); ok {
334- creatorPK = v
335+ // The daemon may omit the creator public key (e.g. for the genesis
336+ // block); fall back to a sentinel so callers get a stable value.
337+ creatorPK := b .CreatorAccount .PublicKey
338+ if creatorPK == "" {
339+ creatorPK = "unknown"
335340 }
336341
337342 blocks [i ] = BlockInfo {
@@ -372,13 +377,15 @@ func (c *Client) GetPeers() ([]PeerInfo, error) {
372377// GetPooledUserCommands returns pending user commands from the transaction pool.
373378// Pass an empty publicKey to get all pending commands.
374379func (c * Client ) GetPooledUserCommands (publicKey string ) ([]PooledUserCommand , error ) {
375- var data json.RawMessage
376- var err error
380+ // publicKey is optional: a non-empty value filters to that sender, while
381+ // leaving it unset omits the $publicKey variable so the daemon returns
382+ // every pending command. A single query serves both cases.
383+ vars := map [string ]any {}
377384 if publicKey != "" {
378- data , err = c .request (queryPooledUserCommands , map [string ]any {"publicKey" : publicKey }, "get_pooled_user_commands" )
379- } else {
380- data , err = c .request (queryPooledUserCommandsAll , nil , "get_pooled_user_commands" )
385+ vars ["publicKey" ] = publicKey
381386 }
387+
388+ data , err := c .request (queryPooledUserCommands , vars , "get_pooled_user_commands" )
382389 if err != nil {
383390 return nil , err
384391 }
@@ -423,6 +430,9 @@ func (c *Client) SendPayment(params SendPaymentParams) (*SendPaymentResult, erro
423430 "amount" : params .Amount .NanominaString (),
424431 "fee" : params .Fee .NanominaString (),
425432 }
433+
434+ // Memo and Nonce are optional: a zero memo and a nil nonce are simply
435+ // omitted, letting the daemon assign the next nonce.
426436 if params .Memo != "" {
427437 input ["memo" ] = params .Memo
428438 }
@@ -508,6 +518,8 @@ func (c *Client) SendDelegation(params SendDelegationParams) (*SendDelegationRes
508518// Pass an empty string to disable the SNARK worker.
509519// Returns the previous snark worker public key (empty if none).
510520func (c * Client ) SetSnarkWorker (publicKey string ) (string , error ) {
521+ // A non-empty publicKey sets the SNARK worker; an empty string sends a
522+ // null input, which unsets it.
511523 var input any
512524 if publicKey != "" {
513525 input = publicKey
0 commit comments