forked from TrueCloudLab/neoneo-go
result: drop Version (un)marshaler, we only need it for Protocol
Simplify code a bit.
This commit is contained in:
parent
8324a247d3
commit
cb806d4233
1 changed files with 37 additions and 58 deletions
|
@ -11,11 +11,11 @@ type (
|
||||||
// Version model used for reporting server version
|
// Version model used for reporting server version
|
||||||
// info.
|
// info.
|
||||||
Version struct {
|
Version struct {
|
||||||
TCPPort uint16
|
TCPPort uint16 `json:"tcpport"`
|
||||||
WSPort uint16
|
WSPort uint16 `json:"wsport,omitempty"`
|
||||||
Nonce uint32
|
Nonce uint32 `json:"nonce"`
|
||||||
UserAgent string
|
UserAgent string `json:"useragent"`
|
||||||
Protocol Protocol
|
Protocol Protocol `json:"protocol"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protocol represents network-dependent parameters.
|
// Protocol represents network-dependent parameters.
|
||||||
|
@ -42,17 +42,6 @@ type (
|
||||||
// ValidatorsHistory stores height:size map of the validators count.
|
// ValidatorsHistory stores height:size map of the validators count.
|
||||||
ValidatorsHistory map[uint32]int
|
ValidatorsHistory map[uint32]int
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// versionMarshallerAux is an auxiliary struct used for Version JSON marshalling.
|
|
||||||
versionMarshallerAux struct {
|
|
||||||
TCPPort uint16 `json:"tcpport"`
|
|
||||||
WSPort uint16 `json:"wsport,omitempty"`
|
|
||||||
Nonce uint32 `json:"nonce"`
|
|
||||||
UserAgent string `json:"useragent"`
|
|
||||||
Protocol protocolMarshallerAux `json:"protocol"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// protocolMarshallerAux is an auxiliary struct used for Protocol JSON marshalling.
|
// protocolMarshallerAux is an auxiliary struct used for Protocol JSON marshalling.
|
||||||
protocolMarshallerAux struct {
|
protocolMarshallerAux struct {
|
||||||
|
@ -73,57 +62,47 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// MarshalJSON implements the json marshaller interface.
|
// MarshalJSON implements the JSON marshaler interface.
|
||||||
func (v *Version) MarshalJSON() ([]byte, error) {
|
func (p Protocol) MarshalJSON() ([]byte, error) {
|
||||||
aux := versionMarshallerAux{
|
aux := protocolMarshallerAux{
|
||||||
TCPPort: v.TCPPort,
|
AddressVersion: p.AddressVersion,
|
||||||
WSPort: v.WSPort,
|
Network: p.Network,
|
||||||
Nonce: v.Nonce,
|
MillisecondsPerBlock: p.MillisecondsPerBlock,
|
||||||
UserAgent: v.UserAgent,
|
MaxTraceableBlocks: p.MaxTraceableBlocks,
|
||||||
Protocol: protocolMarshallerAux{
|
MaxValidUntilBlockIncrement: p.MaxValidUntilBlockIncrement,
|
||||||
AddressVersion: v.Protocol.AddressVersion,
|
MaxTransactionsPerBlock: p.MaxTransactionsPerBlock,
|
||||||
Network: v.Protocol.Network,
|
MemoryPoolMaxTransactions: p.MemoryPoolMaxTransactions,
|
||||||
MillisecondsPerBlock: v.Protocol.MillisecondsPerBlock,
|
ValidatorsCount: p.ValidatorsCount,
|
||||||
MaxTraceableBlocks: v.Protocol.MaxTraceableBlocks,
|
InitialGasDistribution: int64(p.InitialGasDistribution),
|
||||||
MaxValidUntilBlockIncrement: v.Protocol.MaxValidUntilBlockIncrement,
|
|
||||||
MaxTransactionsPerBlock: v.Protocol.MaxTransactionsPerBlock,
|
|
||||||
MemoryPoolMaxTransactions: v.Protocol.MemoryPoolMaxTransactions,
|
|
||||||
ValidatorsCount: v.Protocol.ValidatorsCount,
|
|
||||||
InitialGasDistribution: int64(v.Protocol.InitialGasDistribution),
|
|
||||||
|
|
||||||
CommitteeHistory: v.Protocol.CommitteeHistory,
|
CommitteeHistory: p.CommitteeHistory,
|
||||||
P2PSigExtensions: v.Protocol.P2PSigExtensions,
|
P2PSigExtensions: p.P2PSigExtensions,
|
||||||
StateRootInHeader: v.Protocol.StateRootInHeader,
|
StateRootInHeader: p.StateRootInHeader,
|
||||||
ValidatorsHistory: v.Protocol.ValidatorsHistory,
|
ValidatorsHistory: p.ValidatorsHistory,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return json.Marshal(aux)
|
return json.Marshal(aux)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON implements the json unmarshaller interface.
|
// UnmarshalJSON implements the JSON unmarshaler interface.
|
||||||
func (v *Version) UnmarshalJSON(data []byte) error {
|
func (p *Protocol) UnmarshalJSON(data []byte) error {
|
||||||
var aux versionMarshallerAux
|
var aux protocolMarshallerAux
|
||||||
err := json.Unmarshal(data, &aux)
|
err := json.Unmarshal(data, &aux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v.TCPPort = aux.TCPPort
|
p.AddressVersion = aux.AddressVersion
|
||||||
v.WSPort = aux.WSPort
|
p.Network = aux.Network
|
||||||
v.Nonce = aux.Nonce
|
p.MillisecondsPerBlock = aux.MillisecondsPerBlock
|
||||||
v.UserAgent = aux.UserAgent
|
p.MaxTraceableBlocks = aux.MaxTraceableBlocks
|
||||||
v.Protocol.AddressVersion = aux.Protocol.AddressVersion
|
p.MaxValidUntilBlockIncrement = aux.MaxValidUntilBlockIncrement
|
||||||
v.Protocol.Network = aux.Protocol.Network
|
p.MaxTransactionsPerBlock = aux.MaxTransactionsPerBlock
|
||||||
v.Protocol.MillisecondsPerBlock = aux.Protocol.MillisecondsPerBlock
|
p.MemoryPoolMaxTransactions = aux.MemoryPoolMaxTransactions
|
||||||
v.Protocol.MaxTraceableBlocks = aux.Protocol.MaxTraceableBlocks
|
p.ValidatorsCount = aux.ValidatorsCount
|
||||||
v.Protocol.MaxValidUntilBlockIncrement = aux.Protocol.MaxValidUntilBlockIncrement
|
p.CommitteeHistory = aux.CommitteeHistory
|
||||||
v.Protocol.MaxTransactionsPerBlock = aux.Protocol.MaxTransactionsPerBlock
|
p.P2PSigExtensions = aux.P2PSigExtensions
|
||||||
v.Protocol.MemoryPoolMaxTransactions = aux.Protocol.MemoryPoolMaxTransactions
|
p.StateRootInHeader = aux.StateRootInHeader
|
||||||
v.Protocol.ValidatorsCount = aux.Protocol.ValidatorsCount
|
p.ValidatorsHistory = aux.ValidatorsHistory
|
||||||
v.Protocol.CommitteeHistory = aux.Protocol.CommitteeHistory
|
p.InitialGasDistribution = fixedn.Fixed8(aux.InitialGasDistribution)
|
||||||
v.Protocol.P2PSigExtensions = aux.Protocol.P2PSigExtensions
|
|
||||||
v.Protocol.StateRootInHeader = aux.Protocol.StateRootInHeader
|
|
||||||
v.Protocol.ValidatorsHistory = aux.Protocol.ValidatorsHistory
|
|
||||||
v.Protocol.InitialGasDistribution = fixedn.Fixed8(aux.Protocol.InitialGasDistribution)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue