core

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 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")
)

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
}

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 `bun:"type:bytea" json:"code,omitempty"`
	CodeHash  []byte `bun:"type:bytea" json:"code_hash,omitempty"`
	Data      []byte `bun:"type:bytea" json:"data,omitempty"`
	DataHash  []byte `bun:"type:bytea" json:"data_hash,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,omitempty"`

	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"`
}

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 */

	Transactions []*Transaction `ch:"-" bun:"rel:has-many,join:workchain=workchain,join:shard=shard,join:seq_no=block_seq_no" json:"transactions,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)
}

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 {
	AddInterface(context.Context, *ContractInterface) error

	DelInterface(ctx context.Context, name string) error

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

	AddOperation(context.Context, *ContractOperation) error

	GetOperations(context.Context) ([]*ContractOperation, error)
	GetOperationByID(context.Context, MessageType, []abi.ContractName, bool, 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
	GetMessage(ctx context.Context, hash []byte) (*Message, 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 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