diff --git a/netaddress.go b/netaddress.go index b8db7468..446a9939 100644 --- a/netaddress.go +++ b/netaddress.go @@ -72,6 +72,18 @@ func (na *NetAddress) SetAddress(ip net.IP, port uint16) { na.Port = port } +// NewNetAddressIPPort returns a new NetAddress using the provided IP, port, and +// supported services with defaults for the remaining fields. +func NewNetAddressIPPort(ip net.IP, port uint16, services ServiceFlag) *NetAddress { + na := NetAddress{ + Timestamp: time.Now(), + Services: services, + IP: ip, + Port: port, + } + return &na +} + // NewNetAddress returns a new NetAddress using the provided TCP address and // supported services with defaults for the remaining fields. // @@ -83,13 +95,8 @@ func NewNetAddress(addr net.Addr, services ServiceFlag) (*NetAddress, error) { return nil, ErrInvalidNetAddr } - na := NetAddress{ - Timestamp: time.Now(), - Services: services, - IP: tcpAddr.IP, - Port: uint16(tcpAddr.Port), - } - return &na, nil + na := NewNetAddressIPPort(tcpAddr.IP, uint16(tcpAddr.Port), services) + return na, nil } // readNetAddress reads an encoded NetAddress from r depending on the protocol diff --git a/test_coverage.txt b/test_coverage.txt index 0d93c31f..7a6c0081 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,10 +1,10 @@ github.com/conformal/btcwire/message.go ReadMessage 100.00% (37/37) github.com/conformal/btcwire/message.go WriteMessage 100.00% (31/31) -github.com/conformal/btcwire/msgtx.go MsgTx.BtcDecode 100.00% (25/25) github.com/conformal/btcwire/msgversion.go MsgVersion.BtcDecode 100.00% (25/25) -github.com/conformal/btcwire/msgtx.go MsgTx.Copy 100.00% (24/24) +github.com/conformal/btcwire/msgtx.go MsgTx.BtcDecode 100.00% (25/25) github.com/conformal/btcwire/common.go readVarInt 100.00% (24/24) +github.com/conformal/btcwire/msgtx.go MsgTx.Copy 100.00% (24/24) github.com/conformal/btcwire/msgtx.go MsgTx.BtcEncode 100.00% (23/23) github.com/conformal/btcwire/msgversion.go MsgVersion.BtcEncode 100.00% (22/22) github.com/conformal/btcwire/message.go makeEmptyMessage 100.00% (20/20) @@ -32,12 +32,12 @@ github.com/conformal/btcwire/protocol.go ServiceFlag.String 100.00% (12/12) github.com/conformal/btcwire/msggetdata.go MsgGetData.BtcEncode 100.00% (12/12) github.com/conformal/btcwire/msgnotfound.go MsgNotFound.BtcEncode 100.00% (12/12) github.com/conformal/btcwire/msgtx.go writeTxOut 100.00% (11/11) -github.com/conformal/btcwire/message.go discardInput 100.00% (10/10) github.com/conformal/btcwire/msgblock.go MsgBlock.BtcDecode 100.00% (10/10) github.com/conformal/btcwire/blockheader.go readBlockHeader 100.00% (10/10) +github.com/conformal/btcwire/message.go discardInput 100.00% (10/10) github.com/conformal/btcwire/msgblock.go MsgBlock.BtcEncode 100.00% (9/9) -github.com/conformal/btcwire/common.go readVarString 100.00% (8/8) github.com/conformal/btcwire/blockheader.go writeBlockHeader 100.00% (8/8) +github.com/conformal/btcwire/common.go readVarString 100.00% (8/8) github.com/conformal/btcwire/msgalert.go MsgAlert.BtcEncode 100.00% (8/8) github.com/conformal/btcwire/msgalert.go MsgAlert.BtcDecode 100.00% (8/8) github.com/conformal/btcwire/common.go writeVarString 100.00% (7/7) @@ -75,16 +75,16 @@ github.com/conformal/btcwire/msgtx.go readOutPoint 100.00% (4/4) github.com/conformal/btcwire/msgtx.go writeOutPoint 100.00% (4/4) github.com/conformal/btcwire/netaddress.go maxNetAddressPayload 100.00% (4/4) github.com/conformal/btcwire/shahash.go ShaHash.String 100.00% (4/4) +github.com/conformal/btcwire/shahash.go ShaHash.Bytes 100.00% (3/3) github.com/conformal/btcwire/error.go MessageError.Error 100.00% (3/3) github.com/conformal/btcwire/msgversion.go MsgVersion.HasService 100.00% (3/3) -github.com/conformal/btcwire/msgblock.go MsgBlock.AddTransaction 100.00% (3/3) -github.com/conformal/btcwire/shahash.go ShaHash.Bytes 100.00% (3/3) -github.com/conformal/btcwire/invvect.go InvType.String 100.00% (3/3) github.com/conformal/btcwire/msgaddr.go MsgAddr.MaxPayloadLength 100.00% (3/3) github.com/conformal/btcwire/netaddress.go NetAddress.HasService 100.00% (3/3) +github.com/conformal/btcwire/msgblock.go MsgBlock.AddTransaction 100.00% (3/3) +github.com/conformal/btcwire/invvect.go InvType.String 100.00% (3/3) github.com/conformal/btcwire/msgblock.go MsgBlock.ClearTransactions 100.00% (2/2) github.com/conformal/btcwire/netaddress.go NetAddress.SetAddress 100.00% (2/2) -github.com/conformal/btcwire/msginv.go NewMsgInv 100.00% (1/1) +github.com/conformal/btcwire/netaddress.go NewNetAddressIPPort 100.00% (2/2) github.com/conformal/btcwire/common.go RandomUint64 100.00% (1/1) github.com/conformal/btcwire/common.go writeElement 100.00% (1/1) github.com/conformal/btcwire/msgmempool.go MsgMemPool.Command 100.00% (1/1) @@ -153,5 +153,6 @@ github.com/conformal/btcwire/msggetaddr.go MsgGetAddr.Command 100.00% (1/1) github.com/conformal/btcwire/msggetaddr.go MsgGetAddr.BtcEncode 100.00% (1/1) github.com/conformal/btcwire/msginv.go MsgInv.Command 100.00% (1/1) github.com/conformal/btcwire/msginv.go MsgInv.MaxPayloadLength 100.00% (1/1) -github.com/conformal/btcwire --------------------------------- 100.00% (930/930) +github.com/conformal/btcwire/msginv.go NewMsgInv 100.00% (1/1) +github.com/conformal/btcwire --------------------------------- 100.00% (932/932)