From 685e34d83c06c1d9d95238136fa5e95317edae0f Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 3 Mar 2020 18:59:21 +0300 Subject: [PATCH] rpc: update client documentation Add missing methods, move example into something that can be compiled (and fix it along the way). --- pkg/rpc/client/doc.go | 76 +++++++++++++++++++------------------- pkg/rpc/client/doc_test.go | 33 +++++++++++++++++ 2 files changed, 71 insertions(+), 38 deletions(-) create mode 100644 pkg/rpc/client/doc_test.go diff --git a/pkg/rpc/client/doc.go b/pkg/rpc/client/doc.go index 8c82d20c9..2effd97ff 100644 --- a/pkg/rpc/client/doc.go +++ b/pkg/rpc/client/doc.go @@ -11,59 +11,59 @@ Some of the methods also allow to pass a verbose bool. This will return a more pretty printed response from the server instead of a raw hex string. -An example: - endpoint := "http://seed5.bridgeprotocol.io:10332" - opts := client.Options{} - - c, err := client.New(context.TODO(), endpoint, opts) - if err != nil { - log.Fatal(err) - } - - if err := c.Ping(); err != nil { - log.Fatal(err) - } - - resp, err := c.GetAccountState("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP") - if err != nil { - log.Fatal(err) - } - log.Println(resp.Result.ScriptHash) - log.Println(resp.Result.Balances) - TODO: - Merge structs so can be used by both server and client. Add missing methods to client. Allow client to connect using client cert. More in-depth examples. Supported methods - getblock getaccountstate + getclaimable getunspents - invokescript - invokefunction - sendrawtransaction invoke - getrawtransaction + invokefunction + invokescript + sendrawtransaction Unsupported methods - validateaddress - getblocksysfee - getcontractstate - getrawmempool - getstorage - submitblock - gettxout + claimgas + dumpprivkey + getapplicationlog getassetstate - getpeers - getversion - getconnectioncount - getblockhash - getblockcount + getbalance getbestblockhash + getblock + getblockcount + getblockhash + getblockheader + getblocksysfee + getconnectioncount + getcontractstate + getmetricblocktimestamp + getnep5balances + getnep5transfers + getnewaddress + getpeers + getrawmempool + getrawtransaction + getstorage + gettransactionheight + gettxout + getunclaimed + getunclaimedgas + getvalidators + getversion + getwalletheight + importprivkey + listaddress + listplugins + sendfrom + sendmany + sendtoaddress + submitblock + validateaddress */ package client diff --git a/pkg/rpc/client/doc_test.go b/pkg/rpc/client/doc_test.go new file mode 100644 index 000000000..b7f3e5f00 --- /dev/null +++ b/pkg/rpc/client/doc_test.go @@ -0,0 +1,33 @@ +package client_test + +import ( + "context" + "fmt" + "os" + + "github.com/nspcc-dev/neo-go/pkg/rpc/client" +) + +func Example() { + endpoint := "http://seed5.bridgeprotocol.io:10332" + opts := client.Options{} + + c, err := client.New(context.TODO(), endpoint, opts) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + if err := c.Ping(); err != nil { + fmt.Println(err) + os.Exit(1) + } + + resp, err := c.GetAccountState("ATySFJAbLW7QHsZGHScLhxq6EyNBxx3eFP") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Println(resp.ScriptHash) + fmt.Println(resp.Balances) +}