From 826a29cc988f847476d119bd000bbeada11d81b4 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 19 Nov 2019 20:15:32 +0300 Subject: [PATCH] rpc: implement client-side getunspents --- pkg/rpc/doc.go | 1 + pkg/rpc/rpc.go | 12 ++++++++++++ pkg/rpc/types.go | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/pkg/rpc/doc.go b/pkg/rpc/doc.go index 57246e7ca..5ce0884ef 100644 --- a/pkg/rpc/doc.go +++ b/pkg/rpc/doc.go @@ -41,6 +41,7 @@ Supported methods getblock getaccountstate + getunspents invokescript invokefunction sendrawtransaction diff --git a/pkg/rpc/rpc.go b/pkg/rpc/rpc.go index fc5ba9c73..b14e6db55 100644 --- a/pkg/rpc/rpc.go +++ b/pkg/rpc/rpc.go @@ -39,6 +39,18 @@ func (c *Client) GetAccountState(address string) (*AccountStateResponse, error) return resp, nil } +// GetUnspents returns UTXOs for the given NEO account. +func (c *Client) GetUnspents(address string) (*UnspentResponse, error) { + var ( + params = newParams(address) + resp = &UnspentResponse{} + ) + if err := c.performRequest("getunspents", params, resp); err != nil { + return nil, err + } + return resp, nil +} + // InvokeScript returns the result of the given script after running it true the VM. // NOTE: This is a test invoke and will not affect the blockchain. func (c *Client) InvokeScript(script string) (*InvokeScriptResponse, error) { diff --git a/pkg/rpc/types.go b/pkg/rpc/types.go index f87f712f8..058bc9046 100644 --- a/pkg/rpc/types.go +++ b/pkg/rpc/types.go @@ -2,6 +2,7 @@ package rpc import ( "github.com/CityOfZion/neo-go/pkg/core/transaction" + "github.com/CityOfZion/neo-go/pkg/rpc/wrappers" "github.com/CityOfZion/neo-go/pkg/vm" ) @@ -27,6 +28,13 @@ type AccountStateResponse struct { Result *Account `json:"result"` } +// UnspentResponse represents server response to the `getunspents` command. +type UnspentResponse struct { + responseHeader + Error *Error `json:"error,omitempty"` + Result *wrappers.Unspents `json:"result,omitempty"` +} + // Account represents details about a NEO account. type Account struct { Version int `json:"version"`