-
Notifications
You must be signed in to change notification settings - Fork 8
/
service.go
68 lines (54 loc) · 2.08 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package txsvc
import (
"context"
"math/big"
"time"
cmtCoreTypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/kwilteam/kwil-db/common"
"github.com/kwilteam/kwil-db/common/sql"
"github.com/kwilteam/kwil-db/core/log"
txpb "github.com/kwilteam/kwil-db/core/rpc/protobuf/tx/v1"
coreTypes "github.com/kwilteam/kwil-db/core/types"
adminTypes "github.com/kwilteam/kwil-db/core/types/admin"
"github.com/kwilteam/kwil-db/core/types/transactions"
)
const defaultReadTxTimeout = 5 * time.Second
type Service struct {
txpb.UnimplementedTxServiceServer
log log.Logger
readTxTimeout time.Duration
engine EngineReader
db sql.ReadTxMaker // this should only ever make a read-only tx
nodeApp NodeApplication // so we don't have to do ABCIQuery (indirect)
chainClient BlockchainTransactor
}
func NewService(db sql.ReadTxMaker, engine EngineReader,
chainClient BlockchainTransactor, nodeApp NodeApplication, opts ...TxSvcOpt) *Service {
s := &Service{
log: log.NewNoOp(),
readTxTimeout: defaultReadTxTimeout,
engine: engine,
nodeApp: nodeApp,
chainClient: chainClient,
db: db,
}
for _, opt := range opts {
opt(s)
}
return s
}
type EngineReader interface {
Procedure(ctx context.Context, tx sql.DB, options *common.ExecutionData) (*sql.ResultSet, error)
GetSchema(ctx context.Context, dbid string) (*common.Schema, error)
ListDatasets(ctx context.Context, owner []byte) ([]*coreTypes.DatasetIdentifier, error)
Execute(ctx context.Context, tx sql.DB, dbid string, query string, values map[string]any) (*sql.ResultSet, error)
}
type BlockchainTransactor interface {
Status(ctx context.Context) (*adminTypes.Status, error)
BroadcastTx(ctx context.Context, tx []byte, sync uint8) (*cmtCoreTypes.ResultBroadcastTx, error)
TxQuery(ctx context.Context, hash []byte, prove bool) (*cmtCoreTypes.ResultTx, error)
}
type NodeApplication interface {
AccountInfo(ctx context.Context, identifier []byte, getUncommitted bool) (balance *big.Int, nonce int64, err error)
Price(ctx context.Context, tx *transactions.Transaction) (*big.Int, error)
}