bsdb

package
v0.1.0-fix-1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BucketTableName defines the name of bucket table
	BucketTableName = "buckets"
	// ObjectTableName defines the name of object table
	ObjectTableName = "objects"
	// BlockTableName defines the name of block table
	BlockTableName = "blocks"
)

define table name constant of block syncer db

View Source
const (
	// DeletedObjectsDefaultSize defines the default size of ListDeletedObjectsByBlockNumberRange response
	DeletedObjectsDefaultSize = 1000
)

define metadata query statement

Variables

This section is empty.

Functions

func InitDB

func InitDB(config *config.SQLDBConfig) (*gorm.DB, error)

InitDB init a block syncer db instance

func LoadDBConfigFromEnv

func LoadDBConfigFromEnv(config *config.SQLDBConfig)

LoadDBConfigFromEnv load block syncer db user and password from env vars

Types

type BSDB

type BSDB interface {
	Metadata
}

BSDB contains all the methods required by block syncer database

type BsDBImpl

type BsDBImpl struct {
	// contains filtered or unexported fields
}

BsDBImpl block syncer database, implements BSDB interface

func NewBsDB

func NewBsDB(config *config.SQLDBConfig) (*BsDBImpl, error)

NewBsDB return a block syncer db instance

func (*BsDBImpl) GetBucketByID

func (b *BsDBImpl) GetBucketByID(bucketID int64, isFullList bool) (*Bucket, error)

GetBucketByID get buckets info by a bucket id

func (*BsDBImpl) GetBucketByName

func (b *BsDBImpl) GetBucketByName(bucketName string, isFullList bool) (*Bucket, error)

GetBucketByName get buckets info by a bucket name

func (*BsDBImpl) GetLatestBlockNumber

func (b *BsDBImpl) GetLatestBlockNumber() (int64, error)

GetLatestBlockNumber get current latest block number

func (*BsDBImpl) GetPaymentByBucketID

func (b *BsDBImpl) GetPaymentByBucketID(bucketID int64, isFullList bool) (*StreamRecord, error)

GetPaymentByBucketID get payment info by a bucket id

func (*BsDBImpl) GetPaymentByBucketName

func (b *BsDBImpl) GetPaymentByBucketName(bucketName string, isFullList bool) (*StreamRecord, error)

GetPaymentByBucketName get payment info by a bucket name

func (*BsDBImpl) GetPaymentByPaymentAddress

func (b *BsDBImpl) GetPaymentByPaymentAddress(paymentAddress common.Address) (*StreamRecord, error)

GetPaymentByPaymentAddress get payment info by a payment address

func (*BsDBImpl) GetUserBuckets

func (b *BsDBImpl) GetUserBuckets(accountID common.Address) ([]*Bucket, error)

GetUserBuckets get buckets info by a user address

func (*BsDBImpl) GetUserBucketsCount

func (b *BsDBImpl) GetUserBucketsCount(accountID common.Address) (int64, error)

GetUserBucketsCount get buckets count by a user address

func (*BsDBImpl) ListDeletedObjectsByBlockNumberRange

func (b *BsDBImpl) ListDeletedObjectsByBlockNumberRange(startBlockNumber int64, endBlockNumber int64, isFullList bool) ([]*Object, error)

ListDeletedObjectsByBlockNumberRange list deleted objects info by a block number range

func (*BsDBImpl) ListObjectsByBucketName

func (b *BsDBImpl) ListObjectsByBucketName(bucketName string) ([]*Object, error)

ListObjectsByBucketName list objects info by a bucket name

type Bucket

type Bucket struct {
	// ID defines db auto_increment id of bucket
	ID uint64 `gorm:"id"`
	// Owner is the account address of bucket creator, it is also the bucket owner.
	Owner common.Address `gorm:"column:owner_address"`
	// BucketName is a globally unique name of bucket
	BucketName string `gorm:"bucket_name"`
	// Visibility defines the highest permissions for bucket. When a bucket is public, everyone can get storage obj
	Visibility string `gorm:"visibility"`
	// ID is the unique identification for bucket.
	BucketID common.Hash `gorm:"bucket_id"`
	// SourceType defines which chain the user should send the bucket management transactions to
	SourceType string `gorm:"source_type"`
	// CreateAt defines the block number when the bucket created.
	CreateAt int64 `gorm:"create_at"`
	// CreateTime defines the timestamp when the bucket created
	CreateTime int64 `gorm:"create_time"`
	// PaymentAddress is the address of the payment account
	PaymentAddress common.Address `gorm:"payment_address"`
	// PrimarySpAddress is the address of the primary sp. Objects belong to this bucket will never
	// leave this SP, unless you explicitly shift them to another SP.
	PrimarySpAddress common.Address `gorm:"primary_sp_address"`
	// ReadQuota defines the traffic quota for read
	ChargedReadQuota uint64 `gorm:"charged_read_quota"`
	// PaymentPriceTime defines price time of payment
	PaymentPriceTime int64 `gorm:"payment_price_time"`
	// Removed defines the bucket is deleted or not
	Removed bool `gorm:"removed"`
}

Bucket is the structure for user bucket

func (*Bucket) TableName

func (a *Bucket) TableName() string

TableName is used to set Bucket table name in database

type Epoch

type Epoch struct {
	// OneRowID defines if the table only has one row
	OneRowID bool `gorm:"one_row_id;not null;default:true;primaryKey"`
	// BlockHeight defines the latest block number
	BlockHeight int64 `gorm:"block_height;type:bigint(64)"`
	// BlockHash defines the latest block hash
	BlockHash common.Hash `gorm:"block_hash;type:BINARY(32)"`
	// UpdateTime defines the update time of the latest block
	UpdateTime int64 `gorm:"update_time;type:bigint(64)"`
}

Epoch stores current information of the latest block

func (*Epoch) TableName

func (*Epoch) TableName() string

TableName is used to set Epoch table name in database

type Metadata

type Metadata interface {
	// GetUserBuckets get buckets info by a user address
	GetUserBuckets(accountID common.Address) ([]*Bucket, error)
	// GetUserBucketsCount get buckets count by a user address
	GetUserBucketsCount(accountID common.Address) (int64, error)
	// GetBucketByName get buckets info by a bucket name
	GetBucketByName(bucketName string, isFullList bool) (*Bucket, error)
	// GetBucketByID get buckets info by by a bucket id
	GetBucketByID(bucketID int64, isFullList bool) (*Bucket, error)
	// GetLatestBlockNumber get current latest block number
	GetLatestBlockNumber() (int64, error)
	// GetPaymentByBucketName get bucket payment info by a bucket name
	GetPaymentByBucketName(bucketName string, isFullList bool) (*StreamRecord, error)
	// GetPaymentByBucketID get bucket payment info by a bucket id
	GetPaymentByBucketID(bucketID int64, isFullList bool) (*StreamRecord, error)
	// GetPaymentByPaymentAddress get bucket payment info by a payment address
	GetPaymentByPaymentAddress(address common.Address) (*StreamRecord, error)
	// ListObjectsByBucketName list objects info by a bucket name
	ListObjectsByBucketName(bucketName string) ([]*Object, error)
	// ListDeletedObjectsByBlockNumberRange list deleted objects info by a block number range
	ListDeletedObjectsByBlockNumberRange(startBlockNumber int64, endBlockNumber int64, isFullList bool) ([]*Object, error)
}

Metadata contains all the methods required by block syncer db database

type Object

type Object struct {
	// ID defines db auto_increment id of object
	ID uint64 `gorm:"id"`
	// Creator defines the account address of object creator
	Creator common.Address `gorm:"creator_address"`
	// Owner defines the account address of object owner
	Owner common.Address `gorm:"column:owner_address"`
	// BucketName is the name of the bucket
	BucketName string `gorm:"bucket_name"`
	// ObjectName is the name of object
	ObjectName string `gorm:"object_name"`
	// ObjectID is the unique identifier of object
	ObjectID common.Hash `gorm:"object_id"`
	// BucketID is the unique identifier of bucket
	BucketID common.Hash `gorm:"bucket_id"`
	// PayloadSize is the total size of the object payload
	PayloadSize uint64 `gorm:"payload_size"`
	// Visibility defines the highest permissions for bucket. When a bucket is public, everyone can get storage obj
	Visibility string `gorm:"visibility"`
	// ContentType defines the format of the object which should be a standard MIME type
	ContentType string `gorm:"content_type"`
	// CreateAt defines the block number when the object created
	CreateAt int64 `gorm:"create_at"`
	// CreateTime defines the timestamp when the object created
	CreateTime int64 `gorm:"create_time"`
	// ObjectStatus defines the upload status of the object.
	ObjectStatus string `gorm:"column:status"`
	// RedundancyType defines the type of the redundancy which can be multi-replication or EC
	RedundancyType string `gorm:"redundancy_type"`
	// SourceType defines the source of the object.
	SourceType string `gorm:"source_type"`
	// CheckSums defines the root hash of the pieces which stored in a SP
	Checksums pq.ByteaArray `gorm:"check_sums;type:text"`
	// SecondarySpAddresses defines the addresses of secondary_sps
	SecondarySpAddresses pq.StringArray `gorm:"secondary_sp_addresses;type:text"`
	// LockedBalance defines locked balance of object
	LockedBalance common.Hash `gorm:"locked_balance"`
	// Removed defines the object is deleted or not
	Removed bool `gorm:"removed"`
	// UpdateTime defines the time when the object updated
	UpdateTime int64 `gorm:"update_time"`
	// UpdateAt defines the block number when the object updated
	UpdateAt int64 `gorm:"update_at"`
}

Object is the structure for user object

func (*Object) TableName

func (a *Object) TableName() string

TableName is used to set Object table name in database

type StreamRecord

type StreamRecord struct {
	// ID defines db auto_increment id of stream record
	ID uint64 `gorm:"id"`
	// Account defines the account address
	Account common.Address `gorm:"account"`
	// UpdateTime defines the latest update timestamp of the stream record
	UpdateTime int64 `gorm:"update_time"`
	// NetflowRate defines the per-second rate that an account's balance is changing.
	// It is the sum of the account's inbound and outbound flow rates.
	NetflowRate *common.Big `gorm:"netflow_rate"`
	// StaticBalance defines the balance of the stream account at the latest CRUD timestamp.
	StaticBalance *common.Big `gorm:"static_balance"`
	// BufferBalance defines reserved balance of the stream account
	// If the netflow rate is negative, the reserved balance is `netflow_rate * reserve_time`
	BufferBalance *common.Big `gorm:"buffer_balance"`
	// LockBalance defines the locked balance of the stream account after it puts a new object and before the object is sealed
	LockBalance *common.Big `gorm:"lock_balance"`
	// Status defines the status of the stream account
	Status string `gorm:"status"`
	// SettleTimestamp defines the unix timestamp when the stream account will be settled
	SettleTimestamp int64 `gorm:"column:settle_time"`
	// OutFlows defines the accumulated outflow rates of the stream account
	OutFlows []byte `gorm:"out_flows;type:longblob"`
}

func (*StreamRecord) TableName

func (*StreamRecord) TableName() string

TableName is used to set StreamRecord table name in database

Jump to

Keyboard shortcuts

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