Merge pull request #1525 from nspcc-dev/rpc/base64

rpc: return bse64 bytes from `getblock`, `getblockheader`, `getrawtx`
This commit is contained in:
Roman Khimov 2020-11-09 10:48:28 +03:00 committed by GitHub
commit a9dddf893a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 33 deletions

View file

@ -68,7 +68,7 @@ func (c *Client) GetBlockByHash(hash util.Uint256) (*block.Block, error) {
func (c *Client) getBlock(params request.RawParams) (*block.Block, error) {
var (
resp string
resp []byte
err error
b *block.Block
)
@ -78,11 +78,7 @@ func (c *Client) getBlock(params request.RawParams) (*block.Block, error) {
if err = c.performRequest("getblock", params, &resp); err != nil {
return nil, err
}
blockBytes, err := hex.DecodeString(resp)
if err != nil {
return nil, err
}
r := io.NewBinReaderFromBuf(blockBytes)
r := io.NewBinReaderFromBuf(resp)
b = block.New(c.GetNetwork())
b.DecodeBinary(r)
if r.Err != nil {
@ -137,7 +133,7 @@ func (c *Client) GetBlockHash(index uint32) (util.Uint256, error) {
func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
var (
params = request.NewRawParams(hash.StringLE())
resp string
resp []byte
h *block.Header
)
if !c.initDone {
@ -146,11 +142,7 @@ func (c *Client) GetBlockHeader(hash util.Uint256) (*block.Header, error) {
if err := c.performRequest("getblockheader", params, &resp); err != nil {
return nil, err
}
headerBytes, err := hex.DecodeString(resp)
if err != nil {
return nil, err
}
r := io.NewBinReaderFromBuf(headerBytes)
r := io.NewBinReaderFromBuf(resp)
h = new(block.Header)
h.Network = c.GetNetwork()
h.DecodeBinary(r)
@ -307,7 +299,7 @@ func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction, error) {
var (
params = request.NewRawParams(hash.StringLE())
resp string
resp []byte
err error
)
if !c.initDone {
@ -316,11 +308,7 @@ func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction,
if err = c.performRequest("getrawtransaction", params, &resp); err != nil {
return nil, err
}
txBytes, err := hex.DecodeString(resp)
if err != nil {
return nil, err
}
tx, err := transaction.NewTransactionFromBytes(c.GetNetwork(), txBytes)
tx, err := transaction.NewTransactionFromBytes(c.GetNetwork(), resp)
if err != nil {
return nil, err
}

View file

@ -43,13 +43,13 @@ type rpcClientTestCase struct {
check func(t *testing.T, c *Client, result interface{})
}
const hexB1 = "00000000c0da501a765dcc77a8f2a87c4106cfc0219ff944dc66b87b228ceb95785796a40698a5fbc984182e90f519272f1364568f02f4c845e12d953a4f816d63840f2b19b10e9f73010000010000005e12bea87aeb955884f6f9ce78458cccb97c309501fd08010c400d006b6ec3bf952d536f9a911218be3ec6a94a8014885a630112d0018bcea2c5fb7643b01c68e0bcf4cfb229522e4de97d768549702bdfc7ddc2710eb70d9a820c406dc141248eeccff61f194cbd0610a7c6af4d696b39a1f2cd93b302607b9b001abc9813ffa48f0e4d08b166a3084f53bdea51843d8ead7330d31717e0deab1a7f0c40e4cad924c0979ce67e31dbe979cec6474fa4135c9b01c993965da18f54928af0278371c65b6bb31fe0c752916a92b7ad7152d96033622a85efc8ba891ffd91170c400e1fbd92d760ae03156ed17346ca3ddc80cb5a77e060871bebd7a4fdf842da5a4a51e24a36e85752b580b65e20a4cda9d74ed003d48779ad112cc5f15e29bf3794130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b41138defaf03005704000000000000000200000080969800000000009e7c440000000000b0040000015e12bea87aeb955884f6f9ce78458cccb97c30950100590218ddf5050c14aa8acf859d4fe402b34e673f2156821796a488eb0c145e12bea87aeb955884f6f9ce78458cccb97c309513c00c087472616e736665720c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b523801fd08010c400871252c02d46a978b7e2047a8fa9e3e608edb03a3c6fb5c715243c86f6bcd95a325e0fba68d05454fe6e0da57710986bacdc7287389f419faf28bcd84846a460c4091e1f403af89e3a3de2617afc603e387d18e64ef7e7218c1191ecf7ae7ce81469e9fd004317e620fbcb712e187aba3da74ce0565f410e0dd3c54e69891ca54790c401c8ce4fb2631303519ca8030e45df87add8737328acc6dd6f66ac4e20eed1a7b1cb93395dc8a40358f2a494f8c248718e9d2bae0159452cde621c15d0a973fb20c4088a292b12dde29fa12c7c45ab4ed67df5ddfbeb0dd162115b3bcc267702ac9a923fccf3eb9afc4c6145cef64c7467a558a3bb2a104e8482bac2bcae58d95a0c894130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b41138defaf000300000080969800000000003e8c440000000000b0040000015e12bea87aeb955884f6f9ce78458cccb97c309501005d0300e87648170000000c14aa8acf859d4fe402b34e673f2156821796a488eb0c145e12bea87aeb955884f6f9ce78458cccb97c309513c00c087472616e736665720c14bcaf41d684c7d4ad6ee0d99da9707b9d1f0c8e6641627d5b523801fd08010c408a50f97d779d365cf239eb8102d81ae8aa9376ef8b95de7d73ea40810a66d2ef5e65ce63db876e0b11232c00fd931688617619b5e9a0df36c3e2e6d901fc51380c40f3245b6cf5561cd65222bc6019652c400b3015ffde8a9f6580692ddb0c894024709286c7f3f919f736ebcccaeb6e8d8338bf2122a405fd8248dcbc558629139b0c40a423cf37a27846f5a613c704160f1b26a1fba2a284493a273f709d47f27a9412f32a01360a81d1da04e241558b0aabd33da14bff7e3e8915b303adc6acbe989a0c4084aa4ab66f9d1a11cd4d18cf43040b182c47991eb3350705f76b6b4139e783fca2ed99381ad4866882c660a62b3604e4e864ee8bb8df45258727fbf886702e6e94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b41138defaf"
const base64B1 = "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"
const hexTxMoveNeo = "000200000080969800000000009e7c440000000000b0040000015e12bea87aeb955884f6f9ce78458cccb97c30950100590218ddf5050c14aa8acf859d4fe402b34e673f2156821796a488eb0c145e12bea87aeb955884f6f9ce78458cccb97c309513c00c087472616e736665720c1425059ecb4878d3a875f91c51ceded330d4575fde41627d5b523801fd08010c400871252c02d46a978b7e2047a8fa9e3e608edb03a3c6fb5c715243c86f6bcd95a325e0fba68d05454fe6e0da57710986bacdc7287389f419faf28bcd84846a460c4091e1f403af89e3a3de2617afc603e387d18e64ef7e7218c1191ecf7ae7ce81469e9fd004317e620fbcb712e187aba3da74ce0565f410e0dd3c54e69891ca54790c401c8ce4fb2631303519ca8030e45df87add8737328acc6dd6f66ac4e20eed1a7b1cb93395dc8a40358f2a494f8c248718e9d2bae0159452cde621c15d0a973fb20c4088a292b12dde29fa12c7c45ab4ed67df5ddfbeb0dd162115b3bcc267702ac9a923fccf3eb9afc4c6145cef64c7467a558a3bb2a104e8482bac2bcae58d95a0c894130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b41138defaf"
const base64TxMoveNeo = "AAIAAACAlpgAAAAAAJ58RAAAAAAAsAQAAAFeEr6oeuuVWIT2+c54RYzMuXwwlQEAWQIY3fUFDBSqis+FnU/kArNOZz8hVoIXlqSI6wwUXhK+qHrrlViE9vnOeEWMzLl8MJUTwAwIdHJhbnNmZXIMFCUFnstIeNOodfkcUc7e0zDUV1/eQWJ9W1I4Af0IAQxACHElLALUapeLfiBHqPqePmCO2wOjxvtccVJDyG9rzZWjJeD7po0FRU/m4NpXcQmGus3HKHOJ9Bn68ovNhIRqRgxAkeH0A6+J46PeJhevxgPjh9GOZO9+chjBGR7PeufOgUaen9AEMX5iD7y3EuGHq6PadM4FZfQQ4N08VOaYkcpUeQxAHIzk+yYxMDUZyoAw5F34et2HNzKKzG3W9mrE4g7tGnscuTOV3IpANY8qSU+MJIcY6dK64BWUUs3mIcFdCpc/sgxAiKKSsS3eKfoSx8RatO1n313fvrDdFiEVs7zCZ3Aqyakj/M8+ua/ExhRc72THRnpVijuyoQToSCusK8rljZWgyJQTDCECEDp/fdAWVYWX95YNJ8UWpDlP2Wi55lFV60sBPkBAQG4MIQKnvFX+hoTgEZdo0QS6MHlb3MhmGehkrdJhVnI+0YXNYgwhArNiK/QBe9/jF8WK7V9MdT8ga324lgRvp9d0u8S/f43CDCED2QwH32PmkM53kS4Qq1GsyUS2aGAje2CMT4+DCece5pkUC0ETje+v"
const b1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"size":1641,"nextblockhash":"0x003abea54aa3c5edba7e33fb7ca96452cb65ff8cd36ce1cdfd412a6c4d3ea38a","confirmations":6,"hash":"0xd9518e322440714b0564d6f84a9a39b527b5480e4e7f7932895777a4c8fa0a9e","version":0,"previousblockhash":"0xa496577895eb8c227bb866dc44f99f21c0cf06417ca8f2a877cc5d761a50dac0","merkleroot":"0x2b0f84636d814f3a952de145c8f4028f5664132f2719f5902e1884c9fba59806","time":1596101407001,"index":1,"nextconsensus":"NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY","witnesses":[{"invocation":"DEANAGtuw7+VLVNvmpESGL4+xqlKgBSIWmMBEtABi86ixft2Q7AcaOC89M+yKVIuTel9doVJcCvfx93CcQ63DZqCDEBtwUEkjuzP9h8ZTL0GEKfGr01pazmh8s2TswJge5sAGryYE/+kjw5NCLFmowhPU73qUYQ9jq1zMNMXF+Deqxp/DEDkytkkwJec5n4x2+l5zsZHT6QTXJsByZOWXaGPVJKK8CeDccZba7Mf4MdSkWqSt61xUtlgM2Iqhe/Iuokf/ZEXDEAOH72S12CuAxVu0XNGyj3cgMtad+Bghxvr16T9+ELaWkpR4ko26FdStYC2XiCkzanXTtAD1Id5rREsxfFeKb83","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw=="}],"consensusdata":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0x32f9bd3a2707475407c41bf5daacf9560e25ed74f6d85b3afb2ef72edb2325ba","size":555,"version":0,"nonce":2,"sender":"NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY","sysfee":"10000000","netfee":"4488350","validuntilblock":1200,"attributes":[],"signers":[{"account":"0x95307cb9cc8c4578cef9f6845895eb7aa8be125e","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFKqKz4WdT+QCs05nPyFWgheWpIjrDBReEr6oeuuVWIT2+c54RYzMuXwwlRPADAh0cmFuc2ZlcgwUJQWey0h406h1+RxRzt7TMNRXX95BYn1bUjg=","witnesses":[{"invocation":"DEAIcSUsAtRql4t+IEeo+p4+YI7bA6PG+1xxUkPIb2vNlaMl4PumjQVFT+bg2ldxCYa6zccoc4n0Gfryi82EhGpGDECR4fQDr4njo94mF6/GA+OH0Y5k735yGMEZHs96586BRp6f0AQxfmIPvLcS4Yero9p0zgVl9BDg3TxU5piRylR5DEAcjOT7JjEwNRnKgDDkXfh63Yc3MorMbdb2asTiDu0aexy5M5XcikA1jypJT4wkhxjp0rrgFZRSzeYhwV0Klz+yDECIopKxLd4p+hLHxFq07WffXd++sN0WIRWzvMJncCrJqSP8zz65r8TGFFzvZMdGelWKO7KhBOhIK6wryuWNlaDI","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw=="}]},{"hash":"0xd35d6386ec2f29b90839536f6af9466098d1665e951cdd0a20db6b4629b08369","size":559,"version":0,"nonce":3,"sender":"NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY","sysfee":"10000000","netfee":"4492350","validuntilblock":1200,"attributes":[],"signers":[{"account":"0x95307cb9cc8c4578cef9f6845895eb7aa8be125e","scopes":"CalledByEntry"}],"script":"AwDodkgXAAAADBSqis+FnU/kArNOZz8hVoIXlqSI6wwUXhK+qHrrlViE9vnOeEWMzLl8MJUTwAwIdHJhbnNmZXIMFLyvQdaEx9StbuDZnalwe50fDI5mQWJ9W1I4","witnesses":[{"invocation":"DECKUPl9d502XPI564EC2BroqpN274uV3n1z6kCBCmbS715lzmPbh24LESMsAP2TFohhdhm16aDfNsPi5tkB/FE4DEDzJFts9VYc1lIivGAZZSxACzAV/96Kn2WAaS3bDIlAJHCShsfz+Rn3NuvMyutujYM4vyEipAX9gkjcvFWGKRObDECkI883onhG9aYTxwQWDxsmofuiooRJOic/cJ1H8nqUEvMqATYKgdHaBOJBVYsKq9M9oUv/fj6JFbMDrcasvpiaDECEqkq2b50aEc1NGM9DBAsYLEeZHrM1BwX3a2tBOeeD/KLtmTga1IZogsZgpis2BOToZO6LuN9FJYcn+/iGcC5u","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw=="}]}]}}`
const hexHeader1 = "00000000c0da501a765dcc77a8f2a87c4106cfc0219ff944dc66b87b228ceb95785796a40698a5fbc984182e90f519272f1364568f02f4c845e12d953a4f816d63840f2b19b10e9f73010000010000005e12bea87aeb955884f6f9ce78458cccb97c309501fd08010c400d006b6ec3bf952d536f9a911218be3ec6a94a8014885a630112d0018bcea2c5fb7643b01c68e0bcf4cfb229522e4de97d768549702bdfc7ddc2710eb70d9a820c406dc141248eeccff61f194cbd0610a7c6af4d696b39a1f2cd93b302607b9b001abc9813ffa48f0e4d08b166a3084f53bdea51843d8ead7330d31717e0deab1a7f0c40e4cad924c0979ce67e31dbe979cec6474fa4135c9b01c993965da18f54928af0278371c65b6bb31fe0c752916a92b7ad7152d96033622a85efc8ba891ffd91170c400e1fbd92d760ae03156ed17346ca3ddc80cb5a77e060871bebd7a4fdf842da5a4a51e24a36e85752b580b65e20a4cda9d74ed003d48779ad112cc5f15e29bf3794130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b41138defaf00"
const base64Header1 = "AAAAAMDaUBp2Xcx3qPKofEEGz8Ahn/lE3Ga4eyKM65V4V5akBpil+8mEGC6Q9RknLxNkVo8C9MhF4S2VOk+BbWOEDysZsQ6fcwEAAAEAAABeEr6oeuuVWIT2+c54RYzMuXwwlQH9CAEMQA0Aa27Dv5UtU2+akRIYvj7GqUqAFIhaYwES0AGLzqLF+3ZDsBxo4Lz0z7IpUi5N6X12hUlwK9/H3cJxDrcNmoIMQG3BQSSO7M/2HxlMvQYQp8avTWlrOaHyzZOzAmB7mwAavJgT/6SPDk0IsWajCE9TvepRhD2OrXMw0xcX4N6rGn8MQOTK2STAl5zmfjHb6XnOxkdPpBNcmwHJk5ZdoY9UkorwJ4Nxxltrsx/gx1KRapK3rXFS2WAzYiqF78i6iR/9kRcMQA4fvZLXYK4DFW7Rc0bKPdyAy1p34GCHG+vXpP34QtpaSlHiSjboV1K1gLZeIKTNqddO0APUh3mtESzF8V4pvzeUEwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrwA="
const header1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"hash":"0xd9518e322440714b0564d6f84a9a39b527b5480e4e7f7932895777a4c8fa0a9e","size":518,"version":0,"previousblockhash":"0xa496577895eb8c227bb866dc44f99f21c0cf06417ca8f2a877cc5d761a50dac0","merkleroot":"0x2b0f84636d814f3a952de145c8f4028f5664132f2719f5902e1884c9fba59806","time":1596101407001,"index":1,"nextconsensus":"NUVPACMnKFhpuHjsRjhUvXz1XhqfGZYVtY","witnesses":[{"invocation":"DEANAGtuw7+VLVNvmpESGL4+xqlKgBSIWmMBEtABi86ixft2Q7AcaOC89M+yKVIuTel9doVJcCvfx93CcQ63DZqCDEBtwUEkjuzP9h8ZTL0GEKfGr01pazmh8s2TswJge5sAGryYE/+kjw5NCLFmowhPU73qUYQ9jq1zMNMXF+Deqxp/DEDkytkkwJec5n4x2+l5zsZHT6QTXJsByZOWXaGPVJKK8CeDccZba7Mf4MdSkWqSt61xUtlgM2Iqhe/Iuokf/ZEXDEAOH72S12CuAxVu0XNGyj3cgMtad+Bghxvr16T9+ELaWkpR4ko26FdStYC2XiCkzanXTtAD1Id5rREsxfFeKb83","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBE43vrw=="}],"confirmations":6,"nextblockhash":"0x003abea54aa3c5edba7e33fb7ca96452cb65ff8cd36ce1cdfd412a6c4d3ea38a"}}`
@ -57,7 +57,7 @@ const txMoveNeoVerbose = `{"id":5,"jsonrpc":"2.0","result":{"blockhash":"0xd9518
// getResultBlock1 returns data for block number 1 which is used by several tests.
func getResultBlock1() *result.Block {
binB, err := hex.DecodeString(hexB1)
binB, err := base64.StdEncoding.DecodeString(base64B1)
if err != nil {
panic(err)
}
@ -82,7 +82,7 @@ func getResultBlock1() *result.Block {
func getTxMoveNeo() *result.TransactionOutputRaw {
b1 := getResultBlock1()
txBin, err := hex.DecodeString(hexTxMoveNeo)
txBin, err := base64.StdEncoding.DecodeString(base64TxMoveNeo)
if err != nil {
panic(err)
}
@ -149,7 +149,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
invoke: func(c *Client) (interface{}, error) {
return c.GetBlockByIndex(1)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + hexB1 + `"}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64B1 + `"}`,
result: func(c *Client) interface{} {
b := getResultBlock1()
return &b.Block
@ -177,7 +177,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
}
return c.GetBlockByHash(hash)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + hexB1 + `"}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64B1 + `"}`,
result: func(c *Client) interface{} {
b := getResultBlock1()
return &b.Block
@ -239,7 +239,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
}
return c.GetBlockHeader(hash)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + hexHeader1 + `"}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64Header1 + `"}`,
result: func(c *Client) interface{} {
b := getResultBlock1()
return b.Header()
@ -551,7 +551,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
}
return c.GetRawTransaction(hash)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + hexTxMoveNeo + `"}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"` + base64TxMoveNeo + `"}`,
result: func(c *Client) interface{} {
tx := getTxMoveNeo()
return &tx.Transaction

View file

@ -458,7 +458,7 @@ func (s *Server) getBlock(reqParams request.Params) (interface{}, *response.Erro
}
writer := io.NewBufBinWriter()
block.EncodeBinary(writer.BinWriter)
return hex.EncodeToString(writer.Bytes()), nil
return writer.Bytes(), nil
}
func (s *Server) getBlockHash(reqParams request.Params) (interface{}, *response.Error) {
@ -858,7 +858,7 @@ func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, *resp
}
results = result.NewTransactionOutputRaw(tx, header, st, s.chain)
} else {
results = hex.EncodeToString(tx.Bytes())
results = tx.Bytes()
}
return results, resultsErr
@ -941,7 +941,7 @@ func (s *Server) getBlockHeader(reqParams request.Params) (interface{}, *respons
if buf.Err != nil {
return nil, response.NewInternalServerError("encoding error", buf.Err)
}
return hex.EncodeToString(buf.Bytes()), nil
return buf.Bytes(), nil
}
// getUnclaimedGas returns unclaimed GAS amount of the specified address.

View file

@ -2,6 +2,7 @@ package server
import (
"bytes"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
@ -954,7 +955,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
require.NoErrorf(t, err, "could not parse response: %s", result)
txBin, err := testserdes.EncodeBinary(tx)
require.NoError(t, err)
expected := hex.EncodeToString(txBin)
expected := base64.StdEncoding.EncodeToString(txBin)
assert.Equal(t, expected, res)
})
@ -969,7 +970,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
require.NoErrorf(t, err, "could not parse response: %s", result)
txBin, err := testserdes.EncodeBinary(tx)
require.NoError(t, err)
expected := hex.EncodeToString(txBin)
expected := base64.StdEncoding.EncodeToString(txBin)
assert.Equal(t, expected, res)
})
@ -1005,7 +1006,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
w := io.NewBufBinWriter()
hdr.EncodeBinary(w.BinWriter)
require.NoError(t, w.Err)
encoded := hex.EncodeToString(w.Bytes())
encoded := base64.StdEncoding.EncodeToString(w.Bytes())
t.Run("missing", func(t *testing.T) {
runCase(t, fmt.Sprintf(rpc, `["`+testHeaderHash+`"]`), &encoded, new(string))