Skip to content

Commit

Permalink
update db structure
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocolacio committed Dec 8, 2018
1 parent 4de47d1 commit 7cd0a5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion api/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import(
"io/ioutil"
"crypto/tls"
"net/url"
"log"
)

var(
Expand Down
18 changes: 15 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func init() {

func InitTables() error {
_, err := db.Exec(`CREATE TABLE keys(
owner INT,
id INT PRIMARY KEY AUTO_INCREMENT,
owner VARCHAR(16),
pub BLOB,
priv BLOB
);`)
Expand All @@ -38,12 +39,23 @@ func ResetTables() error {
return InitTables()
}

func LookupKey(owner int, pub []bytes) (priv []bytes, err error) {
func LookupPubKey(owner string) (pub []bytes, err error) {
row := db.QueryRow(
`SELECT priv
FROM keys
WHERE owner = ?
ORDER BY id DESC`,
string, pub)
err = row.Scan(&pub)
return
}

func LookupPrivKey(owner string, pub []bytes) (priv []bytes, err error) {
row := db.QueryRow(
`SELECT priv
FROM keys
WHERE owner = ? AND pub = ?`,
owner, pub)
string, pub)
err = row.Scan(&priv)
return
}
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func main() {
// }

go MessagePoll(jwt, peer, ui)

ui.Callback = func(msg string) {
err := api.MessageSend(jwt, peer, msg)
if err != nil {
Expand Down

0 comments on commit 7cd0a5d

Please sign in to comment.