mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2026-05-23 19:59:24 +02:00
wip: refactor taskers
This commit is contained in:
25
internal/store/dispatch.go
Normal file
25
internal/store/dispatch.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Status string
|
||||
|
||||
func (s *PostgresStore) CreateDispatchStatus(ctx context.Context, dispatch DispatchStatus) (uint, error) {
|
||||
var (
|
||||
id uint
|
||||
)
|
||||
|
||||
if err := s.db.QueryRow(
|
||||
ctx,
|
||||
s.queries.CreateDispatchStatus,
|
||||
dispatch.OtxId,
|
||||
dispatch.Status,
|
||||
dispatch.TrackingId,
|
||||
).Scan(&id); err != nil {
|
||||
return id, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
25
internal/store/otx.go
Normal file
25
internal/store/otx.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package store
|
||||
|
||||
import "context"
|
||||
|
||||
func (s *PostgresStore) CreateOTX(ctx context.Context, otx OTX) (uint, error) {
|
||||
var (
|
||||
id uint
|
||||
)
|
||||
|
||||
if err := s.db.QueryRow(
|
||||
ctx,
|
||||
s.queries.CreateOTX,
|
||||
otx.RawTx,
|
||||
otx.TxHash,
|
||||
otx.From,
|
||||
otx.Data,
|
||||
otx.GasPrice,
|
||||
otx.Nonce,
|
||||
otx.TrackingId,
|
||||
).Scan(&id); err != nil {
|
||||
return id, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
25
internal/store/postgres.go
Normal file
25
internal/store/postgres.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"github.com/grassrootseconomics/cic-custodial/internal/queries"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type (
|
||||
Opts struct {
|
||||
PostgresPool *pgxpool.Pool
|
||||
Queries *queries.Queries
|
||||
}
|
||||
|
||||
PostgresStore struct {
|
||||
db *pgxpool.Pool
|
||||
queries *queries.Queries
|
||||
}
|
||||
)
|
||||
|
||||
func NewPostgresStore(o Opts) Store {
|
||||
return &PostgresStore{
|
||||
db: o.PostgresPool,
|
||||
queries: o.Queries,
|
||||
}
|
||||
}
|
||||
32
internal/store/store.go
Normal file
32
internal/store/store.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grassrootseconomics/cic-custodial/pkg/status"
|
||||
)
|
||||
|
||||
type (
|
||||
OTX struct {
|
||||
RawTx string
|
||||
TxHash string
|
||||
From string
|
||||
Data string
|
||||
GasPrice uint64
|
||||
Nonce uint64
|
||||
TrackingId string
|
||||
}
|
||||
|
||||
DispatchStatus struct {
|
||||
OtxId uint
|
||||
Status status.Status
|
||||
TrackingId string
|
||||
}
|
||||
|
||||
Store interface {
|
||||
// OTX (Custodial originating transactions).
|
||||
CreateOTX(ctx context.Context, otx OTX) (id uint, err error)
|
||||
// Dispatch status.
|
||||
CreateDispatchStatus(ctx context.Context, dispatch DispatchStatus) (id uint, err error)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user