mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-21 23:43:46 +00:00
result: drop obsolete unmarshaling code
A part of #3454. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
2b1b9a4fca
commit
7683f4366d
3 changed files with 1 additions and 45 deletions
|
@ -25,15 +25,6 @@ APIs/commands/configurations will be removed and here is a list of scheduled
|
|||
breaking changes. Consider changing your code/scripts/configurations if you're
|
||||
using anything mentioned here.
|
||||
|
||||
## GetPeers RPC server response type changes and RPC client support
|
||||
|
||||
GetPeers RPC command returns a list of Peers where the port type has changed from
|
||||
string to uint16 to match C#. The RPC client currently supports unmarshalling both
|
||||
formats.
|
||||
|
||||
Removal of Peer unmarshalling with string based ports is scheduled for Jun-Jul 2024
|
||||
(~0.107.0 release).
|
||||
|
||||
## `NEOBalance` from stack item
|
||||
|
||||
We check struct items count before convert LastGasPerVote to let RPC client be compatible with
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package result
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
|
@ -86,37 +85,6 @@ func (p *Peers) addConnectedPeers(connectedPeers []network.PeerInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Peer) UnmarshalJSON(data []byte) error {
|
||||
type NewPeer Peer
|
||||
var np NewPeer
|
||||
|
||||
err := json.Unmarshal(data, &np)
|
||||
if err == nil {
|
||||
*p = Peer(np)
|
||||
return nil
|
||||
}
|
||||
|
||||
type OldPeer struct {
|
||||
Address string `json:"address"`
|
||||
Port string `json:"port"`
|
||||
}
|
||||
var op OldPeer
|
||||
|
||||
err = json.Unmarshal(data, &op)
|
||||
if err == nil {
|
||||
port, err := strconv.ParseUint(op.Port, 10, 16)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = Peer{
|
||||
Address: op.Address,
|
||||
Port: uint16(port),
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// parseHostPort parses host and port from the given address.
|
||||
// An improperly formatted port string will return zero port.
|
||||
func parseHostPort(addr string) (string, uint16, error) {
|
||||
|
|
|
@ -37,11 +37,8 @@ func TestGetPeers(t *testing.T) {
|
|||
require.Equal(t, uint16(20333), gp.Bad[0].Port)
|
||||
|
||||
gps := GetPeers{}
|
||||
oldPeerFormat := `{"unconnected": [{"address": "20.109.188.128","port": "10333"},{"address": "27.188.182.47","port": "10333"}],"connected": [{"address": "54.227.43.72","port": "10333"},{"address": "157.90.177.38","port": "10333"}],"bad": [{"address": "5.226.142.226","port": "10333"}]}`
|
||||
err := json.Unmarshal([]byte(oldPeerFormat), &gps)
|
||||
require.NoError(t, err)
|
||||
newPeerFormat := `{"unconnected": [{"address": "20.109.188.128","port": 10333},{"address": "27.188.182.47","port": 10333}],"connected": [{"address": "54.227.43.72","port": 10333},{"address": "157.90.177.38","port": 10333}],"bad": [{"address": "5.226.142.226","port": 10333},{"address": "54.208.117.178","port": 10333}]}`
|
||||
err = json.Unmarshal([]byte(newPeerFormat), &gps)
|
||||
err := json.Unmarshal([]byte(newPeerFormat), &gps)
|
||||
require.NoError(t, err)
|
||||
badIntFormat := `{"unconnected": [{"address": "20.109.188.128","port": 65536}],"connected": [],"bad": []}`
|
||||
err = json.Unmarshal([]byte(badIntFormat), &gps)
|
||||
|
|
Loading…
Reference in a new issue