From fd334b37380ddd71952944c661bb5b3a3e20713f Mon Sep 17 00:00:00 2001 From: Loong Date: Wed, 2 Sep 2020 13:54:17 +1000 Subject: [PATCH] add network type --- multichain.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/multichain.go b/multichain.go index 0b9b79a6..e20f8a6f 100644 --- a/multichain.go +++ b/multichain.go @@ -197,3 +197,29 @@ func (chainType ChainType) Marshal(buf []byte, rem int) ([]byte, int, error) { func (chainType *ChainType) Unmarshal(buf []byte, rem int) ([]byte, int, error) { return surge.UnmarshalString((*string)(chainType), buf, rem) } + +type Network string + +const ( + NetworkLocalnet = Network("localnet") + NetworkTestnet = Network("testnet") + NetworkMainnet = Network("mainnet") +) + +// SizeHint returns the number of bytes required to represent the network in +// binary. +func (net Network) SizeHint() int { + return surge.SizeHintString(string(net)) +} + +// Marshal the network to binary. You should not call this function directly, +// unless you are implementing marshalling for a container type. +func (net Network) Marshal(buf []byte, rem int) ([]byte, int, error) { + return surge.MarshalString(string(net), buf, rem) +} + +// Unmarshal the network from binary. You should not call this function +// directly, unless you are implementing unmarshalling for a container type. +func (net *Network) Unmarshal(buf []byte, rem int) ([]byte, int, error) { + return surge.UnmarshalString((*string)(net), buf, rem) +}