github.com/annchain/OG@v0.0.9/og/protocol/ogmessage/archive/messages.go (about) 1 package archive 2 3 import ( 4 "fmt" 5 "github.com/annchain/OG/arefactor/og/types" 6 "github.com/annchain/OG/consensus/annsensus" 7 "github.com/annchain/OG/og/protocol/dagmessage" 8 "github.com/annchain/OG/types/msg" 9 ) 10 11 //go:generate msgp 12 13 //msgp:tuple MessagePing 14 type MessagePing struct{} 15 16 func (z MessagePing) String() string { 17 return "MessageTypePing" 18 } 19 20 func (m *MessagePing) GetType() msg.BinaryMessageType { 21 return MessageTypePing 22 } 23 24 func (m *MessagePing) GetData() []byte { 25 return []byte{} 26 } 27 28 func (m *MessagePing) ToBinary() msg.BinaryMessage { 29 return msg.BinaryMessage{ 30 Type: m.GetType(), 31 Data: m.GetData(), 32 } 33 } 34 35 func (z *MessagePing) FromBinary([]byte) error { 36 // do nothing since the array is always empty 37 return nil 38 } 39 40 //msgp:tuple MessagePong 41 type MessagePong struct{} 42 43 func (m *MessagePong) String() string { 44 return "MessageTypePong" 45 } 46 47 func (m *MessagePong) GetType() msg.BinaryMessageType { 48 return MessageTypePong 49 } 50 51 func (m *MessagePong) GetData() []byte { 52 return []byte{} 53 } 54 55 func (m *MessagePong) ToBinary() msg.BinaryMessage { 56 return msg.BinaryMessage{ 57 Type: m.GetType(), 58 Data: m.GetData(), 59 } 60 } 61 62 func (z *MessagePong) FromBinary([]byte) error { 63 // do nothing since the array is always empty 64 return nil 65 } 66 67 //msgp:tuple MessageSyncRequest 68 type MessageSyncRequest struct { 69 Hashes *types.Hashes 70 HashTerminats *HashTerminats 71 Filter *BloomFilter 72 Height *uint64 73 RequestId uint32 //avoid msg drop 74 } 75 76 func (m *MessageSyncRequest) GetType() msg.BinaryMessageType { 77 return MessageTypeSyncRequest 78 } 79 80 func (m *MessageSyncRequest) GetData() []byte { 81 b, err := m.MarshalMsg(nil) 82 if err != nil { 83 panic(err) 84 } 85 return b 86 } 87 88 func (m *MessageSyncRequest) ToBinary() msg.BinaryMessage { 89 return msg.BinaryMessage{ 90 Type: m.GetType(), 91 Data: m.GetData(), 92 } 93 } 94 95 func (m *MessageSyncRequest) FromBinary(bs []byte) error { 96 _, err := m.UnmarshalMsg(bs) 97 return err 98 } 99 100 func (m *MessageSyncRequest) String() string { 101 var str string 102 if m.Filter != nil { 103 str = fmt.Sprintf("count: %d", m.Filter.GetCount()) 104 } 105 if m.Hashes != nil { 106 str += fmt.Sprintf("hash num %v", m.Hashes.String()) 107 } 108 if m.HashTerminats != nil { 109 str += fmt.Sprintf("hashterminates %v ", m.HashTerminats.String()) 110 } 111 str += fmt.Sprintf(" requestId %d ", m.RequestId) 112 return str 113 } 114 115 //msgp:tuple MessageSyncResponse 116 type MessageSyncResponse struct { 117 //RawTxs *RawTxs 118 ////SequencerIndex []uint32 119 //RawSequencers *RawSequencers 120 //RawCampaigns *RawCampaigns 121 //RawTermChanges *RawTermChanges 122 RawTxs *TxisMarshaler 123 RequestedId uint32 //avoid msg drop 124 } 125 126 func (m *MessageSyncResponse) GetType() msg.BinaryMessageType { 127 return MessageTypeSyncResponse 128 } 129 130 func (m *MessageSyncResponse) GetData() []byte { 131 b, err := m.MarshalMsg(nil) 132 if err != nil { 133 panic(err) 134 } 135 return b 136 } 137 138 func (m *MessageSyncResponse) ToBinary() msg.BinaryMessage { 139 return msg.BinaryMessage{ 140 Type: m.GetType(), 141 Data: m.GetData(), 142 } 143 } 144 145 func (m *MessageSyncResponse) FromBinary(bs []byte) error { 146 _, err := m.UnmarshalMsg(bs) 147 return err 148 } 149 150 func (m *MessageSyncResponse) String() string { 151 //for _,i := range m.SequencerIndex { 152 //index = append(index ,fmt.Sprintf("%d",i)) 153 //} 154 return fmt.Sprintf("txs: [%s],requestedId :%d", m.RawTxs.String(), m.RequestedId) 155 } 156 157 //msgp:tuple MessageNewTx 158 type MessageNewTx struct { 159 RawTx *RawTx 160 } 161 162 func (m *MessageNewTx) GetType() msg.BinaryMessageType { 163 return MessageTypeNewTx 164 } 165 166 func (m *MessageNewTx) GetData() []byte { 167 b, err := m.MarshalMsg(nil) 168 if err != nil { 169 panic(err) 170 } 171 return b 172 } 173 174 func (m *MessageNewTx) ToBinary() msg.BinaryMessage { 175 return msg.BinaryMessage{ 176 Type: m.GetType(), 177 Data: m.GetData(), 178 } 179 } 180 181 func (m *MessageNewTx) FromBinary(bs []byte) error { 182 _, err := m.UnmarshalMsg(bs) 183 return err 184 } 185 186 //msgp:tuple MessageNewSequencer 187 type MessageNewSequencer struct { 188 RawSequencer *RawSequencer 189 //Filter *BloomFilter 190 //Hop uint8 191 } 192 193 func (m *MessageNewSequencer) GetType() msg.BinaryMessageType { 194 return MessageTypeNewSequencer 195 } 196 197 func (m *MessageNewSequencer) GetData() []byte { 198 b, err := m.MarshalMsg(nil) 199 if err != nil { 200 panic(err) 201 } 202 return b 203 } 204 205 func (m *MessageNewSequencer) ToBinary() msg.BinaryMessage { 206 return msg.BinaryMessage{ 207 Type: m.GetType(), 208 Data: m.GetData(), 209 } 210 } 211 212 func (m *MessageNewSequencer) FromBinary(bs []byte) error { 213 _, err := m.UnmarshalMsg(bs) 214 return err 215 } 216 217 //msgp:tuple MessageNewTxs 218 type MessageNewTxs struct { 219 RawTxs *RawTxs 220 } 221 222 func (m *MessageNewTxs) GetType() msg.BinaryMessageType { 223 return MessageTypeNewTxs 224 } 225 226 func (m *MessageNewTxs) GetData() []byte { 227 b, err := m.MarshalMsg(nil) 228 if err != nil { 229 panic(err) 230 } 231 return b 232 } 233 234 func (m *MessageNewTxs) ToBinary() msg.BinaryMessage { 235 return msg.BinaryMessage{ 236 Type: m.GetType(), 237 Data: m.GetData(), 238 } 239 } 240 241 func (m *MessageNewTxs) FromBinary(bs []byte) error { 242 _, err := m.UnmarshalMsg(bs) 243 return err 244 } 245 246 func (m *MessageNewTxs) String() string { 247 return m.RawTxs.String() 248 } 249 250 //msgp:tuple MessageTxsRequest 251 type MessageTxsRequest struct { 252 Hashes *types.Hashes 253 SeqHash *types.Hash 254 Id *uint64 255 RequestId uint32 //avoid msg drop 256 } 257 258 func (z *MessageTxsRequest) GetType() msg.BinaryMessageType { 259 return MessageTypeTxsRequest 260 } 261 262 func (m *MessageTxsRequest) GetData() []byte { 263 b, err := m.MarshalMsg(nil) 264 if err != nil { 265 panic(err) 266 } 267 return b 268 } 269 270 func (m *MessageTxsRequest) ToBinary() msg.BinaryMessage { 271 return msg.BinaryMessage{ 272 Type: m.GetType(), 273 Data: m.GetData(), 274 } 275 } 276 277 func (m *MessageTxsRequest) FromBinary(bs []byte) error { 278 _, err := m.UnmarshalMsg(bs) 279 return err 280 } 281 282 func (m *MessageTxsRequest) String() string { 283 return fmt.Sprintf("hashes: [%s], seqHash: %s, id : %d, requstId : %d", m.Hashes.String(), m.SeqHash.String(), m.Id, m.RequestId) 284 } 285 286 //msgp:tuple MessageTxsResponse 287 type MessageTxsResponse struct { 288 //RawTxs *RawTxs 289 RawSequencer *RawSequencer 290 //RawCampaigns *RawCampaigns 291 //RawTermChanges *RawTermChanges 292 RawTxs *TxisMarshaler 293 RequestedId uint32 //avoid msg drop 294 } 295 296 func (m *MessageTxsResponse) GetType() msg.BinaryMessageType { 297 return MessageTypeTxsResponse 298 } 299 300 func (m *MessageTxsResponse) GetData() []byte { 301 b, err := m.MarshalMsg(nil) 302 if err != nil { 303 panic(err) 304 } 305 return b 306 } 307 308 func (m *MessageTxsResponse) ToBinary() msg.BinaryMessage { 309 return msg.BinaryMessage{ 310 Type: m.GetType(), 311 Data: m.GetData(), 312 } 313 } 314 315 func (m *MessageTxsResponse) FromBinary(bs []byte) error { 316 _, err := m.UnmarshalMsg(bs) 317 return err 318 } 319 320 func (m *MessageTxsResponse) String() string { 321 return fmt.Sprintf("txs: [%s], Sequencer: %s, requestedId %d", m.RawTxs.String(), m.RawSequencer.String(), m.RequestedId) 322 } 323 324 // getBlockHeadersData represents a block header query. 325 //msgp:tuple MessageHeaderRequest 326 type MessageHeaderRequest struct { 327 Origin HashOrNumber // Block from which to retrieve headers 328 Amount uint64 // Maximum number of headers to retrieve 329 Skip uint64 // Blocks to skip between consecutive headers 330 Reverse bool // Query direction (false = rising towards latest, true = falling towards genesis) 331 RequestId uint32 //avoid msg drop 332 } 333 334 func (m *MessageHeaderRequest) GetType() msg.BinaryMessageType { 335 return MessageTypeHeaderRequest 336 } 337 338 func (m *MessageHeaderRequest) GetData() []byte { 339 b, err := m.MarshalMsg(nil) 340 if err != nil { 341 panic(err) 342 } 343 return b 344 } 345 346 func (m *MessageHeaderRequest) ToBinary() msg.BinaryMessage { 347 return msg.BinaryMessage{ 348 Type: m.GetType(), 349 Data: m.GetData(), 350 } 351 } 352 353 func (m *MessageHeaderRequest) FromBinary(bs []byte) error { 354 _, err := m.UnmarshalMsg(bs) 355 return err 356 } 357 358 func (m *MessageHeaderRequest) String() string { 359 return fmt.Sprintf("Origin: [%s],amount : %d ,skip : %d, reverse : %v, requestId :%d", m.Origin.String(), m.Amount, m.Skip, m.Reverse, m.RequestId) 360 361 } 362 363 //msgp:tuple MessageSequencerHeader 364 type MessageSequencerHeader struct { 365 Hash *types.Hash 366 Number *uint64 367 } 368 369 func (m *MessageSequencerHeader) GetType() msg.BinaryMessageType { 370 return MessageTypeSequencerHeader 371 } 372 373 func (m *MessageSequencerHeader) GetData() []byte { 374 b, err := m.MarshalMsg(nil) 375 if err != nil { 376 panic(err) 377 } 378 return b 379 } 380 381 func (m *MessageSequencerHeader) ToBinary() msg.BinaryMessage { 382 return msg.BinaryMessage{ 383 Type: m.GetType(), 384 Data: m.GetData(), 385 } 386 } 387 388 func (m *MessageSequencerHeader) FromBinary(bs []byte) error { 389 _, err := m.UnmarshalMsg(bs) 390 return err 391 } 392 393 func (m *MessageSequencerHeader) String() string { 394 return fmt.Sprintf("hash: %s, number : %d", m.Hash.String(), m.Number) 395 } 396 397 //msgp:tuple MessageHeaderResponse 398 type MessageHeaderResponse struct { 399 Headers *dagmessage.SequencerHeaders 400 RequestedId uint32 //avoid msg drop 401 } 402 403 func (m *MessageHeaderResponse) GetType() msg.BinaryMessageType { 404 return MessageTypeHeaderResponse 405 } 406 407 func (m *MessageHeaderResponse) GetData() []byte { 408 b, err := m.MarshalMsg(nil) 409 if err != nil { 410 panic(err) 411 } 412 return b 413 } 414 415 func (m *MessageHeaderResponse) ToBinary() msg.BinaryMessage { 416 return msg.BinaryMessage{ 417 Type: m.GetType(), 418 Data: m.GetData(), 419 } 420 } 421 422 func (m *MessageHeaderResponse) FromBinary(bs []byte) error { 423 _, err := m.UnmarshalMsg(bs) 424 return err 425 } 426 427 func (m *MessageHeaderResponse) String() string { 428 return fmt.Sprintf("headers: [%s] reuqestedId :%d", m.Headers.String(), m.RequestedId) 429 } 430 431 //msgp:tuple MessageBodiesRequest 432 type MessageBodiesRequest struct { 433 SeqHashes types.Hashes 434 RequestId uint32 //avoid msg drop 435 } 436 437 func (m *MessageBodiesRequest) GetType() msg.BinaryMessageType { 438 return MessageTypeBodiesRequest 439 } 440 441 func (m *MessageBodiesRequest) GetData() []byte { 442 b, err := m.MarshalMsg(nil) 443 if err != nil { 444 panic(err) 445 } 446 return b 447 } 448 449 func (m *MessageBodiesRequest) ToBinary() msg.BinaryMessage { 450 return msg.BinaryMessage{ 451 Type: m.GetType(), 452 Data: m.GetData(), 453 } 454 } 455 456 func (m *MessageBodiesRequest) FromBinary(bs []byte) error { 457 _, err := m.UnmarshalMsg(bs) 458 return err 459 } 460 461 func (m *MessageBodiesRequest) String() string { 462 return m.SeqHashes.String() + fmt.Sprintf(" requestId :%d", m.RequestId) 463 } 464 465 //msgp:tuple MessageBodiesResponse 466 type MessageBodiesResponse struct { 467 Bodies []RawData 468 RequestedId uint32 //avoid msg drop 469 } 470 471 func (m *MessageBodiesResponse) GetType() msg.BinaryMessageType { 472 return MessageTypeBodiesResponse 473 } 474 475 func (m *MessageBodiesResponse) GetData() []byte { 476 b, err := m.MarshalMsg(nil) 477 if err != nil { 478 panic(err) 479 } 480 return b 481 } 482 483 func (m *MessageBodiesResponse) ToBinary() msg.BinaryMessage { 484 return msg.BinaryMessage{ 485 Type: m.GetType(), 486 Data: m.GetData(), 487 } 488 } 489 490 func (m *MessageBodiesResponse) FromBinary(bs []byte) error { 491 _, err := m.UnmarshalMsg(bs) 492 return err 493 } 494 495 func (m *MessageBodiesResponse) String() string { 496 return fmt.Sprintf("bodies len : %d, reuqestedId :%d", len(m.Bodies), m.RequestedId) 497 } 498 499 //msgp:tuple MessageControl 500 type MessageControl struct { 501 Hash *types.Hash 502 } 503 504 func (m *MessageControl) GetType() msg.BinaryMessageType { 505 return MessageTypeControl 506 } 507 508 func (m *MessageControl) GetData() []byte { 509 b, err := m.MarshalMsg(nil) 510 if err != nil { 511 panic(err) 512 } 513 return b 514 } 515 516 func (m *MessageControl) ToBinary() msg.BinaryMessage { 517 return msg.BinaryMessage{ 518 Type: m.GetType(), 519 Data: m.GetData(), 520 } 521 } 522 523 func (m *MessageControl) FromBinary(bs []byte) error { 524 _, err := m.UnmarshalMsg(bs) 525 return err 526 } 527 528 func (m *MessageControl) String() string { 529 if m == nil || m.Hash == nil { 530 return "" 531 } 532 return m.Hash.String() 533 } 534 535 //msgp:tuple MessageGetMsg 536 type MessageGetMsg struct { 537 Hash *types.Hash 538 } 539 540 func (m *MessageGetMsg) GetType() msg.BinaryMessageType { 541 return MessageTypeGetMsg 542 } 543 544 func (m *MessageGetMsg) GetData() []byte { 545 b, err := m.MarshalMsg(nil) 546 if err != nil { 547 panic(err) 548 } 549 return b 550 } 551 552 func (m *MessageGetMsg) ToBinary() msg.BinaryMessage { 553 return msg.BinaryMessage{ 554 Type: m.GetType(), 555 Data: m.GetData(), 556 } 557 } 558 559 func (m *MessageGetMsg) FromBinary(bs []byte) error { 560 _, err := m.UnmarshalMsg(bs) 561 return err 562 } 563 564 func (m *MessageGetMsg) String() string { 565 if m == nil || m.Hash == nil { 566 return "" 567 } 568 return m.Hash.String() 569 } 570 571 //msgp:tuple MessageGetMsg 572 type MessageDuplicate bool 573 574 func (m *MessageDuplicate) GetType() msg.BinaryMessageType { 575 return MessageTypeDuplicate 576 } 577 578 func (m *MessageDuplicate) GetData() []byte { 579 b, err := m.MarshalMsg(nil) 580 if err != nil { 581 panic(err) 582 } 583 return b 584 } 585 586 func (m *MessageDuplicate) ToBinary() msg.BinaryMessage { 587 return msg.BinaryMessage{ 588 Type: m.GetType(), 589 Data: m.GetData(), 590 } 591 } 592 593 func (m *MessageDuplicate) FromBinary(bs []byte) error { 594 _, err := m.UnmarshalMsg(bs) 595 return err 596 } 597 598 func (m *MessageDuplicate) String() string { 599 return "MessageDuplicate" 600 } 601 602 //msgp:tuple MessageNewActionTx 603 type MessageNewActionTx struct { 604 ActionTx *ActionTx 605 } 606 607 func (m *MessageNewActionTx) GetType() msg.BinaryMessageType { 608 return MessageTypeNewActionTx 609 } 610 611 func (m *MessageNewActionTx) GetData() []byte { 612 b, err := m.MarshalMsg(nil) 613 if err != nil { 614 panic(err) 615 } 616 return b 617 } 618 619 func (m *MessageNewActionTx) ToBinary() msg.BinaryMessage { 620 return msg.BinaryMessage{ 621 Type: m.GetType(), 622 Data: m.GetData(), 623 } 624 } 625 626 func (m *MessageNewActionTx) FromBinary(bs []byte) error { 627 _, err := m.UnmarshalMsg(bs) 628 return err 629 } 630 631 func (m *MessageNewActionTx) String() string { 632 if m.ActionTx == nil { 633 return "nil" 634 } 635 return m.ActionTx.String() 636 } 637 638 //msgp:tuple GeneralMessageAnnsensus 639 type MessageAnnsensus struct { 640 InnerMessageType annsensus.AnnsensusMessageType 641 InnerMessage []byte 642 } 643 644 func (m MessageAnnsensus) GetType() msg.BinaryMessageType { 645 return MessageTypeAnnsensus 646 } 647 648 func (m MessageAnnsensus) GetData() []byte { 649 b, err := m.MarshalMsg(nil) 650 if err != nil { 651 panic(err) 652 } 653 return b 654 } 655 656 func (m MessageAnnsensus) ToBinary() msg.BinaryMessage { 657 return msg.BinaryMessage{ 658 Type: m.GetType(), 659 Data: m.GetData(), 660 } 661 } 662 663 func (m MessageAnnsensus) FromBinary(bs []byte) error { 664 _, err := m.UnmarshalMsg(bs) 665 return err 666 } 667 668 func (m MessageAnnsensus) String() string { 669 return "GeneralMessageAnnsensus" 670 }