Browse Source

append new files.

410 2 năm trước cách đây
mục cha
commit
a09974671b
3 tập tin đã thay đổi với 196 bổ sung0 xóa
  1. 31 0
      web3/cal.go
  2. 126 0
      web3/rpc.go
  3. 39 0
      web3/test.go

+ 31 - 0
web3/cal.go

@@ -0,0 +1,31 @@
+package main
+
+import (
+	"fmt"
+)
+
+type tokenInfo struct {
+	hash0   string
+	hash1   string
+	symbol0 string
+	symbol1 string
+}
+
+type lpInfo struct {
+	lpHash string
+	fee    int
+	token0 *tokenInfo
+	token1 *tokenInfo
+}
+
+func main() {
+
+	topTokenList := [10]tokenInfo{}
+	lpList := [2]lpInfo{}
+
+	topTokenList[0].hash0 = "0x0a"
+	lpList[0].token0 = &topTokenList[0]
+
+	fmt.Println(lpList[0].token0.hash0)
+
+}

+ 126 - 0
web3/rpc.go

@@ -0,0 +1,126 @@
+package main
+
+import (
+	"context"
+	"github.com/ethereum/go-ethereum/log"
+	"github.com/ethereum/go-ethereum/rpc"
+	"github.com/ethereum/go-ethereum/web3/api"
+	"math/big"
+	"strconv"
+	"time"
+)
+
+func PING() (string, error) {
+	currentTime := time.Now()
+	timeString := currentTime.Format("2006-01-02 15:04:05.123")
+	return timeString, nil
+}
+
+func main() {
+	api.PrintTime("GO")
+	ipcPath := "\\\\.\\pipe\\geth.ipc"
+
+	// 使用 IPC 连接到以太坊节点
+	client, err := rpc.Dial(ipcPath)
+
+	if err != nil {
+		api.PrintTime("无法连接到以太坊节点:", err)
+	}
+
+	// 连接成功,可以使用 client 进行后续操作
+
+	// eth_call
+	var result string
+	//arg := map[string]interface{}{
+	//	"from":     "0x746Fe602eD945378478523D53007B1c9d14037Ff",
+	//	"to":       "0x746Fe602eD945378478523D53007B1c9d14037Ff",
+	//	"data":     "0x",
+	//	"value":    hexutil.Uint64(0),
+	//	"gas":      hexutil.Uint64(100000),
+	//	"gasPrice": hexutil.Uint64(100000),
+	//}
+	//api.PrintTime("eth_call")
+	//err = client.CallContext(context.Background(), &result, "eth_call", arg, "pending")
+	//api.PrintTime(result)
+
+	//
+	//err = client.CallContext(context.Background(), &result, "zdy_getPrvKey", "0x000000FB5e4fbEE939625B0099288bCF51Ed6FA1")
+	//if err != nil {
+	//	log.Fatal("无法获取信息:", err)
+	//}
+	//
+	//fmt.Println("当前结果:", result)
+
+	//err = client.CallContext(context.Background(), &result, "zdy_unLockAllAccount")
+	//if err != nil {
+	//	log.Fatal("无法获取信息:", err)
+	//}
+	//
+	//fmt.Println("当前结果:", result)
+	//
+	//arg = map[string]interface{}{
+	//	"from":     "0x000000fb5e4fbee939625b0099288bcf51ed6fa1",
+	//	"to":       "0x0000000000000000000000000000000000000000",
+	//	"data":     "0x",
+	//	"value":    hexutil.Uint64(0),
+	//	"nonce":    hexutil.Uint64(38),
+	//	"gas":      hexutil.Uint64(100000),
+	//	"gasPrice": hexutil.Uint64(10000000000),
+	//	"chainID":  "0x45c",
+	//}
+	//err = client.CallContext(context.Background(), &result, "eth_sendTransaction", arg)
+	//if err != nil {
+	//	log.Fatal("无法获取信息:", err)
+	//}
+	//
+	//fmt.Println("当前结果:", result)
+	toAddress := "0x0000000000000000000000000000000000000410"
+	gasPrice := big.NewInt(50000000410)
+	gasLimit := uint64(30000)
+	value := big.NewInt(0) // 1 ETH
+	nonce := uint64(87)
+	data := ""
+	// 获取私钥对象
+	privateKeyHex := "d18f844b8ff00c723592257d57c41b2ebef0b197c8daf4f8a5909ffd18165b8d"
+	_, rawHash, err := api.SignTransaction(nonce, toAddress, value, gasLimit, gasPrice, data, privateKeyHex)
+	//api.SpeedTest(PING)
+	//api.SpeedTest(client.CallContext, context.Background(), &result, "zdy_ping")
+	//api.PrintTime(result)
+	err = client.CallContext(context.Background(), &result, "eth_blockNumber")
+	blockNumber, _ := strconv.ParseInt(result, 0, 64)
+	api.PrintTime(blockNumber)
+
+	for {
+		err = client.CallContext(context.Background(), &result, "eth_blockNumber")
+		nowBlockNumber, _ := strconv.ParseInt(result, 0, 64)
+		if nowBlockNumber > blockNumber {
+			api.PrintTime(nowBlockNumber)
+			break
+		}
+	}
+
+	//
+	//err = client.CallContext(context.Background(), &result, "eth_sendRawTransaction", rawHash)
+	//api.PrintTime(result)
+	//
+	//gasLimit = uint64(100002)
+	//
+	//// 获取私钥对象
+	//
+	//_, rawHash, err = api.SignTransaction(nonce, toAddress, value, gasLimit, gasPrice, data, privateKeyHex)
+	//err = client.CallContext(context.Background(), &result, "zdy_sendRawTransaction", rawHash)
+	//api.PrintTime(result)
+
+	//api.PrintTime("zdy_sendRawTransaction")
+	//
+	//client.CallContext(context.Background(), &result, "zdy_sendRawTransaction", rawHash)
+	//api.PrintTime("zdy_sendRawTransaction", result)
+
+	api.PrintTime("eth_newPendingTransactionFilter")
+
+	client.CallContext(context.Background(), &result, "eth_newPendingTransactionFilter", rawHash)
+	api.PrintTime("eth_newPendingTransactionFilter", result)
+
+	api.SpeedTest(log.Info, "abc123")
+
+}

+ 39 - 0
web3/test.go

@@ -0,0 +1,39 @@
+package main
+
+import (
+	"fmt"
+)
+
+func main() {
+	myMap := make(map[string][]int)
+	myMap["key1"] = make([]int, 16)
+	myMap["key2"] = make([]int, 16)
+	myMap["key3"] = make([]int, 16)
+	myMap["key4"] = make([]int, 16)
+	myMap["key5"] = make([]int, 16)
+	myMap["key6"] = make([]int, 16)
+	myMap["key7"] = make([]int, 16)
+	myMap["key8"] = make([]int, 16)
+	myMap["key9"] = make([]int, 16)
+	myMap["key10"] = make([]int, 16)
+	myMap["key11"] = make([]int, 16)
+	myMap["key12"] = make([]int, 16)
+	myMap["key13"] = make([]int, 16)
+	myMap["key14"] = make([]int, 16)
+	myMap["key15"] = make([]int, 16)
+	myMap["key16"] = make([]int, 16)
+
+	for j := 0; j < 100; j++ {
+		i := 0
+		for key, _ := range myMap {
+			myMap[key][i] = myMap[key][i] + 1
+			//fmt.Println(key, myMap[key])
+			i++
+		}
+		//fmt.Println("---------------------------")
+	}
+
+	for key, value := range myMap {
+		fmt.Println(key, value)
+	}
+}