7 "github.com/vapor/errors"
8 "github.com/vapor/federation/common"
9 "github.com/vapor/federation/types"
12 type CrossTransaction struct {
13 ID uint64 `gorm:"primary_key"`
15 SourceBlockHeight uint64
16 SourceBlockHash string
20 SourceRawTransaction string
21 DestBlockHeight sql.NullInt64 `sql:"default:null"`
22 DestBlockHash sql.NullString `sql:"default:null"`
23 DestTxIndex sql.NullInt64 `sql:"default:null"`
24 DestTxHash sql.NullString `sql:"default:null"`
26 CreatedAt types.Timestamp
27 UpdatedAt types.Timestamp
29 Chain *Chain `gorm:"foreignkey:ChainID"`
30 Reqs []*CrossTransactionReq
33 func (c *CrossTransaction) MarshalJSON() ([]byte, error) {
36 case common.CrossTxPendingStatus:
37 status = common.CrossTxPendingStatusLabel
38 case common.CrossTxCompletedStatus:
39 status = common.CrossTxCompletedStatusLabel
41 return nil, errors.New("unknown cross-chain tx status")
44 return json.Marshal(&struct {
45 FromChain string `json:"from_chain"`
46 SourceBlockHeight uint64 `json:"source_block_height"`
47 SourceBlockHash string `json:"source_block_hash"`
48 SourceTxIndex uint64 `json:"source_tx_index"`
49 SourceTxHash string `json:"source_tx_hash"`
50 DestBlockHeight uint64 `json:"dest_block_height"`
51 DestBlockHash string `json:"dest_block_hash"`
52 DestTxIndex uint64 `json:"dest_tx_index"`
53 DestTxHash string `json:"dest_tx_hash"`
54 Status string `json:"status"`
55 Reqs []*CrossTransactionReq `json:"crosschain_requests"`
57 FromChain: c.Chain.Name,
58 SourceBlockHeight: c.SourceBlockHeight,
59 SourceBlockHash: c.SourceBlockHash,
60 SourceTxIndex: c.SourceTxIndex,
61 SourceTxHash: c.SourceTxHash,
62 DestBlockHeight: uint64(c.DestBlockHeight.Int64),
63 DestBlockHash: c.DestBlockHash.String,
64 DestTxIndex: uint64(c.DestTxIndex.Int64),
65 DestTxHash: c.DestTxHash.String,