+ Chain *Chain `gorm:"foreignkey:ChainID"`
+ Reqs []*CrossTransactionReq
+}
+
+func (c *CrossTransaction) MarshalJSON() ([]byte, error) {
+ var status string
+ switch c.Status {
+ case common.CrossTxPendingStatus:
+ status = common.CrossTxPendingStatusLabel
+ case common.CrossTxCompletedStatus:
+ status = common.CrossTxCompletedStatusLabel
+ default:
+ return nil, errors.New("unknown cross-chain tx status")
+ }
+
+ return json.Marshal(&struct {
+ FromChain string `json:"from_chain"`
+ SourceBlockHeight uint64 `json:"source_block_height"`
+ SourceBlockHash string `json:"source_block_hash"`
+ SourceTxIndex uint64 `json:"source_tx_index"`
+ SourceTxHash string `json:"source_tx_hash"`
+ DestBlockHeight uint64 `json:"dest_block_height"`
+ DestBlockHash string `json:"dest_block_hash"`
+ DestTxIndex uint64 `json:"dest_tx_index"`
+ DestTxHash string `json:"dest_tx_hash"`
+ Status string `json:"status"`
+ Reqs []*CrossTransactionReq `json:"crosschain_requests"`
+ }{
+ FromChain: c.Chain.Name,
+ SourceBlockHeight: c.SourceBlockHeight,
+ SourceBlockHash: c.SourceBlockHash,
+ SourceTxIndex: c.SourceTxIndex,
+ SourceTxHash: c.SourceTxHash,
+ DestBlockHeight: uint64(c.DestBlockHeight.Int64),
+ DestBlockHash: c.DestBlockHash.String,
+ DestTxIndex: uint64(c.DestTxIndex.Int64),
+ DestTxHash: c.DestTxHash.String,
+ Status: status,
+ Reqs: c.Reqs,
+ })