wallet

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package wallet is used inside KMS to provide features related to wallet generation & CRUD access.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAddress         = errors.New("invalid address")
	ErrInvalidContractAddress = errors.New("invalid contract address")
	ErrInvalidAmount          = errors.New("invalid amount")
	ErrInvalidNetwork         = errors.New("invalid network")
	ErrInvalidGasSettings     = errors.New("invalid network gas settings")
	ErrInvalidNonce           = errors.New("invalid nonce")
	ErrTronResponse           = errors.New("invalid response from TRON node")
	ErrInsufficientBalance    = errors.New("sender balance is insufficient")
	ErrUnknownBlockchain      = errors.New("unknown blockchain")
)
View Source
var ErrNotFound = errors.New("wallet not found")

Functions

func ValidateAddress

func ValidateAddress(blockchain Blockchain, address string) error

Types

type AssetType

type AssetType string
const (
	Coin  AssetType = "coin"
	Token AssetType = "token"
)

func (AssetType) Valid

func (t AssetType) Valid() bool

type BitcoinProvider

type BitcoinProvider struct {
	Blockchain   Blockchain
	CryptoReader io.Reader
}

func (*BitcoinProvider) Generate

func (p *BitcoinProvider) Generate() *Wallet

func (*BitcoinProvider) GetBlockchain

func (p *BitcoinProvider) GetBlockchain() Blockchain

func (*BitcoinProvider) ValidateAddress

func (p *BitcoinProvider) ValidateAddress(address string) bool

type Blockchain

type Blockchain string
const (
	BTC   Blockchain = "BTC"
	ETH   Blockchain = "ETH"
	TRON  Blockchain = "TRON"
	MATIC Blockchain = "MATIC"
	BSC   Blockchain = "BSC"
)

func ListBlockchains

func ListBlockchains() []Blockchain

func (Blockchain) IsSpecified

func (b Blockchain) IsSpecified() bool

func (Blockchain) IsValid

func (b Blockchain) IsValid() bool

func (Blockchain) NotSpecified

func (b Blockchain) NotSpecified() bool

func (Blockchain) String

func (b Blockchain) String() string

func (Blockchain) ToMoneyBlockchain

func (b Blockchain) ToMoneyBlockchain() money.Blockchain

type CreateTransactionParams

type CreateTransactionParams struct {
	Type            AssetType
	Recipient       string
	AmountRaw       string
	NetworkID       string
	ContractAddress *string
}

type EthProvider

type EthProvider struct {
	Blockchain   Blockchain
	CryptoReader io.Reader
}

EthProvider generates wallets for eth-like chains (eth, tron, bsc, matic, ...)

func (*EthProvider) Generate

func (p *EthProvider) Generate() *Wallet

func (*EthProvider) GetBlockchain

func (p *EthProvider) GetBlockchain() Blockchain

func (*EthProvider) NewTransaction

func (p *EthProvider) NewTransaction(w *Wallet, params EthTransactionParams) (string, error)

func (*EthProvider) ValidateAddress

func (p *EthProvider) ValidateAddress(address string) bool

type EthTransactionParams

type EthTransactionParams struct {
	Type AssetType

	Recipient       string
	Amount          string
	ContractAddress string

	NetworkID int64
	Nonce     int64

	MaxPriorityFeePerGas string
	MaxFeePerGas         string
	Gas                  int64
}

type Generator

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

func NewGenerator

func NewGenerator() *Generator

func (*Generator) AddProvider

func (g *Generator) AddProvider(provider Provider) *Generator

func (*Generator) CreateWallet

func (g *Generator) CreateWallet(blockchain Blockchain) (*Wallet, error)

type Provider

type Provider interface {
	Generate() *Wallet
	GetBlockchain() Blockchain
	ValidateAddress(address string) bool
}

type Repository

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

func NewRepository

func NewRepository(db *bbolt.DB) *Repository

func (*Repository) Get

func (r *Repository) Get(id uuid.UUID, withTrashed bool) (*Wallet, error)

func (*Repository) Set

func (r *Repository) Set(w *Wallet) error

func (*Repository) SoftDelete

func (r *Repository) SoftDelete(w *Wallet) error

type Service

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

func New

func New(repo *Repository, generator *Generator, logger *zerolog.Logger) *Service

func (*Service) CreateBSCTransaction added in v0.3.0

func (s *Service) CreateBSCTransaction(_ context.Context, wt *Wallet, params EthTransactionParams) (string, error)

func (*Service) CreateEthereumTransaction

func (s *Service) CreateEthereumTransaction(_ context.Context, wt *Wallet, params EthTransactionParams) (string, error)

CreateEthereumTransaction creates and sings new raw Ethereum transaction based on provided input.

func (*Service) CreateMaticTransaction

func (s *Service) CreateMaticTransaction(_ context.Context, wt *Wallet, params EthTransactionParams) (string, error)

func (*Service) CreateTronTransaction

func (s *Service) CreateTronTransaction(
	ctx context.Context, wallet *Wallet, params TronTransactionParams,
) (TronTransaction, error)

func (*Service) CreateWallet

func (s *Service) CreateWallet(_ context.Context, blockchain Blockchain) (*Wallet, error)

func (*Service) DeleteWallet

func (s *Service) DeleteWallet(ctx context.Context, id uuid.UUID) error

func (*Service) GetWallet

func (s *Service) GetWallet(_ context.Context, id uuid.UUID, withTrashed bool) (*Wallet, error)

type TronProvider

type TronProvider struct {
	Blockchain   Blockchain
	Trongrid     *trongrid.Provider
	CryptoReader io.Reader
}

func (*TronProvider) Base58ToHexAddress

func (p *TronProvider) Base58ToHexAddress(address string) (string, error)

Base58ToHexAddress converts from base58 to hex. Example: input: TBREsCfBdPyD612xZnwvGPux7osbXvtzLh output: 410fe47f49fd91f0edb7fa2b94a3c45d9c2231709c

func (*TronProvider) Generate

func (p *TronProvider) Generate() *Wallet

func (*TronProvider) GetBlockchain

func (p *TronProvider) GetBlockchain() Blockchain

func (*TronProvider) NewTransaction

func (p *TronProvider) NewTransaction(
	ctx context.Context,
	wallet *Wallet,
	params TronTransactionParams,
) (TronTransaction, error)

NewTransaction create new trx / trc20 transaction. see https://developers.tron.network/docs/tron-protocol-transaction.

func (*TronProvider) ValidateAddress

func (p *TronProvider) ValidateAddress(address string) bool

type TronTransaction

type TronTransaction = trongrid.Transaction

type TronTransactionParams

type TronTransactionParams struct {
	Type            AssetType
	Recipient       string
	Amount          string
	ContractAddress string
	FeeLimit        uint64
	IsTest          bool
}

type Wallet

type Wallet struct {
	UUID       uuid.UUID  `json:"uuid"`
	Address    string     `json:"address"`
	PublicKey  string     `json:"public_key"`
	PrivateKey string     `json:"private_key"`
	CreatedAt  time.Time  `json:"created_at"`
	DeletedAt  *time.Time `json:"deleted_at"`
	Blockchain Blockchain `json:"blockchain"`
}

Jump to

Keyboard shortcuts

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