wtmock

package
v0.0.0-...-e495a10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockConn

func NewMockConn(localPk, remotePk *btcec.PublicKey,
	localAddr, remoteAddr net.Addr,
	bufferSize int) (*MockPeer, *MockPeer)

NewMockConn establishes a bidirectional connection between two MockPeers.

Types

type ClientDB

type ClientDB struct {
	// contains filtered or unexported fields
}

ClientDB is a mock, in-memory database or testing the watchtower client behavior.

func NewClientDB

func NewClientDB() *ClientDB

NewClientDB initializes a new mock ClientDB.

func (*ClientDB) AckUpdate

func (m *ClientDB) AckUpdate(id *wtdb.SessionID, seqNum, lastApplied uint16) error

AckUpdate persists an acknowledgment for a given (session, seqnum) pair. This removes the update from the set of committed updates, and validates the lastApplied value returned from the tower.

func (*ClientDB) AddChanPkScript

func (m *ClientDB) AddChanPkScript(chanID lnwire.ChannelID, pkScript []byte) error

AddChanPkScript sets a pkscript or sweeping funds from the channel or chanID.

func (*ClientDB) CommitUpdate

func (m *ClientDB) CommitUpdate(id *wtdb.SessionID, seqNum uint16,
	update *wtdb.CommittedUpdate) (uint16, error)

CommitUpdate persists the CommittedUpdate provided in the slot for (session, seqNum). This allows the client to retransmit this update on startup.

func (*ClientDB) CreateClientSession

func (m *ClientDB) CreateClientSession(session *wtdb.ClientSession) error

CreateClientSession records a newly negotiated client session in the set of active sessions. The session can be identified by its SessionID.

func (*ClientDB) CreateTower

func (m *ClientDB) CreateTower(lnAddr *lnwire.NetAddress) (*wtdb.Tower, error)

CreateTower initializes a database entry with the given lightning address. If the tower exists, the address is append to the list of all addresses used to that tower previously.

func (*ClientDB) FetchChanPkScripts

func (m *ClientDB) FetchChanPkScripts() (map[lnwire.ChannelID][]byte, error)

FetchChanPkScripts returns the set of sweep pkscripts known for all channels. This allows the client to cache them in memory on startup.

func (*ClientDB) ListClientSessions

func (m *ClientDB) ListClientSessions() (map[wtdb.SessionID]*wtdb.ClientSession, error)

ListClientSessions returns the set of all client sessions known to the db.

func (*ClientDB) MarkBackupIneligible

func (m *ClientDB) MarkBackupIneligible(chanID lnwire.ChannelID, commitHeight uint64) error

MarkBackupIneligible records that particular commit height is ineligible for backup. This allows the client to track which updates it should not attempt to retry after startup.

type MockPeer

type MockPeer struct {
	IncomingMsgs chan []byte
	OutgoingMsgs chan []byte

	RemoteQuit chan struct{}
	Quit       chan struct{}
	// contains filtered or unexported fields
}

MockPeer emulates a single endpoint of brontide transport.

func NewMockPeer

func NewMockPeer(lpk, rpk *btcec.PublicKey, addr net.Addr,
	bufferSize int) *MockPeer

NewMockPeer returns a fresh MockPeer.

func (*MockPeer) Close

func (p *MockPeer) Close() error

Close tearsdown the connection, and fails any pending reads or writes.

func (*MockPeer) LocalAddr

func (p *MockPeer) LocalAddr() net.Addr

LocalAddr returns the local net address of the peer.

func (*MockPeer) Read

func (p *MockPeer) Read(dst []byte) (int, error)

Read is not implemented.

func (*MockPeer) ReadNextMessage

func (p *MockPeer) ReadNextMessage() ([]byte, error)

ReadNextMessage returns the raw bytes of the next full message read from the remote peer. The read will fail if either party closes the connection or the read deadline expires.

func (*MockPeer) RemoteAddr

func (p *MockPeer) RemoteAddr() net.Addr

RemoteAddr returns the net address of the remote peer.

func (*MockPeer) RemotePub

func (p *MockPeer) RemotePub() *btcec.PublicKey

RemotePub returns the public key of the remote peer.

func (*MockPeer) SetDeadline

func (p *MockPeer) SetDeadline(t time.Time) error

SetDeadline is not implemented.

func (*MockPeer) SetReadDeadline

func (p *MockPeer) SetReadDeadline(t time.Time) error

SetReadDeadline initializes a timer that will cause any pending reads to fail at time t. If t is zero, the deadline is infinite.

func (*MockPeer) SetWriteDeadline

func (p *MockPeer) SetWriteDeadline(t time.Time) error

SetWriteDeadline initializes a timer that will cause any pending writes to fail at time t. If t is zero, the deadline is infinite.

func (*MockPeer) Write

func (p *MockPeer) Write(b []byte) (n int, err error)

Write sends the raw bytes as the next full message read to the remote peer. The write will fail if either party closes the connection or the write deadline expires. The passed bytes slice is copied before sending, thus the bytes may be reused once the method returns.

type MockSigner

type MockSigner struct {
	// contains filtered or unexported fields
}

MockSigner is an input.Signer that allows one to add arbitrary private keys and sign messages by passing the assigned keychain.KeyLocator.

func NewMockSigner

func NewMockSigner() *MockSigner

NewMockSigner returns a fresh MockSigner.

func (*MockSigner) AddPrivKey

func (s *MockSigner) AddPrivKey(privKey *btcec.PrivateKey) keychain.KeyLocator

AddPrivKey records the passed privKey in the MockSigner's registry of keys it can sign with in the future. A unique key locator is returned, allowing the caller to sign with this key when presented via an input.SignDescriptor.

func (*MockSigner) ComputeInputScript

func (s *MockSigner) ComputeInputScript(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) (*input.Script, error)

ComputeInputScript is not implemented.

func (*MockSigner) SignOutputRaw

func (s *MockSigner) SignOutputRaw(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) ([]byte, error)

SignOutputRaw signs an input on the passed transaction using the input index in the sign descriptor. The returned signature is the raw DER-encoded signature without the signhash flag.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL