forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_api_scan.go
128 lines (102 loc) · 4.98 KB
/
client_api_scan.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package clientapi
import (
"context"
"math/big"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/go/responses"
"github.com/ethereum/go-ethereum/log"
"github.com/ten-protocol/go-ten/go/common"
"github.com/ten-protocol/go-ten/go/common/host"
)
// ScanAPI implements metric specific RPC endpoints
type ScanAPI struct {
host host.Host
logger log.Logger
}
func NewScanAPI(host host.Host, logger log.Logger) *ScanAPI {
return &ScanAPI{
host: host,
logger: logger,
}
}
// GetTotalContractCount returns the number of recorded contracts on the network.
func (s *ScanAPI) GetTotalContractCount(ctx context.Context) (*big.Int, error) {
return s.host.EnclaveClient().GetTotalContractCount(ctx)
}
// GetTransaction returns the transaction given its hash.
func (s *ScanAPI) GetTransaction(hash gethcommon.Hash) (*common.PublicTransaction, error) {
return s.host.Storage().FetchTransaction(hash)
}
// GetTotalTransactionCount returns the number of recorded transactions on the network.
func (s *ScanAPI) GetTotalTransactionCount() (*big.Int, error) {
return s.host.Storage().FetchTotalTxCount()
}
// GetTotalTransactionsQuery returns the number of recorded transactions on the network.
func (s *ScanAPI) GetTotalTransactionsQuery() (*big.Int, error) {
return s.host.Storage().FetchTotalTxsQuery()
}
// GetBatchListingNew returns a paginated list of batches
func (s *ScanAPI) GetBatchListingNew(pagination *common.QueryPagination) (*common.BatchListingResponse, error) {
return s.host.Storage().FetchBatchListing(pagination)
}
// GetBatchListing returns the deprecated version of batch listing
func (s *ScanAPI) GetBatchListing(pagination *common.QueryPagination) (*common.BatchListingResponseDeprecated, error) {
return s.host.Storage().FetchBatchListingDeprecated(pagination)
}
// GetPublicBatchByHash returns the public batch
func (s *ScanAPI) GetPublicBatchByHash(hash common.L2BatchHash) (*common.PublicBatch, error) {
return s.host.Storage().FetchPublicBatchByHash(hash)
}
// GetBatch returns the `ExtBatch` with the given hash
func (s *ScanAPI) GetBatch(batchHash gethcommon.Hash) (*common.ExtBatch, error) {
return s.host.Storage().FetchBatch(batchHash)
}
// GetBatchByTx returns the `ExtBatch` with the given tx hash
func (s *ScanAPI) GetBatchByTx(txHash gethcommon.Hash) (*common.ExtBatch, error) {
return s.host.Storage().FetchBatchByTx(txHash)
}
// GetLatestBatch returns the head `BatchHeader`
func (s *ScanAPI) GetLatestBatch() (*common.BatchHeader, error) {
return s.host.Storage().FetchLatestBatch()
}
// GetBatchByHeight returns the `BatchHeader` with the given height
func (s *ScanAPI) GetBatchByHeight(height *big.Int) (*common.PublicBatch, error) {
return s.host.Storage().FetchBatchByHeight(height)
}
// GetRollupBySeqNo returns the `PublicRollup` that contains the batch with the given sequence number
func (s *ScanAPI) GetRollupBySeqNo(seqNo uint64) (*common.PublicRollup, error) {
return s.host.Storage().FetchRollupBySeqNo(seqNo)
}
// GetRollupListing returns a paginated list of Rollups
func (s *ScanAPI) GetRollupListing(pagination *common.QueryPagination) (*common.RollupListingResponse, error) {
return s.host.Storage().FetchRollupListing(pagination)
}
// GetLatestRollupHeader returns the head `RollupHeader`
func (s *ScanAPI) GetLatestRollupHeader() (*common.RollupHeader, error) {
return s.host.Storage().FetchLatestRollupHeader()
}
// GetPublicTransactionData returns a paginated list of transaction data
func (s *ScanAPI) GetPublicTransactionData(pagination *common.QueryPagination) (*common.TransactionListingResponse, error) {
return s.host.Storage().FetchTransactionListing(pagination)
}
// GetBlockListing returns a paginated list of blocks that include rollups
func (s *ScanAPI) GetBlockListing(pagination *common.QueryPagination) (*common.BlockListingResponse, error) {
return s.host.Storage().FetchBlockListing(pagination)
}
// GetRollupByHash returns the public rollup data given its hash
func (s *ScanAPI) GetRollupByHash(rollupHash gethcommon.Hash) (*common.PublicRollup, error) {
return s.host.Storage().FetchRollupByHash(rollupHash)
}
// GetRollupBatches returns the list of batches included in a rollup given its hash
func (s *ScanAPI) GetRollupBatches(rollupHash gethcommon.Hash) (*common.BatchListingResponse, error) {
return s.host.Storage().FetchRollupBatches(rollupHash)
}
// GetBatchTransactions returns the public tx data of all txs present in a rollup given its hash
func (s *ScanAPI) GetBatchTransactions(batchHash gethcommon.Hash) (*common.TransactionListingResponse, error) {
return s.host.Storage().FetchBatchTransactions(batchHash)
}
// These methods are for private user data, they will need to be requested with VK (e.g. via the gateway)
// GetPersonalTransactions gets the private transactions data for a given user
func (s *ScanAPI) GetPersonalTransactions(ctx context.Context, encryptedParams common.EncryptedParamsGetPersonalTransactions) (*responses.Receipts, error) {
return s.host.EnclaveClient().GetPersonalTransactions(ctx, encryptedParams)
}