-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#18 WIP on binary graph serialization
- Loading branch information
Showing
15 changed files
with
578 additions
and
420 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package binary | ||
|
||
import ( | ||
"github.com/regen-network/regen-ledger/graph" | ||
"github.com/regen-network/regen-ledger/graph/impl" | ||
"github.com/regen-network/regen-ledger/x/schema" | ||
) | ||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
const ( | ||
prefixGeoAddress byte = iota | ||
prefixAccAddress | ||
prefixHashID | ||
|
||
prefixIDMin = prefixGeoAddress | ||
prefixIDMax = prefixHashID | ||
) | ||
|
||
const ( | ||
prefixPropertyID byte = 0 | ||
) | ||
|
||
type SchemaResolver interface { | ||
GetPropertyByURL(url string) graph.Property | ||
GetPropertyByID(id schema.PropertyID) graph.Property | ||
GetPropertyID(p graph.Property) schema.PropertyID | ||
} | ||
|
||
type onChainSchemaResolver struct { | ||
keeper schema.Keeper | ||
ctx sdk.Context | ||
} | ||
|
||
func (res onChainSchemaResolver) GetPropertyID(p graph.Property) schema.PropertyID { | ||
return res.keeper.GetPropertyID(res.ctx, p.URI().String()) | ||
} | ||
|
||
func (res onChainSchemaResolver) GetPropertyByURL(url string) graph.Property { | ||
id := res.keeper.GetPropertyID(res.ctx, url) | ||
if id == 0 { | ||
return nil | ||
} | ||
return res.GetPropertyByID(id) | ||
} | ||
|
||
func (res onChainSchemaResolver) GetPropertyByID(id schema.PropertyID) graph.Property { | ||
prop, found := res.keeper.GetPropertyDefinition(res.ctx, id) | ||
if !found { | ||
return nil | ||
} | ||
return impl.NewProperty(prop, id, prop.URI()) | ||
} |
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,40 @@ | ||
package binary | ||
|
||
import ( | ||
"fmt" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"net/url" | ||
) | ||
|
||
type AccAddressID struct { | ||
sdk.AccAddress | ||
} | ||
|
||
func (id AccAddressID) URI() *url.URL { | ||
uri, err := url.Parse(id.String()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return uri | ||
} | ||
|
||
type HashID struct { | ||
fragment string | ||
} | ||
|
||
func (id HashID) String() string { | ||
return fmt.Sprintf("_:_.%s", id.fragment) | ||
} | ||
|
||
func (id HashID) URI() *url.URL { | ||
// TODO this should really be a blank node or the actual hash of the graph plus the fragment | ||
uri, err := url.Parse(fmt.Sprintf("root:#%s", id.fragment)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return uri | ||
} | ||
|
||
//func (n node) GetClasses() []string { | ||
// panic("implement me") | ||
//} |
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
Oops, something went wrong.