From fcc949a5b20d1be2b3a6ebb7022ab9abb28335e7 Mon Sep 17 00:00:00 2001 From: capossele <angelocapossele@gmail.com> Date: Wed, 18 Dec 2019 15:40:17 +0000 Subject: [PATCH] :bug: fixes unmarshaling of tx hash --- plugins/gossip/gossip.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go index 2d549ce9..4691f4e5 100644 --- a/plugins/gossip/gossip.go +++ b/plugins/gossip/gossip.go @@ -1,6 +1,8 @@ package gossip import ( + "errors" + "github.com/golang/protobuf/proto" zL "github.com/iotaledger/autopeering-sim/logger" "github.com/iotaledger/autopeering-sim/peer/service" @@ -44,9 +46,10 @@ var ( ) func getTransaction(h []byte) ([]byte, error) { + log.Info("Retrieving tx:", string(h)) tx, err := tangle.GetTransaction(string(h)) - if err != nil { - return []byte{}, err + if err != nil || tx == nil { + return []byte{}, errors.New("Not found") } pTx := &pb.TransactionRequest{ Hash: tx.GetBytes(), @@ -92,7 +95,7 @@ func configureEvents() { })) tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { - log.Info("Tx solidified:", tx.MetaTransaction.GetBytes()) + log.Info("Tx solidified:", tx.MetaTransaction.GetHash()) t := &pb.Transaction{ Body: tx.MetaTransaction.GetBytes(), } @@ -104,7 +107,9 @@ func configureEvents() { })) gossip.Events.RequestTransaction.Attach(events.NewClosure(func(ev *gossip.RequestTransactionEvent) { - log.Info("Tx Requested:", ev.Hash) - go mgr.RequestTransaction(ev.Hash) + pTx := &pb.TransactionRequest{} + proto.Unmarshal(ev.Hash, pTx) + log.Info("Tx Requested:", string(pTx.Hash)) + go mgr.RequestTransaction(pTx.Hash) })) } -- GitLab