This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from JackalLabs/fix-proof-unsupported-key-type
prevent files from burning when rpc is down
- Loading branch information
Showing
5 changed files
with
72 additions
and
49 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
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,46 @@ | ||
package types | ||
|
||
import ( | ||
"strconv" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
storageTypes "github.com/jackalLabs/canine-chain/v3/x/storage/types" | ||
) | ||
|
||
type VerifiedStatus int | ||
|
||
const ( | ||
Verified VerifiedStatus = iota | ||
NotVerified | ||
NotFound | ||
Error | ||
) | ||
|
||
// Returns state of the active deal contract based on query response. | ||
// Returns Error status with non-nil error if respErr is unknown code or parsing resp failed. | ||
func ContractState(resp *storageTypes.QueryActiveDealResponse, respErr error) (VerifiedStatus, error) { | ||
if respErr != nil { | ||
stat, ok := status.FromError(respErr) | ||
if !ok { // unknown grpc error | ||
return Error, respErr | ||
} | ||
|
||
if codes.NotFound == stat.Code() { | ||
return NotFound, nil | ||
} | ||
|
||
return Error, respErr | ||
} | ||
|
||
verified, err := strconv.ParseBool(resp.ActiveDeals.Proofverified) | ||
if err != nil { | ||
return Error, err | ||
} | ||
|
||
if verified { | ||
return Verified, err | ||
} | ||
return NotVerified, err | ||
} |