tokens

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const WithdrawalCreateJobType = "withdrawal_create"

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountAddedHandler

type AccountAddedHandler struct {
	TemplateService templates.Service
	TokenService    Service
}

func (*AccountAddedHandler) Handle

type AccountToken

type AccountToken struct {
	ID             uint64              `json:"-" gorm:"column:id;primaryKey"`
	AccountAddress string              `json:"-" gorm:"column:account_address;uniqueIndex:addressname;index;not null"`
	Account        accounts.Account    `json:"-" gorm:"foreignKey:AccountAddress;references:Address;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	TokenName      string              `json:"name" gorm:"column:token_name;uniqueIndex:addressname;index;not null"`
	TokenAddress   string              `json:"address" gorm:"column:token_address;uniqueIndex:addressname;index;not null"`
	TokenType      templates.TokenType `json:"-" gorm:"column:token_type"`
	CreatedAt      time.Time           `json:"-" gorm:"column:created_at"`
	UpdatedAt      time.Time           `json:"-" gorm:"column:updated_at"`
	DeletedAt      gorm.DeletedAt      `json:"-" gorm:"column:deleted_at;index"`
}

AccountToken represents a token that is enabled on an account.

func (AccountToken) TableName added in v0.6.0

func (AccountToken) TableName() string

type Balance

type Balance struct {
	CadenceValue cadence.Value
}

func (*Balance) MarshalJSON

func (b *Balance) MarshalJSON() ([]byte, error)

type ChainEventHandler

type ChainEventHandler struct {
	AccountService  accounts.Service
	ChainListener   chain_events.Listener
	TemplateService templates.Service
	TokenService    Service
}

func (*ChainEventHandler) Handle

func (h *ChainEventHandler) Handle(ctx context.Context, event flow.Event)

type Details

type Details struct {
	TokenName string   `json:"name"`
	Address   string   `json:"address,omitempty"`
	Balance   *Balance `json:"balance,omitempty"`
}

type GormStore

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

func (*GormStore) AccountTokens

func (s *GormStore) AccountTokens(address string, tokenType templates.TokenType) (att []AccountToken, err error)

func (*GormStore) InsertAccountToken

func (s *GormStore) InsertAccountToken(at *AccountToken) error

func (*GormStore) InsertTokenTransfer

func (s *GormStore) InsertTokenTransfer(t *TokenTransfer) error

func (*GormStore) TokenDeposit

func (s *GormStore) TokenDeposit(address, transactionId string, token *templates.Token) (t *TokenTransfer, err error)

func (*GormStore) TokenDeposits

func (s *GormStore) TokenDeposits(address string, token *templates.Token) (tt []*TokenTransfer, err error)

func (*GormStore) TokenWithdrawal

func (s *GormStore) TokenWithdrawal(address, transactionId string, token *templates.Token) (t *TokenTransfer, err error)

func (*GormStore) TokenWithdrawals

func (s *GormStore) TokenWithdrawals(address string, token *templates.Token) (tt []*TokenTransfer, err error)

type Service

type Service interface {
	Setup(ctx context.Context, sync bool, tokenName, address string) (*jobs.Job, *transactions.Transaction, error)
	AddAccountToken(tokenName, address string) error
	AccountTokens(address string, tType templates.TokenType) ([]AccountToken, error)
	Details(ctx context.Context, tokenName, address string) (*Details, error)
	CreateWithdrawal(ctx context.Context, sync bool, sender string, request WithdrawalRequest) (*jobs.Job, *transactions.Transaction, error)
	ListWithdrawals(address, tokenName string) ([]*TokenWithdrawal, error)
	ListDeposits(address, tokenName string) ([]*TokenDeposit, error)
	GetWithdrawal(address, tokenName, transactionId string) (*TokenWithdrawal, error)
	GetDeposit(address, tokenName, transactionId string) (*TokenDeposit, error)
	RegisterDeposit(ctx context.Context, token *templates.Token, transactionId flow.Identifier, recipient accounts.Account, amountOrNftID string) error

	// DeployTokenContractForAccount is only used in tests
	DeployTokenContractForAccount(ctx context.Context, runSync bool, tokenName, address string) error
}

type ServiceImpl added in v0.10.0

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

func (*ServiceImpl) AccountTokens added in v0.10.0

func (s *ServiceImpl) AccountTokens(address string, tType templates.TokenType) ([]AccountToken, error)

func (*ServiceImpl) AddAccountToken added in v0.10.0

func (s *ServiceImpl) AddAccountToken(tokenName, address string) error

func (*ServiceImpl) CreateWithdrawal added in v0.10.0

func (s *ServiceImpl) CreateWithdrawal(ctx context.Context, sync bool, sender string, request WithdrawalRequest) (*jobs.Job, *transactions.Transaction, error)

func (*ServiceImpl) DeployTokenContractForAccount added in v0.10.0

func (s *ServiceImpl) DeployTokenContractForAccount(ctx context.Context, runSync bool, tokenName, address string) error

DeployTokenContractForAccount is used for testing purposes.

func (*ServiceImpl) Details added in v0.10.0

func (s *ServiceImpl) Details(ctx context.Context, tokenName, address string) (*Details, error)

Details is used to get the accounts balance (or similar for NFTs) for a token.

func (*ServiceImpl) GetDeposit added in v0.10.0

func (s *ServiceImpl) GetDeposit(address, tokenName, transactionId string) (*TokenDeposit, error)

func (*ServiceImpl) GetWithdrawal added in v0.10.0

func (s *ServiceImpl) GetWithdrawal(address, tokenName, transactionId string) (*TokenWithdrawal, error)

func (*ServiceImpl) ListDeposits added in v0.10.0

func (s *ServiceImpl) ListDeposits(address, tokenName string) ([]*TokenDeposit, error)

func (*ServiceImpl) ListWithdrawals added in v0.10.0

func (s *ServiceImpl) ListWithdrawals(address, tokenName string) ([]*TokenWithdrawal, error)

func (*ServiceImpl) RegisterDeposit added in v0.10.0

func (s *ServiceImpl) RegisterDeposit(ctx context.Context, token *templates.Token, transactionId flow.Identifier, recipient accounts.Account, amountOrNftID string) error

RegisterDeposit is an internal API for registering token deposits from on-chain events.

func (*ServiceImpl) Setup added in v0.10.0

func (s *ServiceImpl) Setup(ctx context.Context, sync bool, tokenName, address string) (*jobs.Job, *transactions.Transaction, error)

type Store

type Store interface {
	// List an accounts enabled tokens
	AccountTokens(address string, tokenType templates.TokenType) ([]AccountToken, error)

	// Enable a token for an account
	InsertAccountToken(at *AccountToken) error

	InsertTokenTransfer(*TokenTransfer) error
	TokenWithdrawals(address string, token *templates.Token) ([]*TokenTransfer, error)
	TokenWithdrawal(address, transactionId string, token *templates.Token) (*TokenTransfer, error)
	TokenDeposits(address string, token *templates.Token) ([]*TokenTransfer, error)
	TokenDeposit(address, transactionId string, token *templates.Token) (*TokenTransfer, error)
}

Store manages data regarding tokens.

func NewGormStore

func NewGormStore(db *gorm.DB) Store

type TokenDeposit

type TokenDeposit struct {
	TokenTransferBase
	SenderAddress string `json:"sender"`
}

TokenDeposit is used for JSON interfacing

type TokenTransfer

type TokenTransfer struct {
	ID               uint64                   `gorm:"column:id;primaryKey"`
	TransactionId    string                   `gorm:"column:transaction_id"` // TODO (latenssi): should propably be unique over this column
	Transaction      transactions.Transaction `gorm:"foreignKey:TransactionId;references:TransactionId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	RecipientAddress string                   `gorm:"column:recipient_address;index"`
	SenderAddress    string                   `gorm:"column:sender_address;index"`
	FtAmount         string                   `gorm:"column:ft_amount"`
	NftID            uint64                   `gorm:"column:nft_id"`
	TokenName        string                   `gorm:"column:token_name"`
	CreatedAt        time.Time                `gorm:"column:created_at"`
	UpdatedAt        time.Time                `gorm:"column:updated_at"`
	DeletedAt        gorm.DeletedAt           `gorm:"column:deleted_at;index"`
}

TokenTransfer is used for database interfacing

func (*TokenTransfer) Deposit

func (t *TokenTransfer) Deposit() TokenDeposit

func (TokenTransfer) TableName added in v0.6.0

func (TokenTransfer) TableName() string

func (*TokenTransfer) Withdrawal

func (t *TokenTransfer) Withdrawal() TokenWithdrawal

type TokenTransferBase

type TokenTransferBase struct {
	TransactionId string    `json:"transactionId"`
	FtAmount      string    `json:"amount"`
	NftID         uint64    `json:"nftId"`
	TokenName     string    `json:"token"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

TokenTransferBase is used for JSON interfacing

type TokenWithdrawal

type TokenWithdrawal struct {
	TokenTransferBase
	RecipientAddress string `json:"recipient"`
}

TokenWithdrawal is used for JSON interfacing

type WithdrawalRequest

type WithdrawalRequest struct {
	TokenName string `json:"tokenName,omitempty"`
	Recipient string `json:"recipient"`
	FtAmount  string `json:"amount,omitempty"`
	NftID     uint64 `json:"nftId,omitempty"`
}

Jump to

Keyboard shortcuts

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