github.com/condensat/bank-core@v0.1.0/database/model/batchinfo.go (about) 1 // Copyright 2020 Condensat Tech. All rights reserved. 2 // Use of this source code is governed by a MIT 3 // license that can be found in the LICENSE file. 4 5 package model 6 7 import ( 8 "errors" 9 "time" 10 11 "github.com/condensat/bank-core/database/encoding" 12 ) 13 14 type BatchInfoID ID 15 type BatchStatus String 16 type BatchInfoData encoding.Data 17 18 const ( 19 BatchStatusCreated BatchStatus = "created" 20 BatchStatusReady BatchStatus = "ready" 21 BatchStatusProcessing BatchStatus = "processing" 22 BatchStatusConfirmed BatchStatus = "confirmed" 23 BatchStatusSettled BatchStatus = "settled" 24 BatchStatusCanceled BatchStatus = "canceled" 25 26 BatchInfoCrypto encoding.DataType = "crypto" 27 ) 28 29 var ( 30 ErrInvalidDataType = errors.New("Invalid DataType") 31 ) 32 33 type BatchInfo struct { 34 ID BatchInfoID `gorm:"primary_key"` 35 Timestamp time.Time `gorm:"index;not null;type:timestamp"` // Creation timestamp 36 BatchID BatchID `gorm:"index;not null"` // [FK] Reference to Batch table 37 Status BatchStatus `gorm:"index;not null;size:16"` // BatchStatus [created, processing, completed, canceled] 38 Type encoding.DataType `gorm:"index;not null;size:16"` // DataType [crypto] 39 Data BatchInfoData `gorm:"type:blob;not null;default:'{}'"` // BatchInfo data 40 } 41 42 // BatchInfoCryptoData data type for BatchInfo crypto 43 type BatchInfoCryptoData struct { 44 TxID String `json:"txid,omitempty"` 45 Height Int `json:"height,omitempty"` 46 } 47 48 func (p *BatchInfo) CryptoData() (BatchInfoCryptoData, error) { 49 switch p.Type { 50 51 case BatchInfoCrypto: 52 var data BatchInfoCryptoData 53 err := encoding.DecodeData(&data, encoding.Data(p.Data)) 54 return data, err 55 56 default: 57 return BatchInfoCryptoData{}, ErrInvalidDataType 58 } 59 }