Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(taiko-client): preconfirmation indexing #17866

Merged
merged 16 commits into from
Aug 12, 2024
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/cyberhorsey/webutils v0.0.0-20230314183728-56890c6ddbe7
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/dgraph-io/badger/v4 v4.2.0
github.com/ethereum-optimism/optimism v1.7.4
github.com/ethereum/go-ethereum v1.13.15
github.com/go-git/go-git/v5 v5.12.0
Expand Down Expand Up @@ -66,7 +67,6 @@ require (
github.com/btcsuite/btcd v0.24.0 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
Expand All @@ -87,7 +87,7 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/dgraph-io/ristretto v0.0.4-0.20210318174700-74754f61e018 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
Expand Down Expand Up @@ -123,9 +123,11 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8 // indirect
github.com/google/gopacket v1.1.19 // indirect
Expand Down
17 changes: 7 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
Expand Down Expand Up @@ -170,8 +167,6 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU=
github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down Expand Up @@ -258,8 +253,10 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeC
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/dgraph-io/ristretto v0.0.4-0.20210318174700-74754f61e018 h1:cNcG4c2n5xanQzp2hMyxDxPYVQmZ91y4WN6fJFlndLo=
github.com/dgraph-io/ristretto v0.0.4-0.20210318174700-74754f61e018/go.mod h1:MIonLggsKgZLUSt414ExgwNtlOL5MuEoAJP514mwGe8=
github.com/dgraph-io/badger/v4 v4.2.0 h1:kJrlajbXXL9DFTNuhhu9yCx7JJa4qpYWxtE8BzuWsEs=
github.com/dgraph-io/badger/v4 v4.2.0/go.mod h1:qfCqhPoWDFJRx1gp5QwwyGo8xk1lbHUxvK9nK0OGAak=
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
Expand Down Expand Up @@ -463,6 +460,8 @@ github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47 h1:k4Tw0nt6lwr
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/flatbuffers v1.12.1 h1:MVlul7pQNoDzWRLTw5imwYsl+usrS1TXG2H4jg6ImGw=
github.com/google/flatbuffers v1.12.1/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=
github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -1123,7 +1122,6 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY=
Expand Down Expand Up @@ -1165,8 +1163,6 @@ github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDdvS342BElfbETmL1Aiz3i2t0zfRj16Hs=
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
github.com/taikoxyz/optimism v0.0.0-20240624055706-43346f17fbdb h1:t4JcXSwxpUIYq5HrIYCkIfRBc/cytoC6X4YjeJF+qck=
github.com/taikoxyz/optimism v0.0.0-20240624055706-43346f17fbdb/go.mod h1:jKn73pLX8eDIG0Y3XeuUSetepecM8OvRflyPHbi05B4=
github.com/taikoxyz/optimism v0.0.0-20240627102435-4845247ff00c h1:Hfhh/icxShwpLdX7RqYzZN1EU40MGWhvSXc2V+ZzTxw=
github.com/taikoxyz/optimism v0.0.0-20240627102435-4845247ff00c/go.mod h1:jKn73pLX8eDIG0Y3XeuUSetepecM8OvRflyPHbi05B4=
github.com/taikoxyz/taiko-geth v0.0.0-20240504072040-7e1b8b65a3f8 h1:z4juQ4Nyp2T836JTCNC8t3vrbr0K9v2pPUV/ir2dy9s=
Expand Down Expand Up @@ -1551,6 +1547,7 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
29 changes: 29 additions & 0 deletions packages/taiko-client/cmd/flags/preconfapi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flags

import (
"time"

"github.com/urfave/cli/v2"
)

Expand All @@ -13,6 +15,27 @@ var (
Value: 9871,
EnvVars: []string{"PRECONFAPI_PORT"},
}
PollingInterval = &cli.DurationFlag{
Name: "preconfapi.pollingInterval",
Usage: "Interval at which to poll",
Category: preconfAPICategory,
Value: 1 * time.Second,
EnvVars: []string{"POLLING_INTERVAL"},
}
DBPath = &cli.StringFlag{
YoGhurt111 marked this conversation as resolved.
Show resolved Hide resolved
Name: "preconfapi.dbPath",
Usage: "DB Path",
Category: preconfAPICategory,
Value: "/tmp/badgerdb",
EnvVars: []string{"DB_PATH"},
}
CORSOrigins = &cli.StringSliceFlag{
Name: "preconfapi.corsORigins",
Usage: "Cors Origins",
Category: preconfAPICategory,
EnvVars: []string{"CORS_ORIGINS"},
Required: true,
}
)

// PreconfAPIFlags contains all preconfirmations API flags
Expand All @@ -21,4 +44,10 @@ var PreconfAPIFlags = []cli.Flag{
TxGasLimit,
PreconfAPIHTTPServerPort,
BlobAllowed,
PollingInterval,
L2HTTPEndpoint,
Verbosity,
LogJSON,
DBPath,
CORSOrigins,
}
4 changes: 4 additions & 0 deletions packages/taiko-client/preconfapi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
L2_HTTP=https://rpc.helder.taiko.xyz \
TAIKO_L1=0xf92d16327ADB54e13D13A90e7Cd092962c9e7a8f \
CORS_ORIGINS="*" \
go run cmd/main.go preconfapi
10 changes: 10 additions & 0 deletions packages/taiko-client/preconfapi/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package preconfapi

import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli/v2"

Expand All @@ -12,6 +14,10 @@ type Config struct {
BlobAllowed bool
HTTPPort uint64
ProposeBlockTxGasLimit uint64
PollingInterval time.Duration
L2HTTPEndpoint string
DBPath string
CORSOrigins []string
}

// NewConfigFromCliContext initializes a Config instance from
Expand All @@ -22,5 +28,9 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
BlobAllowed: c.Bool(flags.BlobAllowed.Name),
HTTPPort: c.Uint64(flags.PreconfAPIHTTPServerPort.Name),
ProposeBlockTxGasLimit: c.Uint64(flags.TxGasLimit.Name),
PollingInterval: c.Duration(flags.PollingInterval.Name),
L2HTTPEndpoint: c.String(flags.L2HTTPEndpoint.Name),
DBPath: c.String(flags.DBPath.Name),
CORSOrigins: c.StringSlice(flags.CORSOrigins.Name),
}, nil
}
118 changes: 118 additions & 0 deletions packages/taiko-client/preconfapi/model/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package model

type Transaction struct {
To *AddressParam `json:"to"`
CreatedContract *AddressParam `json:"created_contract"`
Hash string `json:"hash"`
Result string `json:"result"`
Confirmations int `json:"confirmations"`
Status *string `json:"status"`
Block *int `json:"block"`
Timestamp *string `json:"timestamp"`
ConfirmationDuration []int `json:"confirmation_duration"`
From AddressParam `json:"from"`
Value string `json:"value"`
Fee Fee `json:"fee"`
GasPrice string `json:"gas_price"`
Type *int `json:"type"`
GasUsed *uint64 `json:"gas_used"`
GasLimit uint64 `json:"gas_limit"`
MaxFeePerGas *string `json:"max_fee_per_gas"`
MaxPriorityFeePerGas *string `json:"max_priority_fee_per_gas"`
PriorityFee *string `json:"priority_fee"`
BaseFeePerGas *string `json:"base_fee_per_gas"`
TxBurntFee *string `json:"tx_burnt_fee"`
Nonce int `json:"nonce"`
Position *uint `json:"position"`
RevertReason *TransactionRevertReason `json:"revert_reason"`
RawInput string `json:"raw_input"`
DecodedInput *DecodedInput `json:"decoded_input"`
TokenTransfers *[]TokenTransfer `json:"token_transfers"`
TokenTransfersOverflow bool `json:"token_transfers_overflow"`
ExchangeRate string `json:"exchange_rate"`
Method *string `json:"method"`
TxTypes []TransactionType `json:"tx_types"`
TxTag *string `json:"tx_tag"`
Actions []TxAction `json:"actions"`
L1Fee *string `json:"l1_fee"`
L1FeeScalar *string `json:"l1_fee_scalar"`
L1GasPrice *string `json:"l1_gas_price"`
L1GasUsed *string `json:"l1_gas_used"`
HasErrorInInternalTxs *bool `json:"has_error_in_internal_txs"`
}

type TransactionRevertReason struct {
Raw string `json:"raw"`
}

type Fee struct {
Type string `json:"type"`
Value string `json:"value"`
}

type TransactionType string

const (
TxTypeTokenTransfer TransactionType = "token_transfer"
TxTypeContractCreation TransactionType = "contract_creation"
TxTypeContractCall TransactionType = "contract_call"
TxTypeTokenCreation TransactionType = "token_creation"
TxTypeCoinTransfer TransactionType = "coin_transfer"
)

type AddressParam struct {
UserTags
Hash string `json:"hash"`
ImplementationName *string `json:"implementation_name"`
Name *string `json:"name"`
IsContract bool `json:"is_contract"`
IsVerified *bool `json:"is_verified"`
}

type DecodedInput struct {
// Define fields as needed
}

type TxAction struct {
// Define fields as needed
}

type UserTags struct {
// Define fields as needed
}

type TokenTransfer struct {
Token TokenInfo `json:"token"`
Total TokenTotal `json:"total"`
Type string `json:"type"`
TxHash string `json:"tx_hash"`
From AddressParam `json:"from"`
To AddressParam `json:"to"`
Timestamp string `json:"timestamp"`
BlockHash string `json:"block_hash"`
LogIndex string `json:"log_index"`
Method *string `json:"method,omitempty"`
}

type TokenInfo struct {
Type string `json:"type"`
// Add other fields as necessary
}

type TokenTotal struct {
Erc20TotalPayload *Erc20TotalPayload `json:"erc20_total_payload,omitempty"`
Erc721TotalPayload *Erc721TotalPayload `json:"erc721_total_payload,omitempty"`
Erc1155TotalPayload *Erc1155TotalPayload `json:"erc1155_total_payload,omitempty"`
}

type Erc20TotalPayload struct {
// Define fields as necessary
}

type Erc721TotalPayload struct {
// Define fields as necessary
}

type Erc1155TotalPayload struct {
// Define fields as necessary
}
Loading
Loading