github.com/DapperCollectives/CAST/backend@v0.0.0-20230921221157-1350c8be7c96/main/shared/structs.go (about) 1 package shared 2 3 import ( 4 "context" 5 "os" 6 "reflect" 7 "time" 8 9 "github.com/jackc/pgx/v4/pgxpool" 10 ) 11 12 type Config struct { 13 Features map[string]bool `default:"useCorsMiddleware:false,validateTimestamps:true,validateAllowlist:true,validateBlocklist:true,validateSigs:true"` 14 } 15 16 type Database struct { 17 Conn *pgxpool.Pool 18 Context context.Context 19 Name string 20 Env *string 21 } 22 23 type StrategyStruct struct { 24 FlowAdapter *FlowAdapter 25 DB *Database 26 } 27 28 type Allowlist struct { 29 Addresses []string `json:"addresses"` 30 } 31 32 type PaginatedResponse struct { 33 Data interface{} `json:"data"` 34 Start int `json:"start"` 35 Count int `json:"count"` 36 TotalRecords int `json:"totalRecords"` 37 Next int `json:"next"` 38 } 39 40 type PageParams struct { 41 Start int 42 Count int 43 Order string 44 TotalRecords int 45 } 46 47 type SearchFilter struct { 48 Text string `json:"text"` 49 Amount int `json:"amount"` 50 } 51 52 type CompositeSignature struct { 53 Addr string `json:"addr"` 54 Key_id uint `json:"keyId"` 55 Signature string `json:"signature"` 56 F_type *string `json:"f_type,omitempty"` 57 F_vsn *string `json:"f_vsn,omitempty"` 58 } 59 60 type TimestampSignaturePayload struct { 61 Composite_signatures *[]CompositeSignature `json:"compositeSignatures"` 62 Signing_addr string `json:"signingAddr"` 63 Timestamp string `json:"timestamp"` 64 } 65 66 // used in models/proposal.go 67 type Choice struct { 68 Choice_text string `json:"choiceText"` 69 Choice_img_url *string `json:"choiceImgUrl"` 70 } 71 72 type MintParams struct { 73 Recipient string 74 Name string 75 Description string 76 Thumbnail string 77 Cuts []float64 78 RoyaltyDescriptions []string 79 RoyaltyBeneficiaries []string 80 } 81 82 type FTBalanceResponse struct { 83 ID string `json:"id,omitempty"` 84 FungibleTokenID string `json:"fungibleTokenId"` 85 Addr string `json:"addr"` 86 PrimaryAccountBalance uint64 `json:"primaryAccountBalance"` 87 SecondaryAddress string `json:"secondaryAddress"` 88 SecondaryAccountBalance uint64 `json:"secondaryAccountBalance"` 89 Balance uint64 `json:"balance"` 90 StakingBalance uint64 `json:"stakingBalance"` 91 ScriptResult string `json:"scriptResult"` 92 Stakes []string `json:"stakes"` 93 BlockHeight uint64 `json:"blockHeight"` 94 Proposal_id int `json:"proposal_id"` 95 NFTCount int `json:"nftCount"` 96 CreatedAt time.Time `json:"createdAt"` 97 } 98 99 type CustomScript struct { 100 Key string `json:"key" validate:"required"` 101 Name string `json:"name" validate:"required"` 102 Description string `json:"description" validate:"required"` 103 Src string `json:"src" validate:"required"` 104 } 105 106 func (b *FTBalanceResponse) NewFTBalance() { 107 if os.Getenv("APP_ENV") == "TEST" || os.Getenv("APP_ENV") == "DEV" { 108 b.PrimaryAccountBalance = 11100000 109 b.SecondaryAccountBalance = 12300000 110 b.StakingBalance = 13500000 111 } else { 112 b.PrimaryAccountBalance = 0 113 b.SecondaryAccountBalance = 0 114 b.StakingBalance = 0 115 } 116 } 117 118 // Underlying value of payload needs to be a slice 119 func GetPaginatedResponseWithPayload(payload interface{}, p PageParams) *PaginatedResponse { 120 // Tricky way of getting the length of a slice 121 // that is typed as interface{} 122 123 _count := reflect.ValueOf(payload).Len() 124 var next int 125 if p.Start+_count >= (p.TotalRecords - 1) { 126 next = -1 127 } else { 128 next = p.Start + _count 129 } 130 response := PaginatedResponse{ 131 Data: payload, 132 Start: p.Start, 133 Count: _count, 134 TotalRecords: p.TotalRecords, 135 Next: next, 136 } 137 138 return &response 139 }