service

package
v0.0.0-...-855f182 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateFormat = "20060102"
)

Variables

This section is empty.

Functions

func GetBlockFromJson

func GetBlockFromJson(json string) (*Block, []*Tx)

*

{
        "number": "0xf3f088",
        "hash": "0xb49d607f5b80890531e3e1d57798a7573cf8e18048ec0df34e3c81d48115078f",

"transactions":[

{
             "blockHash": "0xb49d607f5b80890531e3e1d57798a7573cf8e18048ec0df34e3c81d48115078f",
             "blockNumber": "0xf3f088",
             "hash": "0x66db3e5d338a7c4e62a5e93c91cdadfa3137f192a492397abdc986eb3b42bdb9",
             "accessList": [
                 {
                     "address": "0xe37009f6a756e8997fac8da44da7b5b87731fc22",
                     "storageKeys": [
                         "0xc4ba43fad33cbfd83623af6a18d276f51e6983dfa3b7cbdfca86c9d20686f31a",
                         "0xda08f9c72fdaacc1a51cab773779619b140e9591e39b9b47cb79ad0c3fcbdbc1"
                     ]
                 },
                 {
                     "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                     "storageKeys": [
                         "0x74ca828535d35a5b1358536ee1cd8c04d06a7c9414e4288c637fc0440236a8c4",
                         "0xe82d4ace14a34d99367f5c69eb6b54767615f9cc44834d5cf79494c9672644a9"
                     ]
                 },
                 {
                     "address": "0x6fa870fc1f1d206f689621990bacf31fde420367",
                     "storageKeys": [
                         "0x0000000000000000000000000000000000000000000000000000000000000006",
                         "0x0000000000000000000000000000000000000000000000000000000000000007",
                         "0x0000000000000000000000000000000000000000000000000000000000000009",
                         "0x000000000000000000000000000000000000000000000000000000000000000a",
                         "0x000000000000000000000000000000000000000000000000000000000000000c",
                         "0x0000000000000000000000000000000000000000000000000000000000000008"
                     ]
                 }
             ],
             "chainId": "0x1",
             "from": "0x4321d28bb600e85400e5658e0530c457e2f03250",
             "gas": "0x2d8b2",
             "gasPrice": "0x2aedb2837",
             "input": "0x066fa870fc1f1d206f689621990bacf31fde420367000000840968310ee5",
             "maxFeePerGas": "0x2aedb2837",
             "maxPriorityFeePerGas": "0x0",
             "nonce": "0x5d1",
             "r": "0xf0589386446e1e4e08987c981483b4ea987e3cca166d61fe900f9f24fcdcf7fe",
             "s": "0x38b1f53807a6da002f1ee62e41403e00f08bc6d25576b7becdea7c99d4ed57aa",
             "to": "0xe9e83e5bf3d200e48059085b780031002200c100",
             "transactionIndex": "0x0",
             "type": "0x2",
             "v": "0x0",
             "value": "0x150f"
         }

],

    "difficulty": "0x0",
    "extraData": "0x627920406275696c64657230783639",
    "gasLimit": "0x1c9c380",
    "gasUsed": "0xc3fd9d",
    "logsBloom": "0xcff73416c8861815909c01c9b99bf32c5952375919140225d08114d4d912895576d64b2985ce445860d3b270028d07ced68209624e2829a1a2f312aa1a7ff40ef886a0dd69888f6ce913a43eeb5632228e80092798604742004b3cc1cd443d01929491a50efa2604ca76ff880ae4c9624a22d960415a6d5490dad592a08e40000a06931052271016954e0e2045121cce9450d091c3cc04582ea924dd2018099d8fd94577a9096ef23a2341d0dc9496100154860229c4afeb795d94ec0291acf5031ef40b26092958559850042436c28b5c3b364a5d1e4a1d7280b923547c360030b6ab9d40a03c68a0848f6088050e0a3456604c00c80e5ddd9eb8d0920bda86",
    "miner": "0x690b9a9e9aa1c9db991c7721a92d351db4fac990",
    "mixHash": "0x3d7e8678c2c523c20e27e2a024a277a4b4bdcd6315f2d51a38bfa5cf6a1dc654",
    "nonce": "0x0000000000000000",
    "parentHash": "0x73b66f8d4a99efe315b3a2bb82787c93693ef3e7f23a232c245f402f69576bcf",
    "receiptsRoot": "0x59adae8e952f90e9653e71a866a90b051b9307636698f6aa4eeb07ba820709d0",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0xe610",
    "stateRoot": "0x46d87b856a87ec0f9a4dd5dd1fbb4ca00d7210b2f58c63a5187d2ebdb3d0f478",
    "timestamp": "0x63759f6b",
    "totalDifficulty": "0xc70d815d562d3cfa955",
    "transactionsRoot": "0xf25865fe021fa09e3d5dbbcc215430e3556a72f4f577c982e968570171f26e4a",
    "uncles": [],
    "baseFeePerGas": "0x2aedb2837"
}

func HexToInt

func HexToInt(hex string) (string, error)

Types

type Block

type Block struct {
	Id              int64    `json:"id" gorm:"column:id"`
	BlockHash       string   `json:"hash" gorm:"column:hash"`
	BlockTime       string   `json:"timestamp" gorm:"column:block_time"`
	BlockStatus     string   `json:"blockStatus" gorm:"column:block_status"`
	BlockNumber     string   `json:"number" gorm:"column:block_number"`
	ParentHash      string   `json:"parentHash" gorm:"column:parent_hash"`
	BlockReward     string   `json:"blockReward" gorm:"column:block_reward"`
	FeeRecipient    string   `json:"feeRecipient" gorm:"column:fee_recipient"`
	TotalDifficulty string   `json:"totalDifficulty" gorm:"column:total_difficulty"`
	BlockSize       string   `json:"size" gorm:"column:block_size"`
	GasLimit        string   `json:"gasLimit" gorm:"column:gas_limit"`
	GasUsed         string   `json:"gasUsed" gorm:"column:gas_used"`
	BaseFee         string   `json:"baseFeePerGas" gorm:"column:base_fee_per_gas"`
	ExtraData       string   `json:"extraData" gorm:"column:extra_data"`
	Root            string   `json:"stateRoot" gorm:"column:state_root"`
	Transactions    []string `json:"transactions" gorm:"column:transactions"`
	TxRoot          string   `json:"transactionsRoot" gorm:"column:transactions_root"`
	ReceiptRoot     string   `json:"receiptsRoot" gorm:"column:receipts_root"`
	Coinbase        string   `json:"miner" gorm:"column:miner"`
	Nonce           string   `json:"nonce" gorm:"column:nonce"`
}

type BlockChainInterface

type BlockChainInterface interface {
	GetTx(txHash string, task *config.TxTask, log *logrus.Entry) *Tx
	GetReceipt(txHash string, task *config.ReceiptTask, log *logrus.Entry) *Receipt
	GetReceiptByBlock(blockHash, number string, task *config.ReceiptTask, log *logrus.Entry) []*Receipt
	GetBlockByNumber(blockNumber string, task *config.BlockTask, log *logrus.Entry) (*Block, []*Tx)

	GetBlockByHash(blockHash string, cfg *config.BlockTask, log *logrus.Entry) (*Block, []*Tx)

	BalanceCluster(key string, clusterList []*config.FromCluster) (*config.FromCluster, error)
	Monitor()
}

BlockChainInterface 公链接口

type Common

type Common interface {
	Start()
	Stop()
}

type KafkaInterface

type KafkaInterface interface {
	//ProductMessage 生产消息到指定kafka.topic
	ProductMessage(msg *kafka.Message)
}

KafkaInterface 接口

type Logs

type Logs []struct {
	BlockHash        string   `json:"blockHash" gorm:"column:block_hash"`
	Address          string   `json:"address" gorm:"column:address"`
	LogIndex         string   `json:"logIndex" gorm:"column:log_index"`
	Data             string   `json:"data" gorm:"column:data"`
	Removed          bool     `json:"removed" gorm:"column:removed"`
	Topics           []string `json:"topics" gorm:"column:topics"`
	BlockNumber      string   `json:"blockNumber" gorm:"column:block_number"`
	TransactionIndex string   `json:"transactionIndex" gorm:"column:transaction_index"`
	TransactionHash  string   `json:"transactionHash" gorm:"column:transaction_hash"`
}

type NodeInfo

type NodeInfo struct {
	Ip         string    `json:"ip"`
	Host       string    `json:"host"`
	Info       string    `json:"info"`   //json 对象
	NodeId     string    `json:"nodeId"` //node 唯一标识
	CreateTime time.Time `json:"createTime" gorm:"column:create_time"`
}

type NodeInterface

type NodeInterface interface {
	//PushNodeInfo  定时的上传node info (20s)
	PushNodeInfo(node *NodeInfo)
}

NodeInterface 节点信息接口

type NodeSource

type NodeSource struct {
	Id          int64     `json:"id" gorm:"column:id"`
	BlockChain  int       `json:"blockChain" gorm:"column:block_chain"` // 公链code
	TxHash      string    `json:"txHash" gorm:"column:tx_hash"`
	BlockHash   string    `json:"blockHash" gorm:"column:block_hash"`
	BlockNumber string    `json:"blockNumber" gorm:"column:block_number"`
	SourceType  int       `json:"sourceType" gorm:"column:source_type"` // 任务类型 1: 交易 2:区块 3.收据
	CreateTime  time.Time `json:"createTime" gorm:"column:create_time"`
}

type NodeTask

type NodeTask struct {
	Id          int64  `json:"id"  gorm:"column:id"`
	NodeId      string `json:"nodeId" gorm:"column:node_id"`
	BlockNumber string `json:"blockNumber" gorm:"column:block_number"`
	BlockHash   string `json:"blockHash" gorm:"column:block_hash"`
	TxHash      string `json:"txHash" gorm:"column:tx_hash"`
	TaskType    int8   `json:"taskType" gorm:"column:task_type"` // 0:保留 1:同步Tx. 2:同步Block 3:同步Receipt
	BlockChain  int    `json:"blockChain" gorm:"column:block_chain"`
	TaskStatus  int    `json:"taskStatus" gorm:"column:task_status"` //0: 初始 1: 成功. 2: 失败.  3: 执行中 其他:重试次数
}

type Receipt

type Receipt struct {
	Id                int64  `json:"id"`
	BlockHash         string `json:"blockHash" gorm:"column:block_hash"`
	LogsBloom         string `json:"logsBloom" gorm:"column:logs_bloom"`
	ContractAddress   string `json:"contractAddress" gorm:"column:contract_address"`
	TransactionIndex  string `json:"transactionIndex" gorm:"column:transaction_index"`
	Type              string `json:"type" gorm:"column:tx_type"`
	TransactionHash   string `json:"transactionHash" gorm:"column:transaction_hash"`
	GasUsed           string `json:"gasUsed" gorm:"column:gas_used"`
	BlockNumber       string `json:"blockNumber" gorm:"column:block_number"`
	CumulativeGasUsed string `json:"cumulativeGasUsed" gorm:"column:cumulative_gas_used"`
	From              string `json:"from" gorm:"column:from_addr"`
	To                string `json:"to" gorm:"column:to_addr"`
	EffectiveGasPrice string `json:"effectiveGasPrice" gorm:"column:effective_gas_price"`
	Logs              *Logs  `json:"logs" gorm:"column:logs"`
	CreateTime        string `json:"createTime" gorm:"column:create_time"` // 2006-01-02
	Status            string `json:"status" gorm:"column:status"`
}

func GetReceiptFromJson

func GetReceiptFromJson(js string) *Receipt

func GetReceiptListFromJson

func GetReceiptListFromJson(js string) []*Receipt

type TaskInterface

type TaskInterface interface {
	GetTaskWithTx(blockChain int, nodeId string) ([]*NodeTask, error)
	GetTaskWithReceipt(blockChain int, nodeId string) ([]*NodeTask, error)
	GetTaskWithBlock(blockChain int, nodeId string) ([]*NodeTask, error)
	UpdateTaskStatus(id int64, status int) error
	AddTaskSource(source *NodeSource) error
	AddNodeTask(list []*NodeTask) error
	UpdateNodeTaskStatusWithTx(task *NodeTask) error
	UpdateNodeTaskListStatusWithTx(txHashList []string, taskType int, blockChain int, taskStatus int) error
}

type Tx

type Tx struct {
	Id          int64  `json:"id" gorm:"column:id"`
	TxHash      string `json:"hash" gorm:"column:hash"`
	TxTime      string `json:"txTime" gorm:"column:tx_time"`
	TxStatus    string `json:"txStatus" gorm:"column:tx_status"`
	BlockNumber string `json:"blockNumber" gorm:"column:block_number"`
	FromAddr    string `json:"from" gorm:"column:from_addr"`
	ToAddr      string `json:"to" gorm:"column:to_addr"`
	Value       string `json:"value" gorm:"column:value"`
	Fee         string `json:"fee" gorm:"column:fee"`
	GasPrice    string `json:"gasPrice" gorm:"column:gas_price"`
	MaxPrice    string `json:"maxFeePerGas" gorm:"column:max_fee_per_gas"`
	GasLimit    string `json:"gas" gorm:"column:gas"`
	GasUsed     string `json:"gasUsed" gorm:"column:gas_used"`
	BaseFee     string `json:"baseFeePerGas" gorm:"column:base_fee_per_gas"`
	PriorityFee string `json:"maxPriorityFeePerGas" gorm:"column:max_priority_fee_per_gas"`
	InputData   string `json:"input" gorm:"column:input_data"`
	BlockHash   string `json:"blockHash" gorm:"column:block_hash"`

	TransactionIndex string `json:"transactionIndex" gorm:"column:transaction_index"`
	Type             string `json:"type" gorm:"column:tx_type"`
}

func GetTxFromJson

func GetTxFromJson(json string) *Tx

*

{
        "blockHash": "0xb49d607f5b80890531e3e1d57798a7573cf8e18048ec0df34e3c81d48115078f",
        "blockNumber": "0xf3f088",
        "hash": "0x5917da4788cdc1383215541744beb93fd804c1902e221d2c5555ce99d9bfff42",
        "accessList": [],
        "chainId": "0x1",
        "from": "0xf4e07370db628044ee8556d1dedb0417bd518970",
        "gas": "0x186a0",
        "gasPrice": "0x2ea75f237",
        "input": "0x095ea7b3000000000000000000000000a152f8bb749c55e9943a3a0a3111d18ee2b3f94effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
        "maxFeePerGas": "0x45ecedb30",
        "maxPriorityFeePerGas": "0x3b9aca00",
        "nonce": "0x0",
        "r": "0x5db86fbd5caf3b3a0896762e90cf99502671b856d8912c059facd2cf9fb1504b",
        "s": "0x43f6c37ea28057e3768fdc1504dee4e362237c26a0582aad57fe94e504372248",
        "to": "0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce",
        "transactionIndex": "0x9a",
        "type": "0x2",
        "v": "0x0",
        "value": "0x0"
    }

Directories

Path Synopsis
cmd
db

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL