From 8714be3c5f15813419f9463db5435e78455015b2 Mon Sep 17 00:00:00 2001 From: revett Date: Fri, 27 Oct 2017 21:09:50 +0100 Subject: [PATCH 1/6] New function: GetStorage() --- neo/client.go | 16 ++++++++++++++++ neo/client_test.go | 14 ++++++++++++++ neo/helper_test.go | 4 ++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/neo/client.go b/neo/client.go index f5a9191..501a35a 100644 --- a/neo/client.go +++ b/neo/client.go @@ -1,6 +1,7 @@ package neo import ( + "encoding/hex" "net" "net/url" @@ -106,6 +107,21 @@ func (c Client) GetConnectionCount() (int64, error) { return response.Result, nil } +// GetStorage is TODO. +func (c Client) GetStorage(scriptHash string, storageKey string) (string, error) { + requestBodyParams := []interface{}{ + scriptHash, hex.EncodeToString([]byte(storageKey)), + } + var response response.String + + err := executeRequest("getstorage", requestBodyParams, c.NodeURI, &response) + if err != nil { + return "", err + } + + return response.Result, nil +} + // GetTransaction returns the corresponding transaction information based on the // specified hash value. func (c Client) GetTransaction(hash string) (*models.Transaction, error) { diff --git a/neo/client_test.go b/neo/client_test.go index ae976cf..4218c64 100644 --- a/neo/client_test.go +++ b/neo/client_test.go @@ -99,6 +99,20 @@ func TestClient(t *testing.T) { }) }) + t.Run(".GetStorage()", func(t *testing.T) { + t.Run("HappyCase", func(t *testing.T) { + client := neo.NewClient(nodeURI) + + storage, err := client.GetStorage( + "0xecc6b20d3ccac1ee9ef109af5a7cdb85706b1df9", + "totalSupply", + ) + + assert.NoError(t, err) + assert.Equal(t, "0072ef3e2597e201", storage) + }) + }) + t.Run(".GetTransaction()", func(t *testing.T) { t.Run("HappyCase", func(t *testing.T) { client := neo.NewClient(nodeURI) diff --git a/neo/helper_test.go b/neo/helper_test.go index 186783b..c2beddc 100644 --- a/neo/helper_test.go +++ b/neo/helper_test.go @@ -7,14 +7,14 @@ import ( ) const ( - cozNodeURI = "http://test%d.cityofzion.io:8880" + neoNodeURI = "http://seed%d.neo.org:10332" ) func selectTestNode() string { var nodeURI string for i := 1; i <= 5; i++ { - uri := fmt.Sprintf(cozNodeURI, i) + uri := fmt.Sprintf(neoNodeURI, i) client := neo.NewClient(uri) ok := client.Ping() From 1d7be05f9c06eb93f06ede179ee75c23a6d84f2e Mon Sep 17 00:00:00 2001 From: revett Date: Fri, 27 Oct 2017 21:10:42 +0100 Subject: [PATCH 2/6] Add comment to function --- neo/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/client.go b/neo/client.go index 501a35a..2310118 100644 --- a/neo/client.go +++ b/neo/client.go @@ -107,7 +107,8 @@ func (c Client) GetConnectionCount() (int64, error) { return response.Result, nil } -// GetStorage is TODO. +// GetStorage takes a smart contract hash and a storage key, and returns the storage value +// if available. func (c Client) GetStorage(scriptHash string, storageKey string) (string, error) { requestBodyParams := []interface{}{ scriptHash, hex.EncodeToString([]byte(storageKey)), From 48291f3a522eb1f239c1576bec05612575a0655f Mon Sep 17 00:00:00 2001 From: revett Date: Fri, 27 Oct 2017 21:11:16 +0100 Subject: [PATCH 3/6] 1.7.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 9c6d629..bd8bf88 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1 +1.7.0 From aa3d4d8fbcff49fb057908504f19c012e9ad9a10 Mon Sep 17 00:00:00 2001 From: revett Date: Fri, 27 Oct 2017 21:22:20 +0100 Subject: [PATCH 4/6] Updated some of the fixtures --- neo/fixtures_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/neo/fixtures_test.go b/neo/fixtures_test.go index 476af83..df4170d 100644 --- a/neo/fixtures_test.go +++ b/neo/fixtures_test.go @@ -43,11 +43,11 @@ var ( numberOfTransactions int }{ { - hash: "0x3f0b498c0d57f73c674a1e28045f5e9a0991f9dac214076fadb5e6bafd546170", + hash: "0x9ceb257832478ef778c1f26ad916ef8cbf116c71fe3cd6c5a8f672c1663539ae", id: "1", - index: 316675, - merkleRoot: "0xd51ef6237173eee1d422811c2e79d2e30928ed7c487ff9be60c493a9901b03b8", - numberOfTransactions: 2, + index: 1511369, + merkleRoot: "0x04bb7e7c56711b3387f1593c36dcdc36516b6ccd06d0e0c15adeba3c33643ebe", + numberOfTransactions: 17, }, } @@ -57,9 +57,9 @@ var ( size int64 }{ { - hash: "0x8aaf766179c07941f24a08157d7e6796e6d4aa999d3eaf83e74024c28d081af0", + hash: "0xc515c4d2db27e06fd2305a5c5378f820d2c4cc04477ebe40ffa40b956eb4f8b5", id: "1", - size: 262, + size: 202, }, } @@ -71,11 +71,11 @@ var ( value string }{ { - asset: "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7", - hash: "0x8aaf766179c07941f24a08157d7e6796e6d4aa999d3eaf83e74024c28d081af0", + asset: "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", + hash: "0xc515c4d2db27e06fd2305a5c5378f820d2c4cc04477ebe40ffa40b956eb4f8b5", id: "1", index: 0, - value: "50", + value: "96", }, } @@ -86,8 +86,8 @@ var ( }{ { id: "1", - index: 316675, - hash: "0x3f0b498c0d57f73c674a1e28045f5e9a0991f9dac214076fadb5e6bafd546170", + index: 1511369, + hash: "0x9ceb257832478ef778c1f26ad916ef8cbf116c71fe3cd6c5a8f672c1663539ae", }, } From b23a614a693689c688456e39aa06e940558888d7 Mon Sep 17 00:00:00 2001 From: revett Date: Fri, 27 Oct 2017 21:23:51 +0100 Subject: [PATCH 5/6] CHANGELOG --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c4c940..a67941d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## v1.7.0 - 2017-10-27 + +### Added + +- New function to fetch a storage value of a given smart contract. + +```golang +storage, err := client.GetStorage( + "0xecc6b20d3ccac1ee9ef109af5a7cdb85706b1df9", // RPX smart contract + "totalSupply", +) +``` + +### Changed + +- Updated client unit tests to adhere to the new JSON RPC hash representations. +- Performed some general cleanup and organization in existing client unit tests. + ## v1.6.1 - 2017-10-13 ### Changed From 7478928e1123da0cfdc17646c79c5ace2e513191 Mon Sep 17 00:00:00 2001 From: revett Date: Fri, 27 Oct 2017 21:25:30 +0100 Subject: [PATCH 6/6] Typo in CHANGELOG --- CHANGELOG.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a67941d..38f1312 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,11 +18,6 @@ storage, err := client.GetStorage( ) ``` -### Changed - -- Updated client unit tests to adhere to the new JSON RPC hash representations. -- Performed some general cleanup and organization in existing client unit tests. - ## v1.6.1 - 2017-10-13 ### Changed