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

2024.3.13 add some apis &fix some bugs #33

Merged
merged 50 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
424630e
change api name :inds_getBalancesByAddress
jonzhang708 Feb 27, 2024
a75a352
add all chain & chain stat
SeriousVv Feb 28, 2024
e456392
add all chain & chain stat
SeriousVv Feb 28, 2024
df271f5
fix openspi doc bug
SeriousVv Feb 28, 2024
4a16fd1
add all chain & chain stat
SeriousVv Feb 29, 2024
f5b8235
add all chain & chain stat
SeriousVv Feb 29, 2024
3e5ba52
add all chain & chain stat
SeriousVv Feb 29, 2024
6b7c8fd
add all chain & chain stat
SeriousVv Feb 29, 2024
4d9c751
change tx_hash field string to hash
jonzhang708 Feb 29, 2024
0f2350d
Merge branch 'main' of github.com:bradzhang717/indexer into main
jonzhang708 Feb 29, 2024
b76feec
GetTransactions add chain query
jonzhang708 Feb 29, 2024
0f49e4b
GetTransactions add chain query
jonzhang708 Feb 29, 2024
66fb850
GetTransactions add chain query
jonzhang708 Feb 29, 2024
01e3be8
GetTransactions add chain query and tx hash to []byte
jonzhang708 Feb 29, 2024
8fe52e7
GetAddressTransactions fix Record not found bug
jonzhang708 Feb 29, 2024
3121fd4
GetAddressTransactions fix Record not found bug
jonzhang708 Feb 29, 2024
44a0fa9
open sortMode
SeriousVv Mar 1, 2024
36569b4
opti GetTxByHash
SeriousVv Mar 1, 2024
8ccc88c
GetAddressTransactions return TransactionResponse
jonzhang708 Mar 1, 2024
d27980a
opti GetTxByHash
SeriousVv Mar 1, 2024
f04b8e5
opti GetTxByHash
SeriousVv Mar 3, 2024
adba207
add GetChainBlockStat
SeriousVv Mar 3, 2024
f47959a
add GetChainBlockStat
SeriousVv Mar 3, 2024
dad3aab
add index amt for txs model
jonzhang708 Mar 3, 2024
c114fa4
Merge branch 'main' of github.com:bradzhang717/indexer into main
jonzhang708 Mar 3, 2024
369786f
add
SeriousVv Mar 4, 2024
b1fb1d8
Merge remote-tracking branch 'origin/main'
SeriousVv Mar 4, 2024
2b4fa7f
add chain info ext
SeriousVv Mar 4, 2024
1d205e2
update ChainInfoExt and set value
jonzhang708 Mar 4, 2024
d374a4a
opti GetTransactions
SeriousVv Mar 5, 2024
350734a
add time utils
jonzhang708 Mar 5, 2024
c52c82a
opti GetTransactions
SeriousVv Mar 5, 2024
0492309
Merge remote-tracking branch 'origin/main'
SeriousVv Mar 5, 2024
1a94ca4
opti chain stat
SeriousVv Mar 7, 2024
fd7537f
opti deploy_time
SeriousVv Mar 7, 2024
c43285a
opti deploy_time
SeriousVv Mar 7, 2024
2d081b0
change table name to txs_new for temp testing db performance
jonzhang708 Mar 7, 2024
d7897a9
change table name to txs_new for temp testing db performance
SeriousVv Mar 7, 2024
83453d8
opti chain_info sql
SeriousVv Mar 7, 2024
d168b87
opt GroupChainBlockStat logic
jonzhang708 Mar 7, 2024
2a47570
opt GroupChainBlockStat logic
jonzhang708 Mar 7, 2024
78064c8
opt GroupChainBlockStat logic and get trs table name
jonzhang708 Mar 7, 2024
954fd34
fix time util bug
jonzhang708 Mar 7, 2024
9c24128
fix time util bug
jonzhang708 Mar 7, 2024
1ed0a99
fix GroupChainBlockStat sql error
jonzhang708 Mar 7, 2024
bb7ea37
add cache for GetAllChain
jonzhang708 Mar 10, 2024
e199745
add cache for GetChainBlockStat
jonzhang708 Mar 10, 2024
92c6061
add cache for GetChainBlockStat
jonzhang708 Mar 10, 2024
f29b844
add cache for GetChainBlockStat
jonzhang708 Mar 10, 2024
93c1ca5
add cache for GetChainBlockStat
jonzhang708 Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/uxuycom/indexer/explorer"
"github.com/uxuycom/indexer/protocol"
"github.com/uxuycom/indexer/storage"
"github.com/uxuycom/indexer/task"
"github.com/uxuycom/indexer/xylog"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -90,6 +91,9 @@ func main() {
// init protocols
protocol.InitProtocols(dCache)

// init task
task.InitTask(dbClient, &cfg)

// Listen for SIGINT and SIGTERM signals
quit := make(chan os.Signal, 1)
dEvent := devents.NewDEvents(context.TODO(), dbClient)
Expand Down
13 changes: 13 additions & 0 deletions db/20240302_create_index_txs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


Use
tap_indexer;

CREATE INDEX idx_chain_protocol_tick ON address_txs(chain,protocol,operate);
CREATE INDEX idx_chain_protocol_tick ON balance_txn(chain, protocol, tick);
CREATE INDEX idx_chain_protocol_tick ON balances(chain, protocol, tick);
CREATE INDEX idx_chain_protocol_tick ON txs(chain, protocol, tick);
CREATE INDEX idx_chain_block_height ON txs(chain, block_height);



62 changes: 0 additions & 62 deletions devents/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ package devents

import (
"encoding/json"
"flag"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/uxuycom/indexer/config"
"github.com/uxuycom/indexer/storage"
"os"
"path/filepath"
"testing"
)

func LoadConfig(cfg *config.Config, filePath string) error {
Expand Down Expand Up @@ -60,61 +56,3 @@ func LoadConfig(cfg *config.Config, filePath string) error {
}
return nil
}

func TestDBLockGetAndRelease(t *testing.T) {
// testing mysql client variable
var flagConfig string
flag.StringVar(&flagConfig, "config", "../config.json", "config file")
flag.Parse()

var cfg config.Config
if err := LoadConfig(&cfg, flagConfig); err != nil {
t.Logf("load config failed & ignore this test case. err:%v", err)
return
}

dbClient, err := storage.NewDbClient(&cfg.Database)
if err != nil {
t.Log("init db client failed & ignore this test case")
return
}

// lock
ok, err := dbClient.GetLock()
if err != nil {
t.Log("get lock failed & ignore this test case")
return
}
assert.Truef(t, ok, "get lock should success but failed")

for i := 0; i < 10; i++ {
dbClientN, errN := storage.NewDbClient(&cfg.Database)
if errN != nil {
t.Log("init db client failed & ignore this test case:", i)
continue
}

okN, errN := dbClientN.GetLock()
if errN != nil {
t.Log("get lock error & ignore this test case:", i)
continue
}
assert.Falsef(t, okN, "get lock should failed but success")
}

// release
cnt, err := dbClient.ReleaseLock()
if err != nil {
t.Log("release lock failed & ignore this test case")
return
}
assert.Equal(t, int64(1), cnt, "return cnt should be 1")

// release again
cnt, err = dbClient.ReleaseLock()
if err != nil {
t.Log("release lock failed & ignore this test case")
return
}
assert.Equal(t, int64(0), cnt, "return cnt should be 0")
}
16 changes: 16 additions & 0 deletions devents/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,22 @@ func (tc *TxResultHandler) BuildTx(e *TxResult) *model.Transaction {
} else {
trx.ChainId = e.Tx.ChainID.Int64()
}
switch trx.Op {
case OperateMint:
if e.Mint != nil {
trx.Amount = e.Mint.Amount
}
case OperateDeploy:
trx.Amount = decimal.NewFromInt(0)
case OperateTransfer:
if e.Transfer != nil {
amount := decimal.NewFromInt(0)
for _, v := range e.Transfer.Receives {
amount = amount.Add(v.Amount)
}
trx.Amount = amount
}
}
return trx
}

Expand Down
66 changes: 66 additions & 0 deletions docs/openapi_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
"",
"",
"",
"",
1
]
}
Expand Down Expand Up @@ -1132,6 +1133,71 @@
}
}
}
},
"/inds_chainBlockStat": {
"post": {
"operationId": "inds_chainBlockStat",
"deprecated": false,
"summary": "Get Chain Block Stat",
"description": "Get Chain Block Stat",
"tags": [
"JSONRPC"
],
"parameters": [],
"responses": {
"200": {
"description": "Successful response"
}
},
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"method",
"id",
"jsonrpc",
"params"
],
"properties": {
"method": {
"type": "string",
"default": "inds_chainBlockStat",
"description": "Method name"
},
"id": {
"type": "integer",
"default": 1,
"format": "int32",
"description": "Request ID"
},
"jsonrpc": {
"type": "string",
"default": "2.0",
"description": "JSON-RPC Version (2.0)"
},
"params": {
"title": "Parameters",
"type": "array",
"required": [
"jsonParam"
],
"properties": {
"jsonParam": {
"type": "string",
"default": "",
"description": "A param to include"
}
},
"default": ["avalanche"]
}
}
}
}
}
}
}
}
},
"x-headers": [],
Expand Down
147 changes: 0 additions & 147 deletions explorer/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,159 +23,12 @@
package explorer

import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/uxuycom/indexer/config"
"github.com/uxuycom/indexer/utils"
"github.com/uxuycom/indexer/xylog"
"io"
"log"
"net/http"
"strings"
"testing"
)

func TestConfigRpcTransactionDataByHash(t *testing.T) {

rpcUrl := Cfg().GetConfig().Chain.Rpc
type args struct {
method string
param string
}

tests := []struct {
name string
method string
args args
want string
}{
{
name: "test_eth_getTransactionByHash",
method: "POST",
args: args{
method: "eth_getTransactionByHash",
param: "{\"method\":\"eth_getTransactionByHash\"," +
"\"params\":[\"0x8166ff37f1fb6b1d2cdb6b8759ca4c790b1ea2ea14bee22ffc0434b81c3d2050\"],\"id\":1," +
"\"jsonrpc\":\"2.0\"}",
},
},
}
for _, tt := range tests {
client := &http.Client{}
req, err := http.NewRequest(tt.args.method, rpcUrl, strings.NewReader(tt.args.param))
if err != nil {
xylog.Logger.Error(err)
return
}

req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
if xylog.Logger != nil {
xylog.Logger.Error(err)
}
return
}
if res != nil {
defer func() {
_ = res.Body.Close()
}()
}

body, err := io.ReadAll(res.Body)
if err != nil {
xylog.Logger.Error(err)
return
}

var data map[string]interface{}
err = json.Unmarshal(body, &data)
if err != nil {
//fmt.Println("Error:", err)
xylog.Logger.Error(err)
return
}

fmt.Println("Data:", data)
if data["error"] != nil {
t.Errorf("Rpc Node Response Error: %v", data["error"])
return
}

subData := data["result"].(map[string]interface{})
fmt.Println("Data>>> :", subData["input"])

var hexString = fmt.Sprintf("%s", subData["input"])
// Decode hex string to byte slice
hexBytes, err := hex.DecodeString(hexString[2:])
if err != nil {
fmt.Println("Error decoding hex string:", err)
return
}

// Convert byte slice to string
resultString := string(hexBytes)

fmt.Println("Original Hex String:", hexString)
fmt.Println("Converted String:", resultString)
//fmt.Println("input:", data["input"])
}
}

func TestRpcEthBlockNumber(t *testing.T) {

rpcUrl := Cfg().GetConfig().Chain.Rpc
type args struct {
method string
param string
}

tests := []struct {
name string
method string
args args
want string
}{
{
name: "eth_blockNumber",
method: "POST",
args: args{
method: "eth_blockNumber",
param: "{\"method\":\"eth_blockNumber\",\"params\":[],\"id\":1,\"jsonrpc\":\"2.0\"}",
},
},
}

for _, t := range tests {
client := &http.Client{}
req, err := http.NewRequest(t.method, rpcUrl, strings.NewReader(t.args.param))

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")

res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer func() {
_ = res.Body.Close()
}()

body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

}

func Cfg() *config.Config {

var cfg *config.Config
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ require (
require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/agiledragon/gomonkey v2.0.2+incompatible // indirect
github.com/agiledragon/gomonkey/v2 v2.11.0 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.6-0.20231231005237-b1b94202082b // indirect
Expand All @@ -43,6 +45,7 @@ require (
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gookit/goutil v0.6.15 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
Expand Down Expand Up @@ -82,5 +85,4 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
github.com/gookit/goutil v0.6.15 // indirect
)
Loading
Loading