core

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var (
	ErrNotFound       = errors.New("not found")
	ErrInvalidArg     = errors.New("invalid arguments")
	ErrNotImplemented = errors.New("not implemented")
	ErrAlreadyExists  = errors.New("already exists")
)

Functions

func SkipAddress added in v0.3.2

func SkipAddress(a addr.Address) bool

Types

type AccountRepository

type AccountRepository interface {
	AddAddressLabel(context.Context, *AddressLabel) error
	GetAddressLabel(context.Context, addr.Address) (*AddressLabel, error)

	AddAccountStates(ctx context.Context, tx bun.Tx, states []*AccountState) error
	UpdateAccountStates(ctx context.Context, states []*AccountState) error

	// MatchStatesByInterfaceDesc returns (address, last_tx_lt) pairs for suitable account states.
	MatchStatesByInterfaceDesc(ctx context.Context,
		contractName abi.ContractName,
		addresses []*addr.Address,
		codeHash []byte,
		getMethodHashes []int32,
		afterAddress *addr.Address,
		afterTxLt uint64,
		limit int) ([]*AccountStateID, error)

	// GetAllAccountInterfaces returns transaction LT, on which contract interface was updated.
	// It also considers, that contract can be both upgraded and downgraded.
	GetAllAccountInterfaces(context.Context, addr.Address) (map[uint64][]abi.ContractName, error)

	// GetAllAccountStates is pretty much similar to GetAllAccountInterfaces, but it returns updates of code or data.
	GetAllAccountStates(ctx context.Context, a addr.Address, beforeTxLT uint64, limit int) ([]*AccountState, error)
}

type AccountState

type AccountState struct {
	ch.CHModel    `ch:"account_states,partition:toYYYYMM(updated_at)" json:"-"`
	bun.BaseModel `bun:"table:account_states" json:"-"`

	Address addr.Address  `ch:"type:String,pk" bun:"type:bytea,pk,notnull" json:"address"`
	Label   *AddressLabel `ch:"-" bun:"rel:has-one,join:address=address" json:"label,omitempty"`

	Workchain  int32  `bun:"type:integer,notnull" json:"workchain"`
	Shard      int64  `bun:"type:bigint,notnull" json:"shard"`
	BlockSeqNo uint32 `bun:"type:integer,notnull" json:"block_seq_no"`

	IsActive bool          `json:"is_active"`
	Status   AccountStatus `ch:",lc" bun:"type:account_status" json:"status"` // TODO: ch enum

	Balance *bunbig.Int `ch:"type:UInt256" bun:"type:numeric" json:"balance"`

	LastTxLT   uint64 `ch:",pk" bun:"type:bigint,pk,notnull" json:"last_tx_lt"`
	LastTxHash []byte `bun:"type:bytea,unique,notnull" json:"last_tx_hash"`

	StateHash []byte `bun:"type:bytea" json:"state_hash,omitempty"` // only if account is frozen
	Code      []byte `ch:"-" bun:"type:bytea" json:"code,omitempty"`
	CodeHash  []byte `bun:"type:bytea" json:"code_hash,omitempty"`
	Data      []byte `ch:"-" bun:"type:bytea" json:"data,omitempty"`
	DataHash  []byte `bun:"type:bytea" json:"data_hash,omitempty"`
	Libraries []byte `bun:"type:bytea" json:"libraries,omitempty"`

	GetMethodHashes []int32 `ch:"type:Array(UInt32)" bun:"type:integer[]" json:"get_method_hashes,omitempty"`

	Types []abi.ContractName `ch:"type:Array(String)" bun:"type:text[],array" json:"types,omitempty"`

	// common fields for FT and NFT
	OwnerAddress  *addr.Address `ch:"type:String" bun:"type:bytea" json:"owner_address,omitempty"` // universal column for many contracts
	MinterAddress *addr.Address `ch:"type:String" bun:"type:bytea" json:"minter_address,omitempty"`

	Fake bool `ch:"type:Bool" bun:"type:boolean" json:"fake"`

	ExecutedGetMethods map[abi.ContractName][]abi.GetMethodExecution `ch:"type:String" bun:"type:jsonb" json:"executed_get_methods,omitempty"`

	// TODO: remove this
	NFTContentData
	FTWalletData

	UpdatedAt time.Time `bun:"type:timestamp without time zone,notnull" json:"updated_at"`
}

func (*AccountState) BlockID added in v0.4.1

func (a *AccountState) BlockID() BlockID

type AccountStateCode added in v0.4.1

type AccountStateCode struct {
	ch.CHModel `ch:"account_states_code" json:"-"`

	CodeHash []byte `ch:"type:String"`
	Code     []byte `ch:"type:String"`
}

type AccountStateData added in v0.4.1

type AccountStateData struct {
	ch.CHModel `ch:"account_states_data" json:"-"`

	DataHash []byte `ch:"type:String"`
	Data     []byte `ch:"type:String"`
}

type AccountStateID added in v0.4.1

type AccountStateID struct {
	Address  addr.Address `ch:"type:String"`
	LastTxLT uint64
}

type AccountStatus

type AccountStatus string

type AddressLabel added in v0.3.1

type AddressLabel struct {
	ch.CHModel    `ch:"address_labels" json:"-"`
	bun.BaseModel `bun:"table:address_labels" json:"-"`

	Address    addr.Address    `ch:"type:String,pk" bun:"type:bytea,pk,notnull" json:"address"`
	Name       string          `bun:"type:text" json:"name"`
	Categories []LabelCategory `ch:",lc" bun:"type:label_category[]" json:"categories,omitempty"`
}

type Block

type Block struct {
	ch.CHModel    `ch:"block_info" json:"-"`
	bun.BaseModel `bun:"table:block_info" json:"-"`

	Workchain int32  `ch:",pk" bun:"type:integer,pk,notnull" json:"workchain"`
	Shard     int64  `ch:",pk" bun:"type:bigint,pk,notnull" json:"shard"`
	SeqNo     uint32 `ch:",pk" bun:"type:integer,pk,notnull" json:"seq_no"`

	FileHash []byte `bun:"type:bytea,unique,notnull" json:"file_hash"`
	RootHash []byte `bun:"type:bytea,unique,notnull" json:"root_hash"`

	MasterID *BlockID `ch:"-" bun:"embed:master_" json:"master,omitempty"`
	Shards   []*Block `` /* 131-byte string literal not displayed */

	TransactionsCount int             `ch:"-" bun:"transactions_count,scanonly" json:"transactions_count"`
	Transactions      []*Transaction  `ch:"-" bun:"rel:has-many,join:workchain=workchain,join:shard=shard,join:seq_no=block_seq_no" json:"transactions,omitempty"`
	Accounts          []*AccountState `ch:"-" bun:"rel:has-many,join:workchain=workchain,join:shard=shard,join:seq_no=block_seq_no" json:"accounts,omitempty"`

	ScannedAt time.Time `bun:"type:timestamp without time zone,notnull" json:"scanned_at"`
}

func (*Block) ID added in v0.3.1

func (b *Block) ID() BlockID

type BlockID

type BlockID struct {
	Workchain int32  `json:"workchain"`
	Shard     int64  `json:"shard"`
	SeqNo     uint32 `json:"seq_no"`
}

func GetBlockID added in v0.3.1

func GetBlockID(b *ton.BlockIDExt) BlockID

type BlockRepository

type BlockRepository interface {
	AddBlocks(ctx context.Context, tx bun.Tx, info []*Block) error
	GetLastMasterBlock(ctx context.Context) (*Block, error)
	CountMasterBlocks(ctx context.Context) (int, error)
}

type ContractDefinition added in v0.4.1

type ContractDefinition struct {
	bun.BaseModel `bun:"table:contract_definitions" json:"-"`

	Name   abi.TLBType       `bun:",pk,notnull" json:"name"`
	Schema abi.TLBFieldsDesc `bun:"type:jsonb,notnull" json:"schema"`
}

type ContractInterface

type ContractInterface struct {
	bun.BaseModel `bun:"table:contract_interfaces" json:"-"`

	Name            abi.ContractName     `bun:",pk" json:"name"`
	Addresses       []*addr.Address      `bun:"type:bytea[],unique" json:"addresses,omitempty"`
	Code            []byte               `bun:"type:bytea,unique" json:"code,omitempty"`
	GetMethodsDesc  []abi.GetMethodDesc  `bun:"type:text" json:"get_methods_descriptors,omitempty"`
	GetMethodHashes []int32              `bun:"type:integer[]" json:"get_method_hashes,omitempty"`
	Operations      []*ContractOperation `ch:"-" bun:"rel:has-many,join:name=contract_name" json:"operations,omitempty"`
}

type ContractOperation

type ContractOperation struct {
	bun.BaseModel `bun:"table:contract_operations" json:"-"`

	OperationName string            `json:"operation_name"`
	ContractName  abi.ContractName  `bun:",pk" json:"contract_name"`
	MessageType   MessageType       `bun:"type:message_type,notnull" json:"message_type"` // only internal is supported now
	Outgoing      bool              `bun:",pk" json:"outgoing"`                           // if operation is going from contract
	OperationID   uint32            `bun:",pk" json:"operation_id"`
	Schema        abi.OperationDesc `bun:"type:jsonb" json:"schema"`
}

type ContractRepository

type ContractRepository interface {
	AddDefinition(context.Context, abi.TLBType, abi.TLBFieldsDesc) error
	UpdateDefinition(ctx context.Context, dn abi.TLBType, d abi.TLBFieldsDesc) error
	DeleteDefinition(ctx context.Context, dn abi.TLBType) error
	GetDefinitions(context.Context) (map[abi.TLBType]abi.TLBFieldsDesc, error)

	AddInterface(context.Context, *ContractInterface) error
	UpdateInterface(ctx context.Context, i *ContractInterface) error
	DeleteInterface(ctx context.Context, name abi.ContractName) error
	GetInterface(ctx context.Context, name abi.ContractName) (*ContractInterface, error)
	GetInterfaces(context.Context) ([]*ContractInterface, error)
	GetMethodDescription(ctx context.Context, name abi.ContractName, method string) (abi.GetMethodDesc, error)

	AddOperation(context.Context, *ContractOperation) error
	UpdateOperation(ctx context.Context, op *ContractOperation) error
	DeleteOperation(ctx context.Context, opName string) error
	GetOperations(context.Context) ([]*ContractOperation, error)
	GetOperationsByID(ctx context.Context, t MessageType, interfaces []abi.ContractName, outgoing bool, id uint32) ([]*ContractOperation, error)
}

type FTWalletData

type FTWalletData struct {
	JettonBalance *bunbig.Int `ch:"type:UInt256" bun:"type:numeric" json:"jetton_balance,omitempty" swaggertype:"string"`
}

type LabelCategory added in v0.3.1

type LabelCategory string
var (
	CentralizedExchange LabelCategory = "centralized_exchange"
	Scam                LabelCategory = "scam"
)

type LatestAccountState

type LatestAccountState struct {
	bun.BaseModel `bun:"table:latest_account_states" json:"-"`

	Address      addr.Address  `bun:"type:bytea,pk,notnull" json:"address"`
	LastTxLT     uint64        `bun:"type:bigint,notnull" json:"last_tx_lt"`
	AccountState *AccountState `bun:"rel:has-one,join:address=address,join:last_tx_lt=last_tx_lt" json:"account"`
}

type Message

type Message struct {
	ch.CHModel    `ch:"messages,partition:toYYYYMM(created_at)" json:"-"`
	bun.BaseModel `bun:"table:messages" json:"-"`

	Type MessageType `ch:",lc" bun:"type:message_type,notnull" json:"type"` // TODO: ch enum

	Hash []byte `ch:",pk" bun:"type:bytea,pk,notnull"  json:"hash"`

	SrcAddress    addr.Address  `ch:"type:String" bun:"type:bytea,nullzero" json:"src_address,omitempty"`
	SrcTxLT       uint64        `bun:",nullzero" json:"src_tx_lt,omitempty"`
	SrcTxHash     []byte        `ch:"-" bun:"-" json:"src_tx_hash,omitempty"`
	SrcWorkchain  int32         `bun:"type:integer,notnull" json:"src_workchain"`
	SrcShard      int64         `bun:"type:bigint,notnull" json:"src_shard"`
	SrcBlockSeqNo uint32        `bun:"type:integer,notnull" json:"src_block_seq_no"`
	SrcState      *AccountState `` /* 161-byte string literal not displayed */

	DstAddress    addr.Address  `ch:"type:String" bun:"type:bytea,nullzero" json:"dst_address,omitempty"`
	DstTxLT       uint64        `bun:",nullzero" json:"dst_tx_lt,omitempty"`
	DstTxHash     []byte        `ch:"-" bun:"-" json:"dst_tx_hash,omitempty"`
	DstWorkchain  int32         `bun:"type:integer,notnull" json:"dst_workchain"`
	DstShard      int64         `bun:"type:bigint,notnull" json:"dst_shard"`
	DstBlockSeqNo uint32        `bun:"type:integer,notnull" json:"dst_block_seq_no"`
	DstState      *AccountState `` /* 161-byte string literal not displayed */

	Bounce  bool `bun:",notnull" json:"bounce"`
	Bounced bool `bun:",notnull" json:"bounced"`

	Amount *bunbig.Int `ch:"type:UInt256" bun:"type:numeric" json:"amount,omitempty"`

	IHRDisabled bool        `bun:",notnull" json:"ihr_disabled"`
	IHRFee      *bunbig.Int `ch:"type:UInt256" bun:"type:numeric" json:"ihr_fee"`
	FwdFee      *bunbig.Int `ch:"type:UInt256" bun:"type:numeric" json:"fwd_fee"`

	Body            []byte `bun:"type:bytea" json:"body"`
	BodyHash        []byte `bun:"type:bytea" json:"body_hash"`
	OperationID     uint32 `json:"operation_id"`
	TransferComment string `json:"transfer_comment,omitempty"`

	StateInitCode []byte `bun:"type:bytea" json:"state_init_code,omitempty"`
	StateInitData []byte `bun:"type:bytea" json:"state_init_data,omitempty"`

	SrcContract abi.ContractName `ch:",lc" bun:",nullzero" json:"src_contract,omitempty"`
	DstContract abi.ContractName `ch:",lc" bun:",nullzero" json:"dst_contract,omitempty"`

	OperationName string          `ch:",lc" bun:",nullzero" json:"operation_name,omitempty"`
	DataJSON      json.RawMessage `ch:"type:String" bun:"type:jsonb" json:"data,omitempty"`
	Error         string          `json:"error,omitempty"`

	CreatedAt time.Time `bun:"type:timestamp without time zone,notnull" json:"created_at"`
	CreatedLT uint64    `bun:",notnull" json:"created_lt"`
}

type MessageRepository

type MessageRepository interface {
	AddMessages(ctx context.Context, tx bun.Tx, messages []*Message) error
	UpdateMessages(ctx context.Context, messages []*Message) error

	GetMessage(ctx context.Context, hash []byte) (*Message, error)
	GetMessages(ctx context.Context, hash [][]byte) ([]*Message, error)

	// MatchMessagesByOperationDesc returns hashes of suitable messages for the given contract operation.
	MatchMessagesByOperationDesc(ctx context.Context,
		contractName abi.ContractName,
		msgType MessageType,
		outgoing bool,
		operationId uint32,
		afterAddress *addr.Address,
		afterTxLT uint64,
		limit int) ([][]byte, error)
}

type MessageType

type MessageType string

type NFTContentData

type NFTContentData struct {
	ContentURI         string `ch:"type:String" bun:",nullzero" json:"content_uri,omitempty"`
	ContentName        string `ch:"type:String" bun:",nullzero" json:"content_name,omitempty"`
	ContentDescription string `ch:"type:String" bun:",nullzero" json:"content_description,omitempty"`
	ContentImage       string `ch:"type:String" bun:",nullzero" json:"content_image,omitempty"`
	ContentImageData   []byte `ch:"type:String" bun:",nullzero" json:"content_image_data,omitempty"`
}

type RescanRepository added in v0.4.1

type RescanRepository interface {
	AddRescanTask(ctx context.Context, task *RescanTask) error
	GetUnfinishedRescanTask(context.Context) (bun.Tx, *RescanTask, error)
	SetRescanTask(context.Context, bun.Tx, *RescanTask) error
}

type RescanTask added in v0.4.1

type RescanTask struct {
	bun.BaseModel `bun:"table:rescan_tasks" json:"-"`

	ID       int            `bun:",pk,autoincrement"`
	Finished bool           `bun:"finished,notnull"`
	Type     RescanTaskType `bun:"type:rescan_task_type,notnull"`

	// contract being rescanned
	ContractName abi.ContractName   `bun:",notnull" json:"contract_name"`
	Contract     *ContractInterface `bun:"rel:has-one,join:contract_name=name" json:"contract_interface"`

	// for get-method update
	ChangedGetMethods []string `bun:"type:text[],array" json:"changed_get_methods,omitempty"`

	// for operations
	MessageType MessageType        `bun:"type:message_type,nullzero" json:"message_type,omitempty"`
	Outgoing    bool               `bun:",nullzero" json:"outgoing,omitempty"` // if operation is going from contract
	OperationID uint32             `bun:",nullzero" json:"operation_id,omitempty"`
	Operation   *ContractOperation `` /* 130-byte string literal not displayed */

	// checkpoint
	LastAddress *addr.Address `bun:"type:bytea" json:"last_address"`
	LastTxLt    uint64        `bun:"type:bigint" json:"last_tx_lt"`

	UpdatedAt time.Time `bun:"type:timestamp without time zone,notnull" json:"updated_at"`
	CreatedAt time.Time `bun:"type:timestamp without time zone,notnull" json:"created_at"`
}

type RescanTaskType added in v0.4.1

type RescanTaskType string
const (
	// AddInterface task filters all account states by suitable addresses, code, or get method hashes.
	// From these account states, extract (address, last_tx_lt) pairs,
	// execute get methods on these pairs, and update the account states with the newly parsed data.
	AddInterface RescanTaskType = "add_interface"

	// UpdInterface is invoked when changes occur to the interface code, addresses, or get-methods.
	// This requires removing parsed data from account states that are no longer relevant
	// and reparsing data for account states that have become relevant due to the changes.
	UpdInterface RescanTaskType = "upd_interface"

	// DelInterface does the same filtering as UpdInterface,
	// but it clears any previously parsed data.
	DelInterface RescanTaskType = "del_interface"

	// AddGetMethod task executes this method across all account states that were previously scanned
	// and clears all parsed data in account states lacking the new get method.
	AddGetMethod RescanTaskType = "add_get_method"

	// DelGetMethod task eliminates the execution of this get-method in all previously parsed account states.
	// Then, it includes all account states that match the contract interface description, minus the deleted get method.
	DelGetMethod RescanTaskType = "del_get_method"

	// UpdGetMethod task simply iterates through all parsed account states associated with the specified contract name
	// and re-execute the changed get method.
	UpdGetMethod RescanTaskType = "upd_get_method"

	// UpdOperation task parses contract messages.
	// It iterates through all messages with specified operation id,
	// directed to (or originating from, in the case of outgoing operations) the given contract
	// and adds the parsed data.
	UpdOperation RescanTaskType = "upd_operation"

	// DelOperation task is the same algorithm, as UpdOperation, but it removes the parsed data.
	DelOperation RescanTaskType = "del_operation"
)

type Transaction

type Transaction struct {
	ch.CHModel    `ch:"transactions,partition:toYYYYMM(created_at)" json:"-"`
	bun.BaseModel `bun:"table:transactions" json:"-"`

	Address   addr.Address  `ch:"type:String,pk" bun:"type:bytea" json:"address"`
	Hash      []byte        `bun:"type:bytea,pk,notnull" json:"hash"`
	CreatedLT uint64        `ch:",pk" bun:",notnull" json:"created_lt"`
	Account   *AccountState `ch:"-" bun:"rel:has-one,join:address=address,join:created_lt=last_tx_lt" json:"account"`

	Workchain  int32  `bun:"type:integer,notnull" json:"workchain"`
	Shard      int64  `bun:"type:bigint,notnull" json:"shard"`
	BlockSeqNo uint32 `bun:"type:integer,notnull" json:"block_seq_no"`

	PrevTxHash []byte `bun:"type:bytea" json:"prev_tx_hash,omitempty"`
	PrevTxLT   uint64 `json:"prev_tx_lt,omitempty"`

	InMsgHash []byte      `json:"in_msg_hash"`
	InMsg     *Message    `ch:"-" bun:"rel:belongs-to,join:in_msg_hash=hash" json:"in_msg"`
	InAmount  *bunbig.Int `ch:"type:UInt256" bun:"type:numeric,notnull" json:"in_amount,omitempty"`

	OutMsg      []*Message  `ch:"-" bun:"rel:has-many,join:address=src_address,join:created_lt=src_tx_lt" json:"out_msg,omitempty"`
	OutMsgCount uint16      `bun:",notnull" json:"out_msg_count"`
	OutAmount   *bunbig.Int `ch:"type:UInt256" bun:"type:numeric,notnull" json:"out_amount,omitempty"`

	TotalFees *bunbig.Int `ch:"type:UInt256" bun:"type:numeric" json:"total_fees"`

	Description           []byte `bun:"type:bytea,notnull" json:"description_boc,omitempty"`
	DescriptionLoaded     any    `ch:"-" bun:"-" json:"description,omitempty"`
	ComputePhaseExitCode  int32  `ch:"type:Int32" bun:",notnull" json:"compute_phase_exit_code"`
	ActionPhaseResultCode int32  `ch:"type:Int32" bun:",notnull" json:"action_phase_result_code"`

	OrigStatus AccountStatus `ch:",lc" bun:"type:account_status,notnull" json:"orig_status"`
	EndStatus  AccountStatus `ch:",lc" bun:"type:account_status,notnull" json:"end_status"`

	CreatedAt time.Time `bun:"type:timestamp without time zone,notnull" json:"created_at"`
}

func (*Transaction) LoadDescription added in v0.2.1

func (tx *Transaction) LoadDescription() error

type TransactionRepository

type TransactionRepository interface {
	AddTransactions(ctx context.Context, tx bun.Tx, transactions []*Transaction) error
}

Directories

Path Synopsis
msg
tx

Jump to

Keyboard shortcuts

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