generated from axone-protocol/template-oss
-
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 #21 from axone-protocol/feat/get-resource-gov
Implement `GetResourceGovAddr`
- Loading branch information
Showing
8 changed files
with
418 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dataverse | ||
|
||
import "fmt" | ||
|
||
type MessageError string | ||
|
||
const ( | ||
ErrNoResult MessageError = "no result found in binding" | ||
ErrVarNotFound MessageError = "variable not found in binding result" | ||
ErrType MessageError = "variable result type mismatch in binding result" | ||
) | ||
|
||
type DVError struct { | ||
message MessageError | ||
detail error | ||
} | ||
|
||
func (e *DVError) Error() string { | ||
if e.detail == nil { | ||
return fmt.Sprintf("%v", e.message) | ||
} | ||
return fmt.Sprintf("%v: %v", e.message, e.detail) | ||
} | ||
|
||
func NewDVError(message MessageError, detail error) error { | ||
return &DVError{ | ||
message: message, | ||
detail: detail, | ||
} | ||
} |
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,18 @@ | ||
package dataverse | ||
|
||
import ( | ||
cgschema "github.com/axone-protocol/axone-contract-schema/go/cognitarium-schema/v5" | ||
dvschema "github.com/axone-protocol/axone-contract-schema/go/dataverse-schema/v5" | ||
) | ||
|
||
func NewDataverseClient( | ||
dataverseClient dvschema.QueryClient, | ||
cognitariumClient cgschema.QueryClient, | ||
) Client { | ||
return &client{ | ||
dataverseClient, | ||
cognitariumClient, | ||
} | ||
} | ||
|
||
var GetCognitariumAddr = getCognitariumAddr |
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,34 @@ | ||
package dataverse | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
cgschema "github.com/axone-protocol/axone-contract-schema/go/cognitarium-schema/v5" | ||
) | ||
|
||
func (c *client) GetResourceGovAddr(ctx context.Context, resourceDID string) (string, error) { | ||
query := buildGetResourceGovAddrRequest(resourceDID) | ||
response, err := c.cognitariumClient.Select(ctx, &cgschema.QueryMsg_Select{Query: query}) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if len(response.Results.Bindings) != 1 { | ||
return "", NewDVError(ErrNoResult, nil) | ||
} | ||
|
||
codeBinding, ok := response.Results.Bindings[0]["code"] | ||
if !ok { | ||
return "", NewDVError(ErrVarNotFound, nil) | ||
} | ||
code, ok := codeBinding.ValueType.(cgschema.URI) | ||
if !ok { | ||
return "", NewDVError(ErrType, fmt.Errorf("expected URI, got %T", codeBinding.ValueType)) | ||
} | ||
return string(*code.Value.Full), nil | ||
} | ||
|
||
func (c *client) ExecGov(_ context.Context, _ string, _ string) (interface{}, error) { | ||
panic("not implemented") | ||
} |
Oops, something went wrong.