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 SourceBlockTimestamp uint64
17 SourceBlockHash string
21 SourceRawTransaction string
22 DestBlockHeight sql.NullInt64 `sql:"default:null"`
23 DestBlockTimestamp sql.NullInt64 `sql:"default:null"`
24 DestBlockHash sql.NullString `sql:"default:null"`
25 DestTxIndex sql.NullInt64 `sql:"default:null"`
26 DestTxHash sql.NullString `sql:"default:null"`
28 CreatedAt types.Timestamp
29 UpdatedAt types.Timestamp
31 Chain *Chain `gorm:"foreignkey:ChainID"`
32 Reqs []*CrossTransactionReq
35 func (c *CrossTransaction) MarshalJSON() ([]byte, error) {
38 case common.CrossTxPendingStatus:
39 status = common.CrossTxPendingStatusLabel
40 case common.CrossTxCompletedStatus:
41 status = common.CrossTxCompletedStatusLabel
43 return nil, errors.New("unknown cross-chain tx status")
46 return json.Marshal(&struct {
47 SourceChainName string `json:"source_chain_name"`
48 SourceBlockHeight uint64 `json:"source_block_height"`
49 SourceBlockTimestamp uint64 `json:"source_block_timestamp"`
50 SourceBlockHash string `json:"source_block_hash"`
51 SourceTxIndex uint64 `json:"source_tx_index"`
52 SourceTxHash string `json:"source_tx_hash"`
53 DestBlockHeight uint64 `json:"dest_block_height"`
54 DestBlockTimestamp uint64 `json:"dest_block_timestamp"`
55 DestBlockHash string `json:"dest_block_hash"`
56 DestTxIndex uint64 `json:"dest_tx_index"`
57 DestTxHash string `json:"dest_tx_hash"`
58 Status string `json:"status"`
59 Reqs []*CrossTransactionReq `json:"crosschain_requests"`
61 SourceChainName: c.Chain.Name,
62 SourceBlockHeight: c.SourceBlockHeight,
63 SourceBlockTimestamp: c.SourceBlockTimestamp,
64 SourceBlockHash: c.SourceBlockHash,
65 SourceTxIndex: c.SourceTxIndex,
66 SourceTxHash: c.SourceTxHash,
67 DestBlockHeight: uint64(c.DestBlockHeight.Int64),
68 DestBlockTimestamp: uint64(c.DestBlockTimestamp.Int64),
69 DestBlockHash: c.DestBlockHash.String,
70 DestTxIndex: uint64(c.DestTxIndex.Int64),
71 DestTxHash: c.DestTxHash.String,