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
const ( | |
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address | |
Bech32PrefixAccAddr = "tru:" | |
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key | |
Bech32PrefixAccPub = "tru:pub" | |
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address | |
Bech32PrefixValAddr = "tru:valoper" | |
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key | |
Bech32PrefixValPub = "tru:valoperpub" | |
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address |
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
{ | |
"genesis_time": "2018-11-29T02:28:27.057819Z", | |
"chain_id": "test-chain-JHrAIn", | |
"consensus_params": { | |
"block_size": { | |
"max_bytes": "22020096", | |
"max_gas": "-1" | |
}, | |
"evidence": { | |
"max_age": "100000" |
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
// Mutations write to the database | |
type Mutations interface { | |
GenericMutations | |
UpsertProfile(profile *Profile) error | |
} | |
// Queries read from the database | |
type Queries interface { | |
GenericQueries | |
ProfileByUsername(username string) (Profile, error) |
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
// Updates an existing Profile or creates a new one | |
func (c *Client) UpsertProfile(profile *Profile) error { | |
_, err := c.Model(profile). | |
OnConflict("(id) DO UPDATE"). | |
Set("username = EXCLUDED.username"). | |
Insert() | |
return err | |
} |
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
// Finds a Profile by the given username | |
func (c *Client) ProfileByUsername(username string) (Profile, error) { | |
profile := new(Profile) | |
err := c.Model(profile).Where("username = ?", username).Select() | |
if err != nil { | |
return *profile, err | |
} | |
return *profile, nil | |
} |
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
// GenericQueries are generic reads for models | |
type GenericQueries interface { | |
Count(model interface{}) (int, error) | |
Find(model interface{}) error | |
FindAll(models interface{}) error | |
} | |
// Count returns the count of the model | |
func (c *Client) Count(model interface{}) (count int, err error) { | |
count, err = c.Model(model).Count() |
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
// GenericMutations write to the database | |
type GenericMutations interface { | |
Add(model ...interface{}) error | |
RegisterModel(model interface{}) error | |
Remove(model interface{}) error | |
} |
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
// Add adds any number of models as a database rows | |
func (c *Client) Add(model ...interface{}) error { | |
return c.Insert(model...) | |
} |
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
// RegisterModel creates a table for a type. | |
// A table is automatically created based on the passed in struct fields. | |
func (c *Client) RegisterModel(model interface{}) error { | |
return c.CreateTable(model, &orm.CreateTableOptions{ | |
Temp: false, | |
IfNotExists: true, | |
}) | |
} |
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
// Datastore defines all operations on the DB | |
// This interface can be mocked out for tests, etc. | |
type Datastore interface { | |
Mutations | |
Queries | |
} |