Skip to content

Commit

Permalink
Obscuroscan - Add Pagination in the list calls (Public and Encrypted) (
Browse files Browse the repository at this point in the history
…#1434)

* Add an health endpoint to OG

* lint

* Public + Personal Pagination - FE + BE

* lint

* Update go/enclave/genesis/testnet_genesis.go
  • Loading branch information
otherview authored Aug 9, 2023
1 parent 1ab9631 commit d2c7acb
Show file tree
Hide file tree
Showing 30 changed files with 1,571 additions and 1,189 deletions.
6 changes: 3 additions & 3 deletions go/common/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ type EnclaveScan interface {
// GetTotalContractCount returns the total number of contracts that have been deployed
GetTotalContractCount() (*big.Int, SystemError)

// GetReceiptsByAddress returns a list of receipts given the sender address
GetReceiptsByAddress(encryptedParams EncryptedParamsGetStorageAt) (*responses.Receipts, SystemError)
// GetCustomQuery returns the data of a custom query
GetCustomQuery(encryptedParams EncryptedParamsGetStorageAt) (*responses.PrivateQueryResponse, SystemError)

// GetPublicTransactionData returns a list of public transaction data
GetPublicTransactionData() ([]PublicTxData, SystemError)
GetPublicTransactionData(pagination *QueryPagination) (*PublicQueryResponse, SystemError)
}

// BlockSubmissionResponse is the response sent from the enclave back to the node after ingesting a block
Expand Down
16 changes: 16 additions & 0 deletions go/common/gethencoding/geth_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,19 @@ func ExtractViewingKey(vkBytesIntf interface{}) ([]byte, []byte, error) {

return vkPubkeyHexBytes, accountSignatureHexBytes, nil
}

func ExtractPrivateCustomQuery(_ interface{}, query interface{}) (*common.PrivateCustomQueryListTransactions, error) {
// Convert the map to a JSON string
jsonData, err := json.Marshal(query)
if err != nil {
return nil, err
}

var result common.PrivateCustomQueryListTransactions
err = json.Unmarshal(jsonData, &result)
if err != nil {
return nil, err
}

return &result, nil
}
65 changes: 65 additions & 0 deletions go/common/query_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package common

import (
"encoding/json"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/core/types"

"github.com/ethereum/go-ethereum/common"
)

type PrivateQueryResponse struct {
Receipts types.Receipts
Total uint64
}

type PublicQueryResponse struct {
PublicTxData []PublicTxData
Total uint64
}

type PublicTxData struct {
TransactionHash TxHash
BatchHeight *big.Int
Finality FinalityType
}

type FinalityType string

const (
MempoolPending FinalityType = "Pending"
BatchFinal FinalityType = "Final"
)

type QueryPagination struct {
Offset uint64
Size uint
}

func (p *QueryPagination) UnmarshalJSON(data []byte) error {
// Use a temporary struct to avoid infinite unmarshalling loop
type Temp struct {
Size uint `json:"size"`
Offset uint64
}

var temp Temp
if err := json.Unmarshal(data, &temp); err != nil {
return err
}

if temp.Size < 1 || temp.Size > 100 {
return fmt.Errorf("size must be between 1 and 100")
}

p.Size = temp.Size
p.Offset = temp.Offset
return nil
}

type PrivateCustomQueryListTransactions struct {
Address common.Address `json:"address"`
Pagination QueryPagination `json:"pagination"`
}
Loading

0 comments on commit d2c7acb

Please sign in to comment.