core

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var (
	ErrNotFound   = errors.New("not found")
	ErrInvalidArg = errors.New("invalid arguments")
)

Functions

This section is empty.

Types

type AccountData

type AccountData struct {
	ch.CHModel    `ch:"account_data,partition:types" json:"-"`
	bun.BaseModel `bun:"table:account_data" json:"-"`

	Address    addr.Address `ch:"type:String,pk" bun:"type:bytea,pk,notnull" json:"address"`
	LastTxLT   uint64       `ch:",pk" bun:",pk,notnull" json:"last_tx_lt"`
	LastTxHash []byte       `bun:"type:bytea,notnull,unique" json:"last_tx_hash"`
	Balance    *bunbig.Int  `ch:"type:UInt256" bun:"type:numeric" json:"balance"`

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

	WalletSeqNo uint64 `json:"wallet_seq_no,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"`

	NFTCollectionData
	NFTRoyaltyData
	NFTContentData
	NFTItemData
	NFTEditable

	FTMasterData
	FTWalletData

	Errors []string `json:"error,omitempty"`

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

type AccountRepository

type AccountRepository interface {
	AddAccountStates(ctx context.Context, tx bun.Tx, states []*AccountState) error
	AddAccountData(ctx context.Context, tx bun.Tx, data []*AccountData) error
}

type AccountState

type AccountState struct {
	ch.CHModel    `ch:"account_states,partition:status" json:"-"`
	bun.BaseModel `bun:"table:account_states" json:"-"`

	Address  addr.Address  `ch:"type:String,pk" bun:"type:bytea,pk,notnull" json:"address"`
	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"`

	StateData *AccountData `ch:"-" bun:"rel:belongs-to,join:address=address,join:last_tx_lt=last_tx_lt" json:"state_data,omitempty"`

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

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

type AccountStatus

type AccountStatus string

type Block

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

	Workchain int32  `ch:",pk" bun:",pk,notnull" json:"workchain"`
	Shard     int64  `ch:",pk" bun:",pk,notnull" json:"shard"`
	SeqNo     uint32 `ch:",pk" bun:",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=block_workchain,join:shard=block_shard,join:seq_no=block_seq_no" json:"transactions"`
}

type BlockID

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

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 {
	ch.CHModel    `ch:"contract_interfaces" json:"-"`
	bun.BaseModel `bun:"table:contract_interfaces" json:"-"`

	Name            abi.ContractName    `bun:",pk" json:"name"`
	Addresses       []*addr.Address     `bun:"type:bytea[],unique" json:"addresses"`
	Code            []byte              `bun:"type:bytea,unique" json:"code"`
	GetMethodsDesc  []abi.GetMethodDesc `bun:"type:text" json:"get_methods_descriptors"`
	GetMethodHashes []int32             `bun:"type:integer[]" json:"get_method_hashes"`
}

type ContractOperation

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

	Name         string            `json:"name"`
	ContractName abi.ContractName  `bun:",pk" json:"contract_name"`
	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
	AddOperation(context.Context, *ContractOperation) error

	DelInterface(ctx context.Context, name string) error

	GetInterfaces(context.Context) ([]*ContractInterface, error)
	GetOperations(context.Context) ([]*ContractOperation, error)
	GetOperationByID(context.Context, []abi.ContractName, bool, uint32) (*ContractOperation, error)
}

type FTMasterData

type FTMasterData struct {
	TotalSupply  *bunbig.Int   `ch:"type:UInt256" bun:"type:numeric" json:"total_supply,omitempty" swaggertype:"string"`
	Mintable     bool          `json:"mintable,omitempty"`
	AdminAddress *addr.Address `ch:"type:String" bun:"type:bytea" json:"admin_addr,omitempty"`
}

type FTWalletData

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

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"`
	DstAddress addr.Address `ch:"type:String" bun:"type:bytea,nullzero" json:"dst_address,omitempty"`

	// SourceTx initiates outgoing message.
	// For external incoming messages SourceTx == nil.
	SourceTxHash []byte       `bun:"type:bytea" json:"source_tx_hash,omitempty"`
	SourceTxLT   uint64       `json:"source_tx_lt,omitempty"`
	Source       *Transaction `ch:"-" bun:"-" json:"source,omitempty"` // TODO: join it

	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,omitempty"`
	TransferComment string          `json:"transfer_comment,omitempty"`
	Payload         *MessagePayload `ch:"-" bun:"rel:belongs-to,join:hash=hash,join:created_lt=created_lt" json:"payload,omitempty"`

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

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

	Known bool `ch:"-" bun:"-" json:"-"`
}

type MessagePayload

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

	Type MessageType `ch:",lc" bun:"type:message_type,notnull" json:"type"`
	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"`
	SrcContract abi.ContractName `ch:",lc" json:"src_contract,omitempty"`
	DstAddress  addr.Address     `ch:"type:String" bun:"type:bytea,nullzero" json:"dst_address,omitempty"`
	DstContract abi.ContractName `ch:",lc" json:"dst_contract,omitempty"`

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

	BodyHash      []byte          `bun:"type:bytea,notnull" json:"body_hash"`
	OperationID   uint32          `bun:",notnull" json:"operation_id"`
	OperationName string          `ch:",lc" bun:",notnull" json:"operation_name"`
	DataJSON      json.RawMessage `ch:"-" bun:"type:jsonb" json:"data"` // TODO: https://github.com/uptrace/go-clickhouse/issues/22

	// can be used to show all jetton or nft item transfers
	MinterAddress *addr.Address `ch:"type:String" bun:"type:bytea" json:"minter_address,omitempty"`

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

	Error string `json:"error,omitempty"`
}

type MessageRepository

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

type MessageType

type MessageType string

type NFTCollectionData

type NFTCollectionData struct {
	NextItemIndex *bunbig.Int `ch:"type:UInt256" bun:"type:numeric" json:"next_item_index,omitempty"`
}

type NFTContentData

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

type NFTEditable added in v0.2.1

type NFTEditable struct {
	EditorAddress *addr.Address `ch:"type:String" bun:"type:bytea" json:"editor_address,omitempty"`
}

type NFTItemData

type NFTItemData struct {
	Initialized bool        `ch:"type:Bool" json:"initialized,omitempty"`
	ItemIndex   *bunbig.Int `ch:"type:UInt256" json:"item_index,omitempty"`
}

type NFTRoyaltyData

type NFTRoyaltyData struct {
	RoyaltyAddress *addr.Address `ch:"type:String" bun:"type:bytea" json:"royalty_address,omitempty"`
	RoyaltyFactor  uint16        `ch:"type:UInt16" bun:"type:integer" json:"royalty_factor,omitempty"`
	RoyaltyBase    uint16        `ch:"type:UInt16" bun:"type:integer" json:"royalty_base,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,notnull" json:"address"`
	Hash    []byte        `ch:",pk" bun:"type:bytea,pk,notnull" json:"hash"`
	Account *AccountState `ch:"-" bun:"rel:has-one,join:address=address,join:created_lt=last_tx_lt" json:"account"`

	BlockWorkchain int32  `bun:",notnull" json:"block_workchain"`
	BlockShard     int64  `bun:",notnull" json:"block_shard"`
	BlockSeqNo     uint32 `bun:",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"`

	OutMsg      []*Message  `ch:"-" bun:"rel:has-many,join:address=src_address,join:created_lt=source_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"`

	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"`
	ResultCode        int32  `ch:"type:Int32" bun:",notnull" json:"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"`
	CreatedLT uint64    `bun:",notnull" json:"created_lt"`
}

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