Add full monorepo: virtual-banker, backend, frontend, docs, scripts, deployment
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
81
backend/api/graphql/resolvers.go
Normal file
81
backend/api/graphql/resolvers.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// Resolver handles GraphQL queries
|
||||
type Resolver struct {
|
||||
db *pgxpool.Pool
|
||||
chainID int
|
||||
}
|
||||
|
||||
// NewResolver creates a new GraphQL resolver
|
||||
func NewResolver(db *pgxpool.Pool, chainID int) *Resolver {
|
||||
return &Resolver{
|
||||
db: db,
|
||||
chainID: chainID,
|
||||
}
|
||||
}
|
||||
|
||||
// BlockResolver resolves Block queries
|
||||
type BlockResolver struct {
|
||||
db *pgxpool.Pool
|
||||
chainID int
|
||||
block *Block
|
||||
}
|
||||
|
||||
// Block represents a block in GraphQL
|
||||
type Block struct {
|
||||
ChainID int32
|
||||
Number int32
|
||||
Hash string
|
||||
ParentHash string
|
||||
Timestamp string
|
||||
Miner string
|
||||
TransactionCount int32
|
||||
GasUsed int64
|
||||
GasLimit int64
|
||||
}
|
||||
|
||||
// TransactionResolver resolves Transaction queries
|
||||
type TransactionResolver struct {
|
||||
db *pgxpool.Pool
|
||||
chainID int
|
||||
tx *Transaction
|
||||
}
|
||||
|
||||
// Transaction represents a transaction in GraphQL
|
||||
type Transaction struct {
|
||||
ChainID int32
|
||||
Hash string
|
||||
BlockNumber int32
|
||||
From string
|
||||
To *string
|
||||
Value string
|
||||
GasPrice *int64
|
||||
GasUsed *int64
|
||||
Status *int32
|
||||
}
|
||||
|
||||
// ResolveBlock resolves block query
|
||||
func (r *Resolver) ResolveBlock(ctx context.Context, args struct {
|
||||
ChainID int32
|
||||
Number *int32
|
||||
}) (*BlockResolver, error) {
|
||||
// Implementation would fetch block from database
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
// ResolveTransaction resolves transaction query
|
||||
func (r *Resolver) ResolveTransaction(ctx context.Context, args struct {
|
||||
ChainID int32
|
||||
Hash string
|
||||
}) (*TransactionResolver, error) {
|
||||
// Implementation would fetch transaction from database
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
102
backend/api/graphql/schema.graphql
Normal file
102
backend/api/graphql/schema.graphql
Normal file
@@ -0,0 +1,102 @@
|
||||
type Query {
|
||||
block(chainId: Int!, number: Int): Block
|
||||
blockByHash(chainId: Int!, hash: String!): Block
|
||||
blocks(chainId: Int!, page: Int, pageSize: Int): BlockConnection!
|
||||
|
||||
transaction(chainId: Int!, hash: String!): Transaction
|
||||
transactions(chainId: Int!, page: Int, pageSize: Int): TransactionConnection!
|
||||
|
||||
address(chainId: Int!, address: String!): Address
|
||||
}
|
||||
|
||||
type Block {
|
||||
chainId: Int!
|
||||
number: Int!
|
||||
hash: String!
|
||||
parentHash: String!
|
||||
timestamp: String!
|
||||
miner: String!
|
||||
transactionCount: Int!
|
||||
gasUsed: Int!
|
||||
gasLimit: Int!
|
||||
transactions: [Transaction!]!
|
||||
}
|
||||
|
||||
type Transaction {
|
||||
chainId: Int!
|
||||
hash: String!
|
||||
blockNumber: Int!
|
||||
from: String!
|
||||
to: String
|
||||
value: String!
|
||||
gasPrice: Int
|
||||
gasUsed: Int
|
||||
status: Int
|
||||
logs: [Log!]!
|
||||
trace: Trace
|
||||
}
|
||||
|
||||
type Log {
|
||||
address: String!
|
||||
topics: [String!]!
|
||||
data: String!
|
||||
logIndex: Int!
|
||||
}
|
||||
|
||||
type Trace {
|
||||
calls: [CallTrace!]!
|
||||
}
|
||||
|
||||
type CallTrace {
|
||||
type: String!
|
||||
from: String!
|
||||
to: String!
|
||||
value: String!
|
||||
gas: Int!
|
||||
gasUsed: Int!
|
||||
input: String!
|
||||
output: String!
|
||||
}
|
||||
|
||||
type Address {
|
||||
address: String!
|
||||
chainId: Int!
|
||||
transactionCount: Int!
|
||||
tokenCount: Int!
|
||||
isContract: Boolean!
|
||||
label: String
|
||||
tags: [String!]!
|
||||
}
|
||||
|
||||
type BlockConnection {
|
||||
edges: [BlockEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type BlockEdge {
|
||||
node: Block!
|
||||
cursor: String!
|
||||
}
|
||||
|
||||
type TransactionConnection {
|
||||
edges: [TransactionEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type TransactionEdge {
|
||||
node: Transaction!
|
||||
cursor: String!
|
||||
}
|
||||
|
||||
type PageInfo {
|
||||
hasNextPage: Boolean!
|
||||
hasPreviousPage: Boolean!
|
||||
startCursor: String
|
||||
endCursor: String
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
newBlock(chainId: Int!): Block!
|
||||
newTransaction(chainId: Int!): Transaction!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user