github.com/annchain/OG@v0.0.9/og/syncer/announcer.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package syncer 15 16 import ( 17 "github.com/annchain/OG/consensus/campaign" 18 "github.com/annchain/OG/og/archive" 19 "github.com/annchain/OG/og/types" 20 archive2 "github.com/annchain/OG/og/types/archive" 21 ) 22 23 type Announcer struct { 24 messageSender MessageSender 25 } 26 27 func NewAnnouncer(messageSender MessageSender) *Announcer { 28 return &Announcer{ 29 messageSender: messageSender, 30 } 31 } 32 33 //BroadcastNewTx brodcast newly created txi message 34 func (m *Announcer) BroadcastNewTx(txi types.Txi) { 35 switch tx := txi.(type) { 36 case *archive2.Tx: 37 msgTx := archive2.MessageNewTx{RawTx: tx.RawTx()} 38 m.messageSender.BroadcastMessageWithLink(archive2.MessageTypeNewTx, &msgTx) 39 case *types.Sequencer: 40 msgTx := archive2.MessageNewSequencer{RawSequencer: tx.RawSequencer()} 41 m.messageSender.BroadcastMessageWithLink(archive2.MessageTypeNewSequencer, &msgTx) 42 case *campaign.Campaign: 43 msg := types.MessageCampaign{ 44 RawCampaign: tx.RawCampaign(), 45 } 46 m.messageSender.BroadcastMessage(types.MessageTypeCampaign, &msg) 47 case *campaign.TermChange: 48 msg := types.MessageTermChange{ 49 RawTermChange: tx.RawTermChange(), 50 } 51 m.messageSender.BroadcastMessage(types.MessageTypeTermChange, &msg) 52 53 case *archive.Archive: 54 msg := types.MessageNewArchive{ 55 Archive: tx, 56 } 57 m.messageSender.BroadcastMessage(archive2.MessageTypeArchive, &msg) 58 case *archive2.ActionTx: 59 msg := archive2.MessageNewActionTx{ 60 ActionTx: tx, 61 } 62 m.messageSender.BroadcastMessage(archive2.MessageTypeActionTX, &msg) 63 64 default: 65 log.Warn("never come here, unknown tx type ", tx) 66 } 67 }