mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-510] Change coinbase flags to kaspad. * [NOD-510] Removed superfluous spaces after periods in comments. * [NOD-510] Rename btcd -> kaspad in the root folder. * [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode. * [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode. * [NOD-510] Continue renaming btcd -> kaspad. * [NOD-510] Rename btcjson -> kaspajson. * [NOD-510] Rename file names inside kaspajson. * [NOD-510] Rename kaspajson -> jsonrpc. * [NOD-510] Finish renaming in addrmgr. * [NOD-510] Rename package btcec to ecc. * [NOD-510] Finish renaming stuff in blockdag. * [NOD-510] Rename stuff in cmd. * [NOD-510] Rename stuff in config. * [NOD-510] Rename stuff in connmgr. * [NOD-510] Rename stuff in dagconfig. * [NOD-510] Rename stuff in database. * [NOD-510] Rename stuff in docker. * [NOD-510] Rename stuff in integration. * [NOD-510] Rename jsonrpc to rpcmodel. * [NOD-510] Rename stuff in limits. * [NOD-510] Rename stuff in logger. * [NOD-510] Rename stuff in mempool. * [NOD-510] Rename stuff in mining. * [NOD-510] Rename stuff in netsync. * [NOD-510] Rename stuff in peer. * [NOD-510] Rename stuff in release. * [NOD-510] Rename stuff in rpcclient. * [NOD-510] Rename stuff in server. * [NOD-510] Rename stuff in signal. * [NOD-510] Rename stuff in txscript. * [NOD-510] Rename stuff in util. * [NOD-510] Rename stuff in wire. * [NOD-510] Fix failing tests. * [NOD-510] Fix merge errors. * [NOD-510] Fix go vet errors. * [NOD-510] Remove merged file that's no longer relevant. * [NOD-510] Add a comment above Op0. * [NOD-510] Fix some comments referencing Bitcoin Core. * [NOD-510] Fix some more comments referencing Bitcoin Core. * [NOD-510] Fix bitcoin -> kaspa. * [NOD-510] Fix more bitcoin -> kaspa. * [NOD-510] Fix comments, remove DisconnectBlock in addrindex. * [NOD-510] Rename KSPD to KASD. * [NOD-510] Fix comments and user agent.
134 lines
3.2 KiB
Go
134 lines
3.2 KiB
Go
// Copyright (c) 2013-2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package wire
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// XXX pedro: we will probably need to bump this.
|
|
const (
|
|
// ProtocolVersion is the latest protocol version this package supports.
|
|
ProtocolVersion uint32 = 1
|
|
)
|
|
|
|
// ServiceFlag identifies services supported by a kaspa peer.
|
|
type ServiceFlag uint64
|
|
|
|
const (
|
|
// SFNodeNetwork is a flag used to indicate a peer is a full node.
|
|
SFNodeNetwork ServiceFlag = 1 << iota
|
|
|
|
// SFNodeGetUTXO is a flag used to indicate a peer supports the
|
|
// getutxos and utxos commands (BIP0064).
|
|
SFNodeGetUTXO
|
|
|
|
// SFNodeBloom is a flag used to indicate a peer supports bloom
|
|
// filtering.
|
|
SFNodeBloom
|
|
|
|
// SFNodeXthin is a flag used to indicate a peer supports xthin blocks.
|
|
SFNodeXthin
|
|
|
|
// SFNodeBit5 is a flag used to indicate a peer supports a service
|
|
// defined by bit 5.
|
|
SFNodeBit5
|
|
|
|
// SFNodeCF is a flag used to indicate a peer supports committed
|
|
// filters (CFs).
|
|
SFNodeCF
|
|
)
|
|
|
|
// Map of service flags back to their constant names for pretty printing.
|
|
var sfStrings = map[ServiceFlag]string{
|
|
SFNodeNetwork: "SFNodeNetwork",
|
|
SFNodeGetUTXO: "SFNodeGetUTXO",
|
|
SFNodeBloom: "SFNodeBloom",
|
|
SFNodeXthin: "SFNodeXthin",
|
|
SFNodeBit5: "SFNodeBit5",
|
|
SFNodeCF: "SFNodeCF",
|
|
}
|
|
|
|
// orderedSFStrings is an ordered list of service flags from highest to
|
|
// lowest.
|
|
var orderedSFStrings = []ServiceFlag{
|
|
SFNodeNetwork,
|
|
SFNodeGetUTXO,
|
|
SFNodeBloom,
|
|
SFNodeXthin,
|
|
SFNodeBit5,
|
|
SFNodeCF,
|
|
}
|
|
|
|
// String returns the ServiceFlag in human-readable form.
|
|
func (f ServiceFlag) String() string {
|
|
// No flags are set.
|
|
if f == 0 {
|
|
return "0x0"
|
|
}
|
|
|
|
// Add individual bit flags.
|
|
s := ""
|
|
for _, flag := range orderedSFStrings {
|
|
if f&flag == flag {
|
|
s += sfStrings[flag] + "|"
|
|
f -= flag
|
|
}
|
|
}
|
|
|
|
// Add any remaining flags which aren't accounted for as hex.
|
|
s = strings.TrimRight(s, "|")
|
|
if f != 0 {
|
|
s += "|0x" + strconv.FormatUint(uint64(f), 16)
|
|
}
|
|
s = strings.TrimLeft(s, "|")
|
|
return s
|
|
}
|
|
|
|
// KaspaNet represents which kaspa network a message belongs to.
|
|
type KaspaNet uint32
|
|
|
|
// Constants used to indicate the message kaspa network. They can also be
|
|
// used to seek to the next message when a stream's state is unknown, but
|
|
// this package does not provide that functionality since it's generally a
|
|
// better idea to simply disconnect clients that are misbehaving over TCP.
|
|
const (
|
|
// MainNet represents the main kaspa network.
|
|
MainNet KaspaNet = 0xd9b4bef9
|
|
|
|
// TestNet represents the test network.
|
|
TestNet KaspaNet = 0x0709110b
|
|
|
|
// RegTest represents the regression test network.
|
|
RegTest KaspaNet = 0xdab5bffa
|
|
|
|
// SimNet represents the simulation test network.
|
|
SimNet KaspaNet = 0x12141c16
|
|
|
|
// DevNet represents the development test network.
|
|
DevNet KaspaNet = 0x01020304
|
|
)
|
|
|
|
// bnStrings is a map of kaspa networks back to their constant names for
|
|
// pretty printing.
|
|
var bnStrings = map[KaspaNet]string{
|
|
MainNet: "MainNet",
|
|
TestNet: "TestNet",
|
|
RegTest: "RegTest",
|
|
SimNet: "SimNet",
|
|
DevNet: "DevNet",
|
|
}
|
|
|
|
// String returns the KaspaNet in human-readable form.
|
|
func (n KaspaNet) String() string {
|
|
if s, ok := bnStrings[n]; ok {
|
|
return s
|
|
}
|
|
|
|
return fmt.Sprintf("Unknown KaspaNet (%d)", uint32(n))
|
|
}
|