To show how you can use transaction propagation as part of Mevlink streamer-go we'll continue working off of the /mevlink/stream.go code we worked through in the Transaction Streamstep.
This is what stream.go looks like at this point:
// mevlink/stream.gopackagemainimport ("encoding/hex""log""time" mlstreamer "github.com/mevlink/streamer-go""golang.org/x/crypto/sha3")funcmain() {// create streamervar str = mlstreamer.NewStreamer("<api-key-id>", "<api-key-secret>", 1)// transaction callback str.OnTransaction(func(txb []byte, noticed, propagated time.Time) {//Getting the transaction hash and printing the relevant timesvar hasher = sha3.NewLegacyKeccak256() hasher.Write(txb)var tx_hash = hasher.Sum(nil) log.Println("Got tx '" + hex.EncodeToString(tx_hash) + "'! Was noticed on ", noticed, "and sent on", propagated)
}) log.Fatal(str.Stream())}
New imports
We'll import a few more packages to help encode / decode the RLP in case you'd like to do some validation.
To test propagation, we'll add a little call to emmit two transactions and close the streamer once those have been emitted as well as log any emission errors we get.
We'll first add a counter where we instantiate the streamer: