Created
April 20, 2022 09:16
-
-
Save jelilat/0e4bb81bac8eef8b3ebced4dd5d0a07e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (msg *MsgCreateGofundme) ValidateBasic() error { | |
// Validate the creator | |
_, err := sdk.AccAddressFromBech32(msg.Creator) | |
if err != nil { | |
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) | |
} | |
// Get the goal amount | |
goal := sdk.NewIntFromUint64(msg.Goal) | |
// Ensure that the goal amount is greater than 0 | |
if goal.IsZero() { | |
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "goal amount must be greater than 0") | |
} | |
var start time.Time | |
//Get the start date | |
if msg.Start != "now" { | |
startDate, err := sdk.ParseTimeBytes([]byte(msg.Start)) | |
if err != nil { | |
return err | |
} | |
start = startDate | |
} else { | |
start = time.Now() | |
} | |
//Get the end date | |
end, err := sdk.ParseTimeBytes([]byte(msg.End)) | |
if err != nil { | |
return err | |
} | |
// Get the current block time | |
blockTime := time.Now() | |
// Ensure that end date is in the future | |
if end.Before(blockTime) { | |
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "end date must be in the future") | |
} | |
//Ensure that start date is not in the past | |
if start.Before(blockTime) { | |
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "start date cannot be in the past") | |
} | |
// Ensure that start date is before end date | |
if start.After(end) { | |
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "start date must be before end date") | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment