Commit ac99774f authored by M an's avatar M an

Merge branch 'main'

parents 7416942a f9a7b32c
Pipeline #544 failed with stages
package main
import (
"context"
"fmt"
"log"
"math/big"
common "github.com/ethereum/go-ethereum/common"
types "github.com/ethereum/go-ethereum/core/types"
ethclient "github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("https://galaxy.block.caduceus.foundation")
if err != nil {
log.Fatal(err)
}
pendingVerifyAddress := "0x61704EFB8b8120c03C210cAC5f5193BF8c80852a"
// Get the last block height
num := getLastTimeBlockNumber()
header, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
log.Fatalf(err.Error())
}
newBlockNum := header.Number.Int64()
for i := num; i < newBlockNum; i++ {
fmt.Println("current scan block number:", i)
if i == 6917803 {
break
}
// Get tx with in a block
if getBlockTxThroughAddress(client, big.NewInt(i), pendingVerifyAddress) {
fmt.Println("verify success:", pendingVerifyAddress)
break
}
}
// Get the tx in the block through the block hash
getTxThroughBlockTx(client, header.Hash().String())
}
func getBlockTxThroughAddress(client *ethclient.Client, blockNumber *big.Int, verifyAddress string) (verifyStatus bool) {
// Specify the block number and get the transactions in the block
block, err := client.BlockByNumber(context.Background(), big.NewInt(blockNumber.Int64()))
if err != nil {
return false
}
for _, tx := range block.Transactions() {
fmt.Println("Hash:", tx.Hash().Hex())
fmt.Println("Value:", tx.Value().String())
fmt.Println("Gas:", tx.Gas())
fmt.Println("GasPrice:", tx.GasPrice().Uint64())
fmt.Println("Nonce:", tx.Nonce())
// fmt.Println("Data:", tx.Data())
chainID, err := client.NetworkID(context.Background())
if err != nil {
log.Fatal(err)
}
msg, err := tx.AsMessage(types.NewEIP155Signer(chainID), big.NewInt(1000))
if err == nil {
fmt.Println("From:", msg.From().Hex())
}
toAddress := tx.To().Hex()
if verifyAddress == toAddress {
fmt.Println("To:", toAddress)
return true
}
fmt.Println("NotTo:", toAddress)
receipt, err := client.TransactionReceipt(context.Background(), tx.Hash())
if err != nil {
log.Fatal(err)
}
fmt.Println("receiptStatus:", receipt.Status)
// Get tx status
_, isPending, err := client.TransactionByHash(context.Background(), tx.Hash())
if err != nil {
log.Fatal(err)
}
fmt.Println("txStatus:", isPending) // false
fmt.Println("---------------------------")
}
return false
}
func getTxThroughBlockTx(client *ethclient.Client, tx string) {
// Specify the block Hash to get the transactions in the block
blockHash := common.HexToHash(tx)
count, err := client.TransactionCount(context.Background(), blockHash)
if err != nil {
log.Fatal(err)
}
for idx := uint(0); idx < count; idx++ {
tx, err := client.TransactionInBlock(context.Background(), blockHash, idx)
if err != nil {
log.Fatal(err)
}
fmt.Println(tx.Hash().Hex())
}
}
func getLastTimeBlockNumber() (number int64) {
number = 6916803
return
}
package config
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
)
// 这个只是一个简单的版本只是获取QQ邮箱并且没有进行封装操作,另外爬出来的数据也没有进行去重操作
var (
// \d是数字
reQQEmail = `(\d+)@qq.com`
)
// 爬邮箱
func GetEmail() {
// 1.去网站拿数据
resp, err := http.Get("https://tieba.baidu.com/p/6051076813?red_tag=1573533731")
HandleError(err, "http.Get url")
defer resp.Body.Close()
// 2.读取页面内容
pageBytes, err := ioutil.ReadAll(resp.Body)
HandleError(err, "ioutil.ReadAll")
// 字节转字符串
pageStr := string(pageBytes)
//fmt.Println(pageStr)
// 3.过滤数据,过滤qq邮箱
re := regexp.MustCompile(reQQEmail)
// -1代表取全部
results := re.FindAllStringSubmatch(pageStr, -1)
//fmt.Println(results)
// 遍历结果
for _, result := range results {
fmt.Println("email:", result[0])
fmt.Println("qq:", result[1])
}
}
// 处理异常
func HandleError(err error, why string) {
if err != nil {
fmt.Println(why, err)
}
}
func Init() {
GetEmail()
}
package config
import (
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/jinzhu/gorm"
"github.com/jmoiron/sqlx"
)
type Person struct {
UserId int `db:"user_id"`
Username string `db:"username"`
Sex string `db:"sex"`
Email string `db:"email"`
}
type Place struct {
Country string `db:"country"`
City string `db:"city"`
TelCode int `db:"telcode"`
}
var Db *sqlx.DB
var redisConncet redis.Conn
func init() {
// connect mysql
database, err := sqlx.Open("mysql", "root:root@tcp(127.0.0.1:3306)/test")
if err != nil {
fmt.Println("open mysql failed,", err)
return
}
Db = database
defer Db.Close() // 注意这行代码要写在上面err判断的下面
// connect Redis
c, err := redis.Dial("tcp", "localhost:6379")
if err != nil {
fmt.Println("conn redis failed,", err)
return
}
redisConncet = c
fmt.Println("redis conn success")
defer c.Close()
}
func operateMysql() {
r, err := Db.Exec("insert into person(username, sex, email)values(?, ?, ?)", "stu001", "man", "stu01@qq.com")
if err != nil {
fmt.Println("exec failed, ", err)
return
}
id, err := r.LastInsertId()
if err != nil {
fmt.Println("exec failed, ", err)
return
}
fmt.Println("insert succ:", id)
}
func operateRedis() {
r, err := redis.Int(redisConncet.Do("Get", "abc"))
if err != nil {
fmt.Println("get abc failed,", err)
return
}
fmt.Println(r)
}
type Product struct {
gorm.Model
Code string
Price uint
}
func gorm_test() {
db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
if err != nil {
panic("failed to connect database")
}
defer db.Close()
//自动检查 Product 结构是否变化,变化则进行迁移
db.AutoMigrate(&Product{})
// 增
db.Create(&Product{Code: "L1212", Price: 1000})
// 查
var product Product
db.First(&product, 1) // 找到id为1的产品
db.First(&product, "code = ?", "L1212") // 找出 code 为 l1212 的产品
// 改 - 更新产品的价格为 2000
db.Model(&product).Update("Price", 2000)
// 删 - 删除产品
db.Delete(&product)
}
module GoChainDemo
go 1.19
require github.com/ethereum/go-ethereum v1.10.23
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/astaxie/beego v1.12.3 // indirect
github.com/beego/bee v1.12.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cosiner/argv v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/flosch/pongo2 v0.0.0-20200913210552-0d938eb266f3 // indirect
github.com/flosch/pongo2/v6 v6.0.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gadelkareem/delve v1.4.2-0.20200619175259-dcd01330766f // indirect
github.com/garyburd/redigo v1.6.3 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/gorm v1.9.16 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/lib/pq v1.10.6 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/peterh/liner v1.2.2 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/smartwalle/pongo2render v1.0.2 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
go.starlark.net v0.0.0-20220817180228-f738f5508c12 // indirect
golang.org/x/arch v0.0.0-20220823144127-ada1728cebaa // indirect
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment