commit
1f98289f5d
5 changed files with 17 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
@ -43,8 +43,8 @@ func batchToMap(index uint32, batch *storage.MemBatch) blockDump {
|
|||
|
||||
ops = append(ops, storageOp{
|
||||
State: op,
|
||||
Key: hex.EncodeToString(key[1:]),
|
||||
Value: hex.EncodeToString(batch.Put[i].Value),
|
||||
Key: base64.StdEncoding.EncodeToString(key[1:]),
|
||||
Value: base64.StdEncoding.EncodeToString(batch.Put[i].Value),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ func batchToMap(index uint32, batch *storage.MemBatch) blockDump {
|
|||
|
||||
ops = append(ops, storageOp{
|
||||
State: "Deleted",
|
||||
Key: hex.EncodeToString(key[1:]),
|
||||
Key: base64.StdEncoding.EncodeToString(key[1:]),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
|
@ -349,24 +349,20 @@ func (c *Client) GetRawTransactionVerbose(hash util.Uint256) (*result.Transactio
|
|||
|
||||
// GetStorageByID returns the stored value, according to the contract ID and the stored key.
|
||||
func (c *Client) GetStorageByID(id int32, key []byte) ([]byte, error) {
|
||||
return c.getStorage(request.NewRawParams(id, hex.EncodeToString(key)))
|
||||
return c.getStorage(request.NewRawParams(id, base64.StdEncoding.EncodeToString(key)))
|
||||
}
|
||||
|
||||
// GetStorageByHash returns the stored value, according to the contract script hash and the stored key.
|
||||
func (c *Client) GetStorageByHash(hash util.Uint160, key []byte) ([]byte, error) {
|
||||
return c.getStorage(request.NewRawParams(hash.StringLE(), hex.EncodeToString(key)))
|
||||
return c.getStorage(request.NewRawParams(hash.StringLE(), base64.StdEncoding.EncodeToString(key)))
|
||||
}
|
||||
|
||||
func (c *Client) getStorage(params request.RawParams) ([]byte, error) {
|
||||
var resp string
|
||||
var resp []byte
|
||||
if err := c.performRequest("getstorage", params, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := hex.DecodeString(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetTransactionHeight returns the block index in which the transaction is found.
|
||||
|
|
|
@ -607,7 +607,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
}
|
||||
return c.GetStorageByHash(hash, key)
|
||||
},
|
||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":"4c696e"}`,
|
||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":"TGlu"}`,
|
||||
result: func(c *Client) interface{} {
|
||||
value, err := hex.DecodeString("4c696e")
|
||||
if err != nil {
|
||||
|
@ -625,7 +625,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
}
|
||||
return c.GetStorageByID(-1, key)
|
||||
},
|
||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":"4c696e"}`,
|
||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":"TGlu"}`,
|
||||
result: func(c *Client) interface{} {
|
||||
value, err := hex.DecodeString("4c696e")
|
||||
if err != nil {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"crypto/elliptic"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -915,7 +914,7 @@ func (s *Server) getStorage(ps request.Params) (interface{}, *response.Error) {
|
|||
return nil, rErr
|
||||
}
|
||||
|
||||
key, err := ps.Value(1).GetBytesHex()
|
||||
key, err := ps.Value(1).GetBytesBase64()
|
||||
if err != nil {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
|
@ -925,7 +924,7 @@ func (s *Server) getStorage(ps request.Params) (interface{}, *response.Error) {
|
|||
return "", nil
|
||||
}
|
||||
|
||||
return hex.EncodeToString(item.Value), nil
|
||||
return item.Value, nil
|
||||
}
|
||||
|
||||
func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, *response.Error) {
|
||||
|
|
|
@ -3,7 +3,6 @@ package server
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
@ -346,15 +345,15 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
"getstorage": {
|
||||
{
|
||||
name: "positive",
|
||||
params: fmt.Sprintf(`["%s", "746573746b6579"]`, testContractHash),
|
||||
params: fmt.Sprintf(`["%s", "dGVzdGtleQ=="]`, testContractHash),
|
||||
result: func(e *executor) interface{} {
|
||||
v := hex.EncodeToString([]byte("testvalue"))
|
||||
v := base64.StdEncoding.EncodeToString([]byte("testvalue"))
|
||||
return &v
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing key",
|
||||
params: fmt.Sprintf(`["%s", "7465"]`, testContractHash),
|
||||
params: fmt.Sprintf(`["%s", "dGU="]`, testContractHash),
|
||||
result: func(e *executor) interface{} {
|
||||
v := ""
|
||||
return &v
|
||||
|
@ -377,7 +376,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
},
|
||||
{
|
||||
name: "invalid key",
|
||||
params: fmt.Sprintf(`["%s", "notahex"]`, testContractHash),
|
||||
params: fmt.Sprintf(`["%s", "notabase64$"]`, testContractHash),
|
||||
fail: true,
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue