trx

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Trx   string = "trx"
	Trc10 string = "trc10"
	Trc20 string = "trc20"
)
View Source
const (
	Send         = "send"          // 提币 即 主地址提币到其他地址
	Receive      = "receive"       // 本平台地址 分配的用户地址收到的
	ReceiveOther = "receive_other" // 主地址收到的外来地址转帐
	Collect      = "collect"       // 本平台地址归集到主地址
	CollectOwn   = "collect_own"   // 站内转账
	CollectSend  = "collect_send"  // 本平台地址提币到站外 异常的
)

Variables

View Source
var IsMulti bool // 是否采用外部多链地址
View Source
var RPC = struct {
	Service struct{ Getinfo, GetNewAddress, ValidateAddress, ListTransactions, SendToAddress, GetRecords string }
}{
	Service: struct{ Getinfo, GetNewAddress, ValidateAddress, ListTransactions, SendToAddress, GetRecords string }{
		Getinfo:          "getinfo",
		GetNewAddress:    "getnewaddress",
		ValidateAddress:  "validateaddress",
		ListTransactions: "listtransactions",
		SendToAddress:    "sendtoaddress",
		GetRecords:       "getrecords",
	},
}

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

func GenerateRandomNumber

func GenerateRandomNumber(start int, end int, count int) []int

GenerateRandomNumber 生成count个[start,end)结束的不重复的随机数 为了用户抽奖 TODO

func Init

func Init()

Init 初始化

func InitAddressDB

func InitAddressDB(dsn string)

func InitAllContarctServer

func InitAllContarctServer(ctx context.Context, exit chan<- struct{})

InitAllContarctServer 初始化所有节点

func InitAllNode

func InitAllNode(url []string)

func InitConfig

func InitConfig()

func InitContract

func InitContract(contracts []Contract)

InitContract 初始化所有合约

func InitDB

func InitDB()

func InitLog

func InitLog()

InitLog 初始化日志文件

func InitMainAndFee

func InitMainAndFee()

InitMainAndFee 初始化主账户和手续费账户

func InitMainNode

func InitMainNode(url string)

func InitSeed

func InitSeed()

func InitWalletInfo

func InitWalletInfo()

InitWalletInfo 初始化钱包信息

func IsContract

func IsContract(contract string) bool

IsContract 判断当前合约是否存在

func NewPrivateKey

func NewPrivateKey() (int, *ecdsa.PrivateKey, error)

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func RunCollect

func RunCollect()

RunCollect 获取数据库中 大于指定余额钱包余额进行归集

func RunTransaction

func RunTransaction()

RunTransaction .

func Serv

func Serv(ctx context.Context, rpcSev Service) *http.Server

Serv 监听服务

Types

type Account

type Account struct {
	ID         int64  `xorm:"'id' pk autoincr"`
	Address    string `xorm:"'address' unique DEFAULT '' "`         // 唯一索引
	PublicKey  string `xorm:"'public_key'"  json:"publickey"`       // 公钥新版字段 如果有就是新版
	PrivateKey string `xorm:"'private_key'" sql:"comment:'地址私钥'"`   // 地址私钥
	Index      int    `xorm:"'index' DEFAULT 0" sql:"comment:'位置'"` // 唯一
	User       string `xorm:"'user'"`
	Ctime      int64  `xorm:"'ctime'"`                          // 创建时间
	Amount     int64  `xorm:"'amount' index INTEGER DEFAULT 0"` // 主链币种余额
}

Account 账户分配的地址

func SearchAccount

func SearchAccount(addr string) (*Account, error)

func (Account) TableName

func (fh Account) TableName() string

type Balance

type Balance struct {
	ID       int64  `xorm:"'id' pk autoincr"`
	Address  string `xorm:"'address' DEFAULT '' "`
	Contract string `xorm:"'contract' index"` // 哪种合约
	Amount   int64  `xorm:"'amount' index INTEGER DEFAULT 0"`
}

Balance 代币余额

func (Balance) TableName

func (fh Balance) TableName() string

type Client

type Client struct {
	NodeTrx     string          `toml:"nodeTrx"`       // 超级节点url 主节点
	NodeUrl     []string        `toml:"nodeUrl"`       // 其他节点url
	Password    string          `toml:"password"`      // 主钱包密码 加密后的
	MainAddr    string          `toml:"main_addr"`     // 主钱包地址
	MainPri     string          `toml:"main_pri"`      // 主钱包私钥
	Seed        string          `toml:"seed"`          // 私钥种子base64
	SeedPri     string          `toml:"seed_pri"`      // 私钥种子密码
	Password1   string          `toml:"password1"`     // 主钱包密码 加密后的2
	MainAddr1   string          `toml:"main_addr1"`    // 主钱包地址2
	MainPri1    string          `toml:"main_pri1"`     // 主钱包私钥
	DBAddr      string          `toml:"db_addr"`       // sqlite 地址
	DBAddrMulti string          `toml:"db_addr_multi"` // 多链地址保存mysql数据库地址
	KeyStore    string          `toml:"key_store"`     // 用户钱包保存路径
	Port        string          `toml:"port"`          // 监听端口 trx
	LogLevel    string          `toml:"logLevel"`      // 日志等级
	Count       int64           `toml:"count"`         // 批量查询交易记录个数
	Feelimit    int64           `toml:"feelimit"`      // 转账合约消耗sun个数 建议设置5000000
	PerFee      decimal.Decimal `toml:"perfee"`        // 每次归集每个合约需要手续费消耗
	MinFee      decimal.Decimal `toml:"minfee"`        // 每个地址至少保留多少trx手续费
	IsMulti     bool            `toml:"is_multi"`      // 是否采用外部地址
}

Client 钱包节点

type Collection

type Collection struct {
	TimeIntervalMin int64           `toml:"time_interval_min"` // 所有代币归集扫描间隔
	MinAmount       decimal.Decimal `toml:"min_amount"`        // trx 最小归集数目

}

Collection 归集配置

type Contract

type Contract struct {
	Port                string          `toml:"port"`       // rpc 监听端口
	Name                string          `toml:"name"`       // USDT BTT
	Type                string          `toml:"type"`       // TRC20 和 TRC10
	Contract            string          `toml:"contract"`   // 合约地址或者合约ID
	Issuer              string          `toml:"issuer"`     // 合约创建者
	Decimal             int32           `toml:"decimal"`    // 合约小数位
	CollectionMinAmount decimal.Decimal `toml:"min_amount"` // 代币最小归集数目
}

Contract 合约 TRC20 和 TRC10

type DB

type DB struct {
	*xorm.Engine
}

DB .

func NewDB

func NewDB(url string) (*DB, error)

NewDB 初始化数据库

func (*DB) Close

func (db *DB) Close()

Close 关闭数据库引擎

func (*DB) GetAccount

func (db *DB) GetAccount(from int) ([]Account, error)

GetAccount 获取所有账户

func (*DB) GetAccountMaxIndex

func (db *DB) GetAccountMaxIndex() int

func (*DB) GetAccountWithAddr

func (db *DB) GetAccountWithAddr(addr string) (*Account, error)

GetAccountWithAddr 搜索地址是否存在

func (*DB) GetAccountWithBalance

func (db *DB) GetAccountWithBalance(startid int64, count int) ([]Account, error)

GetAccountWithBalance 获取大于minAmount的所有账户

func (*DB) GetAccountWithContractBalance

func (db *DB) GetAccountWithContractBalance(contract string, minAmount, startid int64, count int) ([]Balance, error)

GetAccountWithContractBalance 获取大于minAmount的所有账户合约余额

func (*DB) GetCollestTransactions

func (db *DB) GetCollestTransactions(sTime, eTime int64, contract string) ([]Transactions, error)

GetCollestTransactions 获取指定时间段内归集交易记录

func (*DB) GetSumContractBalance

func (db *DB) GetSumContractBalance(contract string) (map[string]int64, error)

GetSumContractBalance 获取合约总余额

func (*DB) GetTransactions

func (db *DB) GetTransactions(contract, addr string, count, skip int) ([]Transactions, error)

GetTransactions 获取最近交易记录

func (*DB) InsertAccount

func (db *DB) InsertAccount(account *Account) (int64, error)

InsertAccount 插入数据

func (*DB) InsertBalance

func (db *DB) InsertBalance(account *Balance) (int64, error)

InsertBalance 插入数据

func (*DB) InsertLastBlockHeight

func (db *DB) InsertLastBlockHeight(num int64) (err error)

InsertLastBlockHeight 更新最后一次扫描高度

func (*DB) InsertTransactions

func (db *DB) InsertTransactions(transactions *Transactions) (int64, error)

InsertTransactions 插入数据

func (*DB) LoadLastBlockHeight

func (db *DB) LoadLastBlockHeight() (int64, error)

LoadLastBlockHeight 获取最后一次扫描高度 已经扫描到这个高度

func (*DB) SearchBalance

func (db *DB) SearchBalance(contract, address string) (*Balance, error)

SearchBalance 搜索余额记录是否存在

func (*DB) SearchTransactions

func (db *DB) SearchTransactions(txid string) (*Transactions, error)

SearchTransactions 搜索交易记录是否存在

func (*DB) Session

func (db *DB) Session() *xorm.Session

Session 创建事务

func (*DB) Sync

func (db *DB) Sync() error

Sync 同步数据库结构

func (*DB) UpdateAccount

func (db *DB) UpdateAccount(account *Account) (int64, error)

UpdateAccount 更新数据

type GlobalConf

type GlobalConf struct {
	Client          `toml:"client"`          // 钱包相关配置
	Scantraderecord `toml:"scantraderecord"` // 扫描交易记录配置
	Collection      `toml:"collection"`      // 钱包归集配置
	Contracts       []Contract               `toml:"contract"` // 合约
}

GlobalConf .

type OtherParam

type OtherParam struct {
	Key   string `xorm:"'key' unique"`
	Value string `xorm:"'value'"`
}

OtherParam .

func (OtherParam) TableName

func (fh OtherParam) TableName() string

TableName 表名

type Scantraderecord

type Scantraderecord struct {
	TimeIntervalSec int64 `toml:"time_interval_sec"` // 扫描间隔
	GoroutineNum    int64 `toml:"goroutine_num"`     // 扫描协程数
	MinScanBlock    int64 `toml:"min_scan_block"`    // 扫描交易记录起始位置 如果配置为正数 取最大值开始扫描 如果为负数 则取绝对值 从绝对值位置开始扫描,不取最大值开始扫描
}

Scantraderecord 扫描交易记录配置

type Service

type Service struct {
	zenrpc.Service
	Contract string
	Port     string
}

Service Trx 钱包信息

func (Service) GetNewAddress

func (as Service) GetNewAddress() (string, error)

GetNewAddress 获取新地址

func (Service) GetRecords

func (as Service) GetRecords(sTime, eTime int64) ([]util.SummaryData, error)

GetRecords 归集交易记录 中转记录

func (Service) Getinfo

func (as Service) Getinfo() util.Info

Getinfo 获取钱包信息

func (Service) Invoke

func (s Service) Invoke(ctx context.Context, method string, params json.RawMessage) zenrpc.Response

Invoke is as generated code from zenrpc cmd

func (Service) ListTransactions

func (as Service) ListTransactions(addr string, count, skip int) ([]util.Transactions, error)

ListTransactions 获取指定地址最近的交易记录

func (Service) SMD

func (Service) SMD() smd.ServiceInfo

func (Service) SendToAddress

func (as Service) SendToAddress(addr string, amount json.Number) (string, error)

SendToAddress 提币请求

func (Service) ValidateAddress

func (as Service) ValidateAddress(addr string) util.ValidateAddress

ValidateAddress 校验地址

type Transactions

type Transactions struct {
	ID          int64  `xorm:"'id' pk autoincr" json:"-"`
	TxID        string `xorm:"'tx_id'" json:"txid"`
	BlockHeight int64  `xorm:"'block_height'" json:"blockheight"`
	PublicKey   string `xorm:"'public_key'"  json:"publickey"` // 公钥新版字段 如果有就是新版
	Address     string `xorm:"'address' index" json:""`
	FromAddress string `xorm:"'from_address'" json:"fromaddress"`
	Contract    string `xorm:"'contract' index"` // 哪种合约
	Amount      string `xorm:"'amount'" json:"amount"`
	Fee         string `xorm:"'fee'" json:"fee"` // 保留字段
	Timestamp   int64  `xorm:"'timestamp'"`
	Type        string `xorm:"'type'"` // send recive collect
}

Transactions .

Jump to

Keyboard shortcuts

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