refactor: move Data to be accessed via Bytes and Raw

This commit is contained in:
Derrick Hammer 2024-01-06 06:33:23 -05:00
parent 785d4029e9
commit 8d1bdd87ac
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 5 deletions

View File

@ -15,11 +15,15 @@ var (
type NodeIdCode = int type NodeIdCode = int
type NodeId struct { type NodeId struct {
Bytes []byte bytes []byte
}
func (nodeId *NodeId) Bytes() []byte {
return nodeId.bytes
} }
func NewNodeId(bytes []byte) *NodeId { func NewNodeId(bytes []byte) *NodeId {
return &NodeId{Bytes: bytes} return &NodeId{bytes: bytes}
} }
func DecodeNodeId(nodeId string) (*NodeId, error) { func DecodeNodeId(nodeId string) (*NodeId, error) {
@ -37,19 +41,23 @@ func DecodeNodeId(nodeId string) (*NodeId, error) {
func (nodeId *NodeId) Equals(other interface{}) bool { func (nodeId *NodeId) Equals(other interface{}) bool {
if otherNodeId, ok := other.(*NodeId); ok { if otherNodeId, ok := other.(*NodeId); ok {
return bytes.Equal(nodeId.Bytes, otherNodeId.Bytes) return bytes.Equal(nodeId.bytes, otherNodeId.bytes)
} }
return false return false
} }
func (nodeId *NodeId) HashCode() int { func (nodeId *NodeId) HashCode() int {
return utils.HashCode(nodeId.Bytes[:4]) return utils.HashCode(nodeId.bytes[:4])
} }
func (nodeId *NodeId) ToBase58() (string, error) { func (nodeId *NodeId) ToBase58() (string, error) {
return bases.ToBase58BTC(nodeId.Bytes) return bases.ToBase58BTC(nodeId.bytes)
} }
func (nodeId *NodeId) ToString() (string, error) { func (nodeId *NodeId) ToString() (string, error) {
return nodeId.ToBase58() return nodeId.ToBase58()
} }
func (nodeId *NodeId) Raw() []byte {
return nodeId.bytes[1:]
}