mysql

package
v0.0.0-...-ffb6f1e Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Migrations = []*gormigrate.Migration{

	&gormigrate.Migration{
		ID: "2018-10-24T11:21:36.396Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				CreateTable(&Block{}).
				AddIndex("ix_block_timestamp", "timestamp").
				CreateTable(&Transaction{}).
				AddIndex("ix_transaction_block", "block").
				AddIndex("ix_transaction_from_nonce", "from", "nonce").
				AddIndex("ix_transaction_to", "to").
				AddIndex("ix_transaction_timestamp", "timestamp").
				CreateTable(&TransactionData{}).
				AddIndex("ix_transaction_data_digest", "digest").
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				DropTable("rp_blocks").
				DropTable("rp_transactions").
				DropTable("rp_transaction_data").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2018-10-26T16:12:44.945Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				AutoMigrate(&Block{}).
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				Model(&Block{}).
				DropColumn("orchestrator").
				DropColumn("total_mnt").
				DropColumn("total_gold").
				DropColumn("fee_mnt").
				DropColumn("fee_gold").
				DropColumn("total_user_data").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2018-10-26T17:26:26.746Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				CreateTable(&DailyStats{}).
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				DropTable("rp_daily_stats").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2018-11-12T14:16:25.368Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				Model(&Transaction{}).
				AddIndex("ix_transaction_type", "type").
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				Model(&Transaction{}).
				RemoveIndex("ix_transaction_type").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2018-12-07T16:24:44.609Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				CreateTable(&Node{}).
				AddIndex("ix_node_created_at", "created_at").
				AddIndex("ix_node_quit", "quit").
				CreateTable(&NodeReward{}).
				CreateTable(&NodeRewardTx{}).
				AddIndex("ix_node_reward_txes_tx_digest", "tx_digest").
				AddIndex("ix_node_reward_txes_tx_nonce", "tx_nonce").
				AddIndex("ix_node_reward_txes_created_at", "created_at").
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				DropTable("rp_node_reward_txes").
				DropTable("rp_node_rewards").
				DropTable("rp_nodes").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2018-12-11T16:29:49.569Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				Model(&NodeRewardTx{}).
				AddForeignKey("reward_id", "rp_node_rewards(id)", "RESTRICT", "RESTRICT").
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				Model(&NodeRewardTx{}).
				RemoveForeignKey("reward_id", "rp_node_rewards(id)").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2018-12-14T11:46:19.745Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				AutoMigrate(&Node{}).
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				Model(&Node{}).
				DropColumn("reward_history").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2019-01-20T16:40:12.752Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				AutoMigrate(&EthereumRewardTx{}).
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				DropTable(&EthereumRewardTx{}).
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2019-01-21T16:06:15.291Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				Model(&EthereumRewardTx{}).
				AddForeignKey("reward_id", "rp_node_rewards(id)", "RESTRICT", "RESTRICT").
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return tx.
				Model(&EthereumRewardTx{}).
				RemoveForeignKey("reward_id", "rp_node_rewards(id)").
				Error
		},
	},

	&gormigrate.Migration{
		ID: "2019-06-25T20:27:43.624Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				AutoMigrate(&Node{}).
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return nil
		},
	},

	&gormigrate.Migration{
		ID: "2019-07-04T15:01:21.180Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				AutoMigrate(&DailyStats{}).
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return nil
		},
	},

	&gormigrate.Migration{
		ID: "2019-07-05T13:12:21.872Z",
		Migrate: func(tx *gorm.DB) error {
			tx.LogMode(false)

			var blocks int
			if res := tx.Model(&Block{}).Count(&blocks); res.Error != nil {
				return res.Error
			}
			arr := make([]*Block, 0, 500)
			off := 0
			for blocks > 0 {
				arr = arr[:]
				if res := tx.Model(&Block{}).Offset(off).Limit(500).Scan(&arr); res.Error != nil {
					return res.Error
				}
				for _, b := range arr {
					tx.Exec(
						"UPDATE `rp_daily_stats` SET `volume_mnt`=`volume_mnt`+?, `volume_gold`=`volume_gold`+? WHERE `timestamp`=? LIMIT 1",
						b.TotalMNT, b.TotalGOLD, lib.DayStartTime(b.Timestamp),
					)
				}
				blocks -= len(arr)
				off += len(arr)
			}
			return nil
		},
		Rollback: func(tx *gorm.DB) error {
			return nil
		},
	},

	&gormigrate.Migration{
		ID: "2019-07-10T10:56:59.344Z",
		Migrate: func(tx *gorm.DB) error {
			return tx.
				AutoMigrate(&Node{}).
				Error
		},
		Rollback: func(tx *gorm.DB) error {
			return nil
		},
	},
}

Migrations array

Functions

This section is empty.

Types

type Base

type Base struct {
	CreatedAt time.Time `gorm:"NOT NULL;DEFAULT:current_timestamp"`
	UpdatedAt time.Time `gorm:"NOT NULL;DEFAULT:current_timestamp"`
}

Base model

type BaseAutoincrement

type BaseAutoincrement struct {
	Base
	ID uint64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT:true"`
}

BaseAutoincrement model

type Block

type Block struct {
	Base

	Block             uint64    `gorm:"PRIMARY_KEY;AUTO_INCREMENT:false"`
	PrevDigest        []byte    `gorm:"size:32;NOT NULL" sql:"type:binary(32);"`
	MerkleRoot        []byte    `gorm:"size:32;NOT NULL" sql:"type:binary(32);"`
	TransactionsCount uint16    `gorm:"NOT NULL"`
	SignersCount      uint16    `gorm:"NOT NULL"`
	Orchestrator      []byte    `gorm:"size:32;NOT NULL" sql:"type:binary(32);"`
	TotalMNT          string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	TotalGOLD         string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	FeeMNT            string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	FeeGOLD           string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	TotalUserData     uint64    `gorm:"NOT NULL"`
	Timestamp         time.Time `gorm:"NOT NULL;DEFAULT:current_timestamp"`
}

Block model

func (*Block) Map

func (m *Block) Map() (*types.BlockView, error)

Map ...

type DailyStats

type DailyStats struct {
	Base
	Timestamp    time.Time `gorm:"NOT NULL;DEFAULT:current_timestamp;PRIMARY_KEY;AUTO_INCREMENT:false"`
	Transactions uint64    `gorm:"NOT NULL"`
	FeeMNT       string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	FeeGOLD      string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	VolumeMNT    string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	VolumeGOLD   string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	TotalStake   string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	PriceMNTPUSD float64   `gorm:"NOT NULL"`
	PriceGOLDUSD float64   `gorm:"NOT NULL"`
	PriceMNTPBTC float64   `gorm:"NOT NULL"`
	PriceGOLDBTC float64   `gorm:"NOT NULL"`
}

DailyStats model

func (*DailyStats) Map

func (m *DailyStats) Map() (*types.DailyStatsView, error)

Map ...

type Database

type Database struct {
	*gorm.DB
}

Database data

func New

func New(connection string, multiStatements bool, maxPacket uint32) (*Database, error)

New instance

func (*Database) AddBlock

func (d *Database) AddBlock(m []*types.Block) error

AddBlock impl

func (*Database) AddNodeReward

func (d *Database) AddNodeReward(m *types.NodeReward, txs []*types.NodeRewardTx, rh []*types.NodeRewardHistory, cd *types.EthereumRewardTx) (string, error)

AddNodeReward impl

func (*Database) AddTransaction

func (d *Database) AddTransaction(m []*types.Transaction) error

AddTransaction impl

func (*Database) GetActiveNodeStats

func (d *Database) GetActiveNodeStats() (*types.NodeStatsView, error)

GetActiveNodeStats impl

func (*Database) GetBlockByID

func (d *Database) GetBlockByID(id *big.Int) (*types.BlockView, error)

GetBlockByID impl

func (*Database) GetBlockIDRange

func (d *Database) GetBlockIDRange(from, to *big.Int) ([]*big.Int, error)

GetBlockIDRange impl

func (*Database) GetBlockRangeStats

func (d *Database) GetBlockRangeStats(from, to *big.Int) (*types.BlockRangeStatsView, error)

GetBlockRangeStats impl

func (*Database) GetBlocksPreview

func (d *Database) GetBlocksPreview(from *big.Int, limit uint16) ([]*types.BlockView, error)

GetBlocksPreview impl

func (*Database) GetDailyStatsView

func (d *Database) GetDailyStatsView(timestamp time.Time) ([]*types.DailyStatsView, error)

GetDailyStatsView impl

func (*Database) GetIncompleteEthereumRewardTx

func (d *Database) GetIncompleteEthereumRewardTx() ([]*types.EthereumRewardTxView, error)

GetIncompleteEthereumRewardTx impl

func (*Database) GetIncompleteNodeRewardTx

func (d *Database) GetIncompleteNodeRewardTx() ([]*types.NodeRewardTxView, error)

GetIncompleteNodeRewardTx impl

func (*Database) GetLatestNodeReward

func (d *Database) GetLatestNodeReward() (*types.NodeRewardView, error)

GetLatestNodeReward impl

func (*Database) GetNodeList

func (d *Database) GetNodeList(fromAddress []byte, active, all bool, healthGte float64) ([]*types.NodeView, error)

GetNodeList impl

func (*Database) GetNodeRewardTxLatestNonce

func (d *Database) GetNodeRewardTxLatestNonce() (uint64, error)

GetNodeRewardTxLatestNonce impl

func (*Database) GetRewardList

func (d *Database) GetRewardList(from *uint64) ([]*types.NodeRewardView, error)

GetRewardList impl

func (*Database) GetRewardTransactionsList

func (d *Database) GetRewardTransactionsList(id uint64, fromNonce *uint64) ([]*types.NodeRewardTxView, error)

GetRewardTransactionsList impl

func (*Database) GetTransactionPreviewByDigest

func (d *Database) GetTransactionPreviewByDigest(digest []byte) (*types.TransactionView, error)

GetTransactionPreviewByDigest impl

func (*Database) GetTransactionsPreview

func (d *Database) GetTransactionsPreview(block *big.Int, addr, fromDigest []byte, txName *sumuslib.Transaction) ([]*types.TransactionView, error)

GetTransactionsPreview impl

func (*Database) IsAvailable

func (d *Database) IsAvailable() bool

IsAvailable impl

func (*Database) IsDuplicateError

func (d *Database) IsDuplicateError(err error) bool

IsDuplicateError impl

func (*Database) IsMaxPacketError

func (d *Database) IsMaxPacketError(err error) bool

IsMaxPacketError impl

func (*Database) UpdateDailyCoinsPrice

func (d *Database) UpdateDailyCoinsPrice(mntpUSD, goldUSD, mntpBTC, goldBTC float64, utc time.Time) error

UpdateDailyCoinsPrice impl

func (*Database) UpdateDailyTotalStake

func (d *Database) UpdateDailyTotalStake(a *amount.Amount, utc time.Time) error

UpdateDailyTotalStake impl

func (*Database) UpdateEthereumRewardTxStatus

func (d *Database) UpdateEthereumRewardTxStatus(id uint64, s lib.TransactionStatus, hash, message string) error

UpdateEthereumRewardTxStatus impl

func (*Database) UpdateNodeList

func (d *Database) UpdateNodeList(m []*types.Node) error

UpdateNodeList impl

func (*Database) UpdateNodeRewardTxStatus

func (d *Database) UpdateNodeRewardTxStatus(digest []byte, s lib.TransactionStatus) error

UpdateNodeRewardTxStatus impl

type EthereumRewardTx

type EthereumRewardTx struct {
	BaseAutoincrement

	RewardID   uint64 `gorm:"NOT NULL"` // FK
	Address    string `gorm:"size:64;NOT NULL"`
	Hash       string `gorm:"size:128;NOT NULL"`
	MntAmount  string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	GoldAmount string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	TxStatus   uint8  `gorm:"NOT NULL"`
	Message    string `gorm:"size:128;NOT NULL"`
}

EthereumRewardTx model

func (*EthereumRewardTx) Map

Map ...

type Node

type Node struct {
	Base

	Index          uint32    `gorm:"NOT NULL"`
	Address        []byte    `gorm:"size:32;PRIMARY_KEY;AUTO_INCREMENT:false" sql:"type:binary(32);"`
	Name           string    `gorm:"size:128;NOT NULL"`
	IP             string    `gorm:"size:32;NOT NULL"`
	MajorVersion   uint16    `gorm:"NOT NULL"`
	MinorVersion   uint16    `gorm:"NOT NULL"`
	OldVersion     bool      `gorm:"NOT NULL"`
	GenesisDigest  []byte    `gorm:"size:32;" sql:"type:binary(32);"`
	Blocks         uint64    `gorm:"NOT NULL"`
	BlocksDesync   bool      `gorm:"NOT NULL"`
	VotingPool     uint64    `gorm:"NOT NULL"`
	PendingPool    uint64    `gorm:"NOT NULL"`
	ValidSignature bool      `gorm:"NOT NULL"`
	BalanceGOLD    string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	BalanceMNT     string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	GainedGOLD     string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	GainedMNT      string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	RewardHistory  string    `gorm:"size:2048;NOT NULL"`
	Activity       float64   `gorm:"NOT NULL"`
	Quit           bool      `gorm:"NOT NULL"`
	QuitAt         time.Time `gorm:"NOT NULL;DEFAULT:current_timestamp"`
}

Node model

func (*Node) Map

func (m *Node) Map() (*types.NodeView, error)

Map ...

type NodeReward

type NodeReward struct {
	BaseAutoincrement

	BlockFrom       uint64 `gorm:"NOT NULL"`
	BlockTo         uint64 `gorm:"NOT NULL"`
	Transactions    uint64 `gorm:"NOT NULL"`
	TransferredGOLD string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	TransferredMNT  string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	RewardGOLD      string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	RewardMNT       string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
}

NodeReward model

func (*NodeReward) Map

func (m *NodeReward) Map() (*types.NodeRewardView, error)

Map ...

type NodeRewardHistoryInternal

type NodeRewardHistoryInternal struct {
	Time       uint64  `json:"t,omitempty"`
	GainedGOLD float64 `json:"g,omitempty"`
	GainedMNT  float64 `json:"m,omitempty"`
}

NodeRewardHistoryInternal model

type NodeRewardTx

type NodeRewardTx struct {
	Base

	RewardID       uint64 `gorm:"NOT NULL"` // FK
	NodeAddress    []byte `gorm:"size:32;NOT NULL" sql:"type:binary(32);"`
	NodeName       string `gorm:"size:128;NOT NULL"`
	NodeBalanceMNT string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	TxNonce        uint64 `gorm:"NOT NULL"`
	TxDigest       []byte `gorm:"size:32;NOT NULL" sql:"type:binary(32);"`
	TxToken        uint16 `gorm:"NOT NULL"`
	TxAmount       string `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	TxStatus       uint8  `gorm:"NOT NULL"`
}

NodeRewardTx model

func (*NodeRewardTx) Map

Map ...

type Transaction

type Transaction struct {
	Base

	Digest     []byte    `gorm:"size:32;PRIMARY_KEY;AUTO_INCREMENT:false" sql:"type:binary(32);"`
	Block      *uint64   `gorm:""`
	Type       uint16    `gorm:"NOT NULL"`
	Nonce      uint64    `gorm:"NOT NULL"`
	From       []byte    `gorm:"size:32;NOT NULL" sql:"type:binary(32);"`
	To         []byte    `gorm:"size:32" sql:"type:binary(32);"`
	AmountMNT  string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	AmountGOLD string    `gorm:"NOT NULL" sql:"type:decimal(38,18);"`
	Status     uint8     `gorm:"NOT NULL"`
	DataSize   uint64    `gorm:"NOT NULL"`
	DataPiece  []byte    `gorm:"size:128"`
	Timestamp  time.Time `gorm:"NOT NULL;DEFAULT:current_timestamp"`
}

Transaction model

func (*Transaction) Map

func (m *Transaction) Map() (*types.TransactionView, error)

Map ...

type TransactionData

type TransactionData struct {
	Base

	Digest []byte `gorm:"size:32;PRIMARY_KEY;AUTO_INCREMENT:false" sql:"type:binary(32);"`
	Data   []byte `gorm:"size:4096"`
	Status uint8  `gorm:"NOT NULL"`
}

TransactionData model

Jump to

Keyboard shortcuts

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