[golang] implement automation loop and add contract accepting
This commit is contained in:
parent
3dad3f60f2
commit
d97985a694
9 changed files with 223 additions and 64 deletions
|
@ -12,7 +12,7 @@ func (db *DB) SaveAgent(agent *model.Agent) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal agent: %w", err)
|
||||
}
|
||||
if _, err := db.Exec(`INSERT INTO agents SET data = (json(?));`, data); err != nil {
|
||||
if _, err := db.Exec(`INSERT INTO agents VALUES data = (json(?));`, data); err != nil {
|
||||
return fmt.Errorf("failed to insert agent data: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func initDB(ctx context.Context, url string) (*sql.DB, error) {
|
||||
|
@ -90,6 +91,21 @@ func (db *DB) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) Reset() error {
|
||||
_, err := db.Exec(strings.Join([]string{
|
||||
"DELETE FROM agents;",
|
||||
"DELETE FROM markets;",
|
||||
"DELETE FROM systems;",
|
||||
"DELETE FROM tokens;",
|
||||
"DELETE FROM transactions;",
|
||||
"DELETE FROM waypoints;",
|
||||
}, ""))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to reset database: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) Exec(query string, args ...any) (sql.Result, error) {
|
||||
return db.writeDB.ExecContext(db.ctx, query, args...)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package database
|
||||
|
||||
func (db *DB) AddToken(token string) error {
|
||||
func (db *DB) SaveToken(token string) error {
|
||||
_, err := db.Exec(`INSERT INTO tokens(data) VALUES (?);`, token)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue