@@ -9,21 +9,21 @@ import (
99)
1010
1111var (
12- ErrCampaignNotFound = errors .New ("campaign not found" )
13- ErrInvalidCampaign = errors .New ("invalid campaign " )
12+ ErrIssuanceNotFound = errors .New ("issuance not found" )
13+ ErrInvalidIssuance = errors .New ("invalid issuance " )
1414)
1515
16- type CampaignState string
16+ type IssuanceState string
1717
1818const (
19- CampaignStateClosed CampaignState = "closed"
20- CampaignStateOngoing CampaignState = "ongoing"
21- CampaignStateCanceled CampaignState = "canceled"
22- CampaignStateSettled CampaignState = "settled"
23- CampaignStateCollateralExecuted CampaignState = "collateral_executed"
19+ IssuanceStateClosed IssuanceState = "closed"
20+ IssuanceStateOngoing IssuanceState = "ongoing"
21+ IssuanceStateCanceled IssuanceState = "canceled"
22+ IssuanceStateSettled IssuanceState = "settled"
23+ IssuanceStateCollateralExecuted IssuanceState = "collateral_executed"
2424)
2525
26- type Campaign struct {
26+ type Issuance struct {
2727 Id uint `json:"id" gorm:"primaryKey"`
2828 Title string `json:"title,omitempty" gorm:"not null"`
2929 Description string `json:"description,omitempty" gorm:"not null"`
@@ -37,16 +37,16 @@ type Campaign struct {
3737 MaxInterestRate * uint256.Int `json:"max_interest_rate,omitempty" gorm:"types:text;not null"`
3838 TotalObligation * uint256.Int `json:"total_obligation,omitempty" gorm:"types:text;not null;default:0"`
3939 TotalRaised * uint256.Int `json:"total_raised,omitempty" gorm:"types:text;not null;default:0"`
40- State CampaignState `json:"state,omitempty" gorm:"types:text;not null"`
41- Orders []* Order `json:"orders,omitempty" gorm:"foreignKey:CampaignId ;constraint:OnDelete:CASCADE"`
40+ State IssuanceState `json:"state,omitempty" gorm:"types:text;not null"`
41+ Orders []* Order `json:"orders,omitempty" gorm:"foreignKey:IssuanceId ;constraint:OnDelete:CASCADE"`
4242 ClosesAt int64 `json:"closes_at,omitempty" gorm:"not null"`
4343 MaturityAt int64 `json:"maturity_at,omitempty" gorm:"not null"`
4444 CreatedAt int64 `json:"created_at,omitempty" gorm:"not null"`
4545 UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"`
4646}
4747
48- func NewCampaign (title string , description string , promotion string , token types.Address , creatorAddress types.Address , collateralAddress types.Address , collateralAmount * uint256.Int , badgeAddress types.Address , debtIssued * uint256.Int , maxInterestRate * uint256.Int , closesAt int64 , maturityAt int64 , createdAt int64 ) (* Campaign , error ) {
49- campaign := & Campaign {
48+ func NewIssuance (title string , description string , promotion string , token types.Address , creatorAddress types.Address , collateralAddress types.Address , collateralAmount * uint256.Int , badgeAddress types.Address , debtIssued * uint256.Int , maxInterestRate * uint256.Int , closesAt int64 , maturityAt int64 , createdAt int64 ) (* Issuance , error ) {
49+ issuance := & Issuance {
5050 Title : title ,
5151 Description : description ,
5252 Promotion : promotion ,
@@ -57,57 +57,57 @@ func NewCampaign(title string, description string, promotion string, token types
5757 BadgeAddress : badgeAddress ,
5858 DebtIssued : debtIssued ,
5959 MaxInterestRate : maxInterestRate ,
60- State : CampaignStateOngoing ,
60+ State : IssuanceStateOngoing ,
6161 Orders : []* Order {},
6262 ClosesAt : closesAt ,
6363 MaturityAt : maturityAt ,
6464 CreatedAt : createdAt ,
6565 }
66- if err := campaign .validate (); err != nil {
66+ if err := issuance .validate (); err != nil {
6767 return nil , err
6868 }
69- return campaign , nil
69+ return issuance , nil
7070}
7171
72- func (a * Campaign ) validate () error {
72+ func (a * Issuance ) validate () error {
7373 if a .Title == "" {
74- return fmt .Errorf ("%w: title cannot be empty" , ErrInvalidCampaign )
74+ return fmt .Errorf ("%w: title cannot be empty" , ErrInvalidIssuance )
7575 }
7676 if a .Description == "" {
77- return fmt .Errorf ("%w: description cannot be empty" , ErrInvalidCampaign )
77+ return fmt .Errorf ("%w: description cannot be empty" , ErrInvalidIssuance )
7878 }
7979 if a .Promotion == "" {
80- return fmt .Errorf ("%w: promotion cannot be empty" , ErrInvalidCampaign )
80+ return fmt .Errorf ("%w: promotion cannot be empty" , ErrInvalidIssuance )
8181 }
8282 if a .Token == (types.Address {}) {
83- return fmt .Errorf ("%w: invalid token address" , ErrInvalidCampaign )
83+ return fmt .Errorf ("%w: invalid token address" , ErrInvalidIssuance )
8484 }
8585 if a .CreatorAddress == (types.Address {}) {
86- return fmt .Errorf ("%w: invalid creator address" , ErrInvalidCampaign )
86+ return fmt .Errorf ("%w: invalid creator address" , ErrInvalidIssuance )
8787 }
8888 if a .CollateralAddress == (types.Address {}) {
89- return fmt .Errorf ("%w: invalid collateral address" , ErrInvalidCampaign )
89+ return fmt .Errorf ("%w: invalid collateral address" , ErrInvalidIssuance )
9090 }
9191 if a .CollateralAmount .Sign () == 0 {
92- return fmt .Errorf ("%w: collateral amount cannot be zero" , ErrInvalidCampaign )
92+ return fmt .Errorf ("%w: collateral amount cannot be zero" , ErrInvalidIssuance )
9393 }
9494 if a .BadgeAddress == (types.Address {}) {
95- return fmt .Errorf ("%w: invalid badge address" , ErrInvalidCampaign )
95+ return fmt .Errorf ("%w: invalid badge address" , ErrInvalidIssuance )
9696 }
9797 if a .DebtIssued .Sign () == 0 {
98- return fmt .Errorf ("%w: debt issued cannot be zero" , ErrInvalidCampaign )
98+ return fmt .Errorf ("%w: debt issued cannot be zero" , ErrInvalidIssuance )
9999 }
100100 if a .MaxInterestRate .Sign () == 0 {
101- return fmt .Errorf ("%w: max interest rate cannot be zero" , ErrInvalidCampaign )
101+ return fmt .Errorf ("%w: max interest rate cannot be zero" , ErrInvalidIssuance )
102102 }
103103 if a .CreatedAt == 0 {
104- return fmt .Errorf ("%w: creation date is missing" , ErrInvalidCampaign )
104+ return fmt .Errorf ("%w: creation date is missing" , ErrInvalidIssuance )
105105 }
106106 if a .ClosesAt == 0 {
107- return fmt .Errorf ("%w: close date is missing" , ErrInvalidCampaign )
107+ return fmt .Errorf ("%w: close date is missing" , ErrInvalidIssuance )
108108 }
109109 if a .MaturityAt == 0 {
110- return fmt .Errorf ("%w: maturity date is missing" , ErrInvalidCampaign )
110+ return fmt .Errorf ("%w: maturity date is missing" , ErrInvalidIssuance )
111111 }
112112 return nil
113113}
0 commit comments