db

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(params map[string]any) types.BlockchainContext

NewContext creates a new SQLite-backed blockchain context using GORM

Types

type Context

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

Context implements the BlockchainContext interface using SQLite with GORM

func (*Context) Balance

func (c *Context) Balance(addr core.Address) uint64

Balance implements types.BlockchainContext

func (*Context) BlockHeight

func (c *Context) BlockHeight() uint64

BlockHeight implements types.BlockchainContext

func (*Context) BlockTime

func (c *Context) BlockTime() int64

BlockTime implements types.BlockchainContext

func (*Context) Call

func (c *Context) Call(caller core.Address, contract core.Address, function string, args ...any) ([]byte, error)

Call implements types.BlockchainContext

func (*Context) ContractAddress

func (c *Context) ContractAddress() core.Address

ContractAddress implements types.BlockchainContext

func (*Context) CreateObject

func (c *Context) CreateObject(contract core.Address) (types.VMObject, error)

CreateObject implements types.BlockchainContext

func (*Context) CreateObjectWithID

func (c *Context) CreateObjectWithID(contract core.Address, id core.ObjectID) (types.VMObject, error)

CreateObjectWithID implements types.BlockchainContext

func (*Context) DeleteObject

func (c *Context) DeleteObject(contract core.Address, id core.ObjectID) error

DeleteObject implements types.BlockchainContext

func (*Context) GetGas

func (c *Context) GetGas() int64

GetGas implements types.BlockchainContext

func (*Context) GetObject

func (c *Context) GetObject(contract core.Address, id core.ObjectID) (types.VMObject, error)

GetObject implements types.BlockchainContext

func (*Context) GetObjectWithOwner

func (c *Context) GetObjectWithOwner(contract core.Address, owner core.Address) (types.VMObject, error)

GetObjectWithOwner implements types.BlockchainContext

func (*Context) Log

func (c *Context) Log(contract core.Address, eventName string, keyValues ...any)

Log implements types.BlockchainContext

func (*Context) Sender

func (c *Context) Sender() core.Address

Sender implements types.BlockchainContext

func (*Context) SetBlockInfo added in v0.1.2

func (c *Context) SetBlockInfo(height uint64, time int64, hash core.Hash) error

func (*Context) SetGasLimit

func (c *Context) SetGasLimit(limit int64)

func (*Context) SetTransactionInfo added in v0.1.2

func (c *Context) SetTransactionInfo(hash core.Hash, from types.Address, to types.Address, value uint64) error

func (*Context) TransactionHash

func (c *Context) TransactionHash() core.Hash

TransactionHash implements types.BlockchainContext

func (*Context) Transfer

func (c *Context) Transfer(from, to core.Address, amount uint64) error

Transfer implements types.BlockchainContext

func (*Context) WithBlock

func (c *Context) WithBlock(height uint64) error

WithBlock sets the current block context

func (*Context) WithTransaction

func (c *Context) WithTransaction(hash string) error

WithTransaction sets the current transaction context

type DBBalance

type DBBalance struct {
	Address string `gorm:"column:address;primaryKey;size:42"`
	Amount  uint64 `gorm:"column:balance;not null;default:0"`
}

DBBalance represents the balance in database

func (DBBalance) TableName

func (DBBalance) TableName() string

TableName specifies the table name for DBBalance

type DBBlock

type DBBlock struct {
	gorm.Model
	Height uint64 `gorm:"column:height;not null;unique;index"`
	Time   int64  `gorm:"column:block_time;not null"`
	Hash   string `gorm:"column:block_hash;not null;unique;index;size:66"`
}

func (DBBlock) TableName

func (DBBlock) TableName() string

type DBEvent

type DBEvent struct {
	gorm.Model
	BlockHeight uint64 `gorm:"column:block_height;not null;index"`
	TxHash      string `gorm:"column:tx_hash;not null;index;size:66"`
	Contract    string `gorm:"column:contract_address;not null;index;size:42"`
	EventName   string `gorm:"column:event_name;not null;index;size:255"`
	KeyValues   []byte `gorm:"column:key_values;type:blob;not null"` // JSON encoded key-value pairs
}

DBEvent represents an event in the database

func (DBEvent) TableName

func (DBEvent) TableName() string

TableName specifies the table name for DBEvent

type DBObject

type DBObject struct {
	gorm.Model
	ObjectID string `gorm:"column:object_id;not null;unique;index;size:66"`
	Owner    string `gorm:"column:owner_address;not null;index;size:42"`
	Contract string `gorm:"column:contract_address;not null;index;size:42"`
}

DBObject represents the object in database

func (DBObject) TableName

func (DBObject) TableName() string

TableName specifies the table name for DBObject

type DBObjectField

type DBObjectField struct {
	gorm.Model
	ObjectID string `gorm:"column:object_id;not null;index;size:66"`
	Key      string `gorm:"column:field_key;not null;index;size:255"`
	Value    []byte `gorm:"column:field_value;type:blob;not null"`
}

DBObjectField represents a field of an object

func (DBObjectField) TableName

func (DBObjectField) TableName() string

TableName specifies the table name for DBObjectField

type DBTransaction

type DBTransaction struct {
	gorm.Model
	Hash        string `gorm:"column:tx_hash;not null;unique;index;size:66"`
	BlockHeight uint64 `gorm:"column:block_height;not null;index"`
	FromAddress string `gorm:"column:from_address;not null;index;size:42"`
	ToAddress   string `gorm:"column:to_address;not null;index;size:42"`
	Value       uint64 `gorm:"column:value;not null"`
	Data        []byte `gorm:"column:tx_data;type:blob;default:''"`
}

func (DBTransaction) TableName

func (DBTransaction) TableName() string

type Object

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

Object implements the VMObject interface

func (*Object) Contract

func (o *Object) Contract() core.Address

func (*Object) Get

func (o *Object) Get(contract core.Address, field string) ([]byte, error)

func (*Object) ID

func (o *Object) ID() core.ObjectID

func (*Object) Owner

func (o *Object) Owner() core.Address

func (*Object) Set

func (o *Object) Set(contract, sender core.Address, field string, value []byte) error

func (*Object) SetOwner

func (o *Object) SetOwner(contract, sender, addr core.Address) error

Jump to

Keyboard shortcuts

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