From 2ebe2017faba69029c1451e8e73587df9491879b Mon Sep 17 00:00:00 2001 From: Diego Masini Date: Tue, 30 Jul 2019 15:08:28 -0300 Subject: [PATCH] swap: cast handshake message in run() function before using it in constructors. --- swap/protocol.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/swap/protocol.go b/swap/protocol.go index cf8d887860..30fdac39b2 100644 --- a/swap/protocol.go +++ b/swap/protocol.go @@ -99,19 +99,24 @@ func (s *Swap) verifyHandshake(msg interface{}) error { func (s *Swap) run(p *p2p.Peer, rw p2p.MsgReadWriter) error { protoPeer := protocols.NewPeer(p, rw, Spec) - answer, err := protoPeer.Handshake(context.TODO(), &HandshakeMsg{ + handshake, err := protoPeer.Handshake(context.TODO(), &HandshakeMsg{ ContractAddress: s.owner.Contract, }, s.verifyHandshake) if err != nil { return err } - beneficiary, err := s.getContractOwner(context.TODO(), answer.(*HandshakeMsg).ContractAddress) + answer, ok := handshake.(*HandshakeMsg) + if !ok { + return ErrInvalidHandshakeMsg + } + + beneficiary, err := s.getContractOwner(context.TODO(), answer.ContractAddress) if err != nil { return err } - swapPeer := NewPeer(protoPeer, s, s.backend, beneficiary, answer.(*HandshakeMsg).ContractAddress) + swapPeer := NewPeer(protoPeer, s, s.backend, beneficiary, answer.ContractAddress) s.addPeer(swapPeer) defer s.removePeer(swapPeer)