-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added verify uniqueID of certificate (#542)
- Loading branch information
Showing
7 changed files
with
362 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
func (m *Certificate) ValidateBasic() error { | ||
if m.UnsignedCertificate == nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unsignedCertificate is empty") | ||
} | ||
|
||
if err := m.UnsignedCertificate.ValidateBasic(); err != nil { | ||
return sdkerrors.Wrapf(err, "failed to validation unsignedCertificate") | ||
} | ||
|
||
if m.Signature == nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "signature is empty") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *UnsignedCertificate) ValidateBasic() error { | ||
if len(m.Cid) == 0 { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "cid is empty") | ||
} | ||
|
||
if len(m.UniqueId) == 0 { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "uniqueId is empty") | ||
} | ||
|
||
if _, err := sdk.AccAddressFromBech32(m.OracleAddress); err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "oracleAddress is invalid. address: %s, error: %s", m.OracleAddress, err.Error()) | ||
} | ||
|
||
if m.DealId <= 0 { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "dealId is greater than 0") | ||
} | ||
|
||
if _, err := sdk.AccAddressFromBech32(m.ProviderAddress); err != nil { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "providerAddress is invalid. address: %s, error: %s", m.OracleAddress, err.Error()) | ||
} | ||
|
||
if len(m.DataHash) == 0 { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "dataHash is empty") | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.