2018-03-23 20:36:59 +00:00
|
|
|
package result
|
|
|
|
|
2021-09-07 12:42:04 +00:00
|
|
|
import (
|
2022-04-26 09:32:06 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
2021-09-07 12:42:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
2022-04-25 13:01:30 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
2021-09-07 12:42:04 +00:00
|
|
|
)
|
2020-10-14 13:52:49 +00:00
|
|
|
|
2018-03-23 20:36:59 +00:00
|
|
|
type (
|
|
|
|
// Version model used for reporting server version
|
|
|
|
// info.
|
|
|
|
Version struct {
|
2022-04-26 09:32:06 +00:00
|
|
|
TCPPort uint16
|
|
|
|
WSPort uint16
|
|
|
|
Nonce uint32
|
|
|
|
UserAgent string
|
|
|
|
Protocol Protocol
|
2021-09-07 12:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Protocol represents network-dependent parameters.
|
|
|
|
Protocol struct {
|
2022-04-26 09:32:06 +00:00
|
|
|
AddressVersion byte
|
|
|
|
Network netmode.Magic
|
|
|
|
MillisecondsPerBlock int
|
|
|
|
MaxTraceableBlocks uint32
|
|
|
|
MaxValidUntilBlockIncrement uint32
|
|
|
|
MaxTransactionsPerBlock uint16
|
|
|
|
MemoryPoolMaxTransactions int
|
|
|
|
ValidatorsCount byte
|
|
|
|
InitialGasDistribution fixedn.Fixed8
|
2022-08-08 13:10:02 +00:00
|
|
|
|
|
|
|
// Below are NeoGo-specific extensions to the protocol that are
|
|
|
|
// returned by the server in case they're enabled.
|
|
|
|
|
|
|
|
// CommitteeHistory stores height:size map of the committee size.
|
|
|
|
CommitteeHistory map[uint32]int
|
|
|
|
// P2PSigExtensions is true when Notary subsystem is enabled on the network.
|
|
|
|
P2PSigExtensions bool
|
2022-04-26 09:32:06 +00:00
|
|
|
// StateRootInHeader is true if state root is contained in block header.
|
|
|
|
StateRootInHeader bool
|
2022-08-08 13:10:02 +00:00
|
|
|
// ValidatorsHistory stores height:size map of the validators count.
|
|
|
|
ValidatorsHistory map[uint32]int
|
2022-04-26 09:32:06 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// versionMarshallerAux is an auxiliary struct used for Version JSON marshalling.
|
|
|
|
versionMarshallerAux struct {
|
2022-11-10 13:32:49 +00:00
|
|
|
TCPPort uint16 `json:"tcpport"`
|
|
|
|
WSPort uint16 `json:"wsport,omitempty"`
|
|
|
|
Nonce uint32 `json:"nonce"`
|
|
|
|
UserAgent string `json:"useragent"`
|
|
|
|
Protocol protocolMarshallerAux `json:"protocol"`
|
2022-04-26 09:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// protocolMarshallerAux is an auxiliary struct used for Protocol JSON marshalling.
|
|
|
|
protocolMarshallerAux struct {
|
2021-09-07 12:42:04 +00:00
|
|
|
AddressVersion byte `json:"addressversion"`
|
|
|
|
Network netmode.Magic `json:"network"`
|
|
|
|
MillisecondsPerBlock int `json:"msperblock"`
|
|
|
|
MaxTraceableBlocks uint32 `json:"maxtraceableblocks"`
|
|
|
|
MaxValidUntilBlockIncrement uint32 `json:"maxvaliduntilblockincrement"`
|
|
|
|
MaxTransactionsPerBlock uint16 `json:"maxtransactionsperblock"`
|
|
|
|
MemoryPoolMaxTransactions int `json:"memorypoolmaxtransactions"`
|
2021-09-28 07:10:26 +00:00
|
|
|
ValidatorsCount byte `json:"validatorscount"`
|
2022-04-26 09:32:06 +00:00
|
|
|
InitialGasDistribution int64 `json:"initialgasdistribution"`
|
2022-08-08 13:10:02 +00:00
|
|
|
|
|
|
|
CommitteeHistory map[uint32]int `json:"committeehistory,omitempty"`
|
|
|
|
P2PSigExtensions bool `json:"p2psigextensions,omitempty"`
|
|
|
|
StateRootInHeader bool `json:"staterootinheader,omitempty"`
|
|
|
|
ValidatorsHistory map[uint32]int `json:"validatorshistory,omitempty"`
|
2022-04-26 09:32:06 +00:00
|
|
|
}
|
2018-03-23 20:36:59 +00:00
|
|
|
)
|
2022-04-26 09:32:06 +00:00
|
|
|
|
|
|
|
// MarshalJSON implements the json marshaller interface.
|
|
|
|
func (v *Version) MarshalJSON() ([]byte, error) {
|
|
|
|
aux := versionMarshallerAux{
|
|
|
|
TCPPort: v.TCPPort,
|
|
|
|
WSPort: v.WSPort,
|
|
|
|
Nonce: v.Nonce,
|
|
|
|
UserAgent: v.UserAgent,
|
|
|
|
Protocol: protocolMarshallerAux{
|
|
|
|
AddressVersion: v.Protocol.AddressVersion,
|
|
|
|
Network: v.Protocol.Network,
|
|
|
|
MillisecondsPerBlock: v.Protocol.MillisecondsPerBlock,
|
|
|
|
MaxTraceableBlocks: v.Protocol.MaxTraceableBlocks,
|
|
|
|
MaxValidUntilBlockIncrement: v.Protocol.MaxValidUntilBlockIncrement,
|
|
|
|
MaxTransactionsPerBlock: v.Protocol.MaxTransactionsPerBlock,
|
|
|
|
MemoryPoolMaxTransactions: v.Protocol.MemoryPoolMaxTransactions,
|
|
|
|
ValidatorsCount: v.Protocol.ValidatorsCount,
|
|
|
|
InitialGasDistribution: int64(v.Protocol.InitialGasDistribution),
|
2022-08-08 13:10:02 +00:00
|
|
|
|
|
|
|
CommitteeHistory: v.Protocol.CommitteeHistory,
|
|
|
|
P2PSigExtensions: v.Protocol.P2PSigExtensions,
|
|
|
|
StateRootInHeader: v.Protocol.StateRootInHeader,
|
|
|
|
ValidatorsHistory: v.Protocol.ValidatorsHistory,
|
2022-04-26 09:32:06 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
return json.Marshal(aux)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON implements the json unmarshaller interface.
|
|
|
|
func (v *Version) UnmarshalJSON(data []byte) error {
|
2022-11-10 13:49:38 +00:00
|
|
|
var aux versionMarshallerAux
|
2022-04-26 09:32:06 +00:00
|
|
|
err := json.Unmarshal(data, &aux)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.TCPPort = aux.TCPPort
|
|
|
|
v.WSPort = aux.WSPort
|
|
|
|
v.Nonce = aux.Nonce
|
|
|
|
v.UserAgent = aux.UserAgent
|
|
|
|
v.Protocol.AddressVersion = aux.Protocol.AddressVersion
|
|
|
|
v.Protocol.Network = aux.Protocol.Network
|
|
|
|
v.Protocol.MillisecondsPerBlock = aux.Protocol.MillisecondsPerBlock
|
|
|
|
v.Protocol.MaxTraceableBlocks = aux.Protocol.MaxTraceableBlocks
|
|
|
|
v.Protocol.MaxValidUntilBlockIncrement = aux.Protocol.MaxValidUntilBlockIncrement
|
|
|
|
v.Protocol.MaxTransactionsPerBlock = aux.Protocol.MaxTransactionsPerBlock
|
|
|
|
v.Protocol.MemoryPoolMaxTransactions = aux.Protocol.MemoryPoolMaxTransactions
|
|
|
|
v.Protocol.ValidatorsCount = aux.Protocol.ValidatorsCount
|
2022-08-08 13:10:02 +00:00
|
|
|
v.Protocol.CommitteeHistory = aux.Protocol.CommitteeHistory
|
|
|
|
v.Protocol.P2PSigExtensions = aux.Protocol.P2PSigExtensions
|
2022-04-26 09:32:06 +00:00
|
|
|
v.Protocol.StateRootInHeader = aux.Protocol.StateRootInHeader
|
2022-08-08 13:10:02 +00:00
|
|
|
v.Protocol.ValidatorsHistory = aux.Protocol.ValidatorsHistory
|
2022-11-10 13:49:38 +00:00
|
|
|
v.Protocol.InitialGasDistribution = fixedn.Fixed8(aux.Protocol.InitialGasDistribution)
|
2022-04-26 09:32:06 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|