api

package
v0.0.0-...-d1fccd7 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2019 License: GPL-3.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DBFilename is a path of the database file
	DBFilename = "./api.db"

	// MaxOffset is maximum number of transactions in database
	// https://github.com/golang/go/issues/9373 issue prevents to use max uint64 value
	MaxOffset = ^uint64(0) / 2
)

Variables

This section is empty.

Functions

func RunRestAPI

func RunRestAPI(api BlockchainAPI)

RunRestAPI registers router and runs web server

Types

type API

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

API struct stores all data source objects for blockchain api methods

func New

func New(bm *books.Accounts, db DataBase, sync *replication.Sync, m *mint.Mint) *API

New returns new instance of blockchain api

func (*API) AccountTransactions

func (api *API) AccountTransactions(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)

AccountTransactions returns transactions from and to 'keyBase64' account

func (*API) Balances

func (api *API) Balances(keys []string) []int64

Balances takes array of account public keys in base64 format and returns balances

func (*API) BlockByHash

func (api *API) BlockByHash(hashBase64 string) *block.Block

BlockByHash returns block with hash

func (*API) BlockByHeight

func (api *API) BlockByHeight(height uint64) *block.Block

BlockByHeight returns meta info of block with specific height value

func (*API) BlockHeight

func (api *API) BlockHeight() uint64

BlockHeight returns last block's height, registered in the ledger

func (*API) BlockTime

func (api *API) BlockTime() int64

BlockTime returns time for creating single block in milliseconds

func (*API) BlockTransactionsByHeight

func (api *API) BlockTransactionsByHeight(blockHeight uint64, offset, limit uint64) (*block.Transactions, uint64)

BlockTransactionsByHeight looks for block according heigh and returns it's transactions

func (*API) Blocks

func (api *API) Blocks(offset, limit uint64) ([]block.Block, uint64)

Blocks returns block according offset

func (*API) BlocksTotal

func (api *API) BlocksTotal() uint64

BlocksTotal returns number of processed blocks from books

func (*API) MintKey

func (api *API) MintKey() ed25519.PublicKey

MintKey returns mint key, to monitor it's balance on web site

func (*API) Nodes

func (api *API) Nodes() map[string]*replication.NodeData

Nodes returns remote nodes connected to us

func (*API) RandomKeys

func (api *API) RandomKeys(num uint64) []ed25519.PublicKey

RandomKeys returns account keys from book manager, to monitor them on web site

func (*API) TPS

func (api *API) TPS() int64

TPS returns latest TPS

func (*API) TransactionsFrom

func (api *API) TransactionsFrom(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)

TransactionsFrom returns transactions from 'keyBase64' account

func (*API) TransactionsTo

func (api *API) TransactionsTo(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)

TransactionsTo returns transactions to 'keyBase64' account

func (*API) TransactionsTotal

func (api *API) TransactionsTotal() uint64

TransactionsTotal returns total transactions count

type AccountModel

type AccountModel struct {
	PublicKey string
	Balance   int64
}

AccountModel is the data model of the Ansiblock blockchain Accounts. It is passed to the front end to display each account public key with its balance

type BlockDetailsModel

type BlockDetailsModel struct {
	Count         uint64
	VDF           string
	BlockHeight   uint64
	Taransactions []TransactionModel
}

BlockDetailsModel is the data model of the Ansiblock blockchain detailed blocks. It is passed to the front end to display detailed info of the block

type BlockListModel

type BlockListModel struct {
	Blocks []BlockModel
	Offset uint64
}

BlockListModel stores block list and offset value, for paging, to get next part of blocks

type BlockModel

type BlockModel struct {
	Size         int
	VDF          string
	BlockHeight  uint64
	Transactions int32
}

BlockModel is the data model of the Ansiblock blockchain blocks. It is passed to the front end to display each block

type BlockchainAPI

type BlockchainAPI interface {
	Nodes() map[string]*replication.NodeData
	TransactionsTotal() uint64
	BlocksTotal() uint64
	Balances(keys []string) []int64
	TransactionsFrom(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)
	TransactionsTo(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)
	AccountTransactions(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)
	BlockTransactionsByHeight(blockHeight uint64, offset, limit uint64) (*block.Transactions, uint64)
	Blocks(offset, limit uint64) ([]block.Block, uint64)
	BlockByHeight(height uint64) *block.Block
	BlockByHash(hashBase64 string) *block.Block
	BlockHeight() uint64
	TPS() int64
	BlockTime() int64
	RandomKeys(uint64) []ed25519.PublicKey
	MintKey() ed25519.PublicKey
}

BlockchainAPI gives access to information about blocks, transactions, nodes etc. part of information is extracted from db.

type BlockchainApiMock

type BlockchainApiMock struct {
	NodesMap             map[string]*replication.NodeData
	TransactionsTotalVal uint64
	BlocksToTalVal       uint64
	BalanceValues        []int64
	AccTransactions      *block.Transactions
	BlockTransactions    *block.Transactions
	BlocksList           []block.Block
	Block                *block.Block
	BlockHeightVal       uint64
	TPSVal               int64
	BlockTimeVal         int64
	QueryParams          map[string]string
}

func NewBlockchainAPIMock

func NewBlockchainAPIMock() *BlockchainApiMock

func (*BlockchainApiMock) AccountTransactions

func (apiMock *BlockchainApiMock) AccountTransactions(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)

func (*BlockchainApiMock) Balances

func (apiMock *BlockchainApiMock) Balances(keys []string) []int64

func (*BlockchainApiMock) BlockByHash

func (apiMock *BlockchainApiMock) BlockByHash(hashBase64 string) *block.Block

func (*BlockchainApiMock) BlockByHeight

func (apiMock *BlockchainApiMock) BlockByHeight(height uint64) *block.Block

func (*BlockchainApiMock) BlockHeight

func (apiMock *BlockchainApiMock) BlockHeight() uint64

func (*BlockchainApiMock) BlockTime

func (apiMock *BlockchainApiMock) BlockTime() int64

func (*BlockchainApiMock) BlockTransactionsByHeight

func (apiMock *BlockchainApiMock) BlockTransactionsByHeight(blockHeight uint64, offset, limit uint64) (*block.Transactions, uint64)

func (*BlockchainApiMock) Blocks

func (apiMock *BlockchainApiMock) Blocks(offset, limit uint64) ([]block.Block, uint64)

func (*BlockchainApiMock) BlocksTotal

func (apiMock *BlockchainApiMock) BlocksTotal() uint64

func (*BlockchainApiMock) MintKey

func (apiMock *BlockchainApiMock) MintKey() ed25519.PublicKey

func (*BlockchainApiMock) Nodes

func (apiMock *BlockchainApiMock) Nodes() map[string]*replication.NodeData

func (*BlockchainApiMock) RandomKeys

func (apiMock *BlockchainApiMock) RandomKeys(uint64) []ed25519.PublicKey

func (*BlockchainApiMock) TPS

func (apiMock *BlockchainApiMock) TPS() int64

func (*BlockchainApiMock) TransactionsFrom

func (apiMock *BlockchainApiMock) TransactionsFrom(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)

func (*BlockchainApiMock) TransactionsTo

func (apiMock *BlockchainApiMock) TransactionsTo(keyBase64 string, offset, limit uint64) (*block.Transactions, uint64)

func (*BlockchainApiMock) TransactionsTotal

func (apiMock *BlockchainApiMock) TransactionsTotal() uint64

type DB

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

DB is database object, created by NewDBConnection method

func NewDBConnection

func NewDBConnection(dbFileName string) *DB

NewDBConnection creates a connection to database Database will be initialized with tables and indexes if there is no file or it does not contain necessary schema

func (*DB) GetAccountTransactions

func (db *DB) GetAccountTransactions(account []byte, offset, limit uint64) (*block.Transactions, uint64)

GetAccountTransactions gets abstract of given account from database including transaction with given offset

func (*DB) GetBlockByHash

func (db *DB) GetBlockByHash(hash []byte) *block.Block

GetBlockByHash gets block from database with VDF value returns pointer to block or nil if not found

func (*DB) GetBlockByHeight

func (db *DB) GetBlockByHeight(height uint64) *block.Block

GetBlockByHeight gets block from database searching by height returns pointer to block or nil if not found

func (*DB) GetBlocksAfterHeight

func (db *DB) GetBlocksAfterHeight(offset, limit uint64) ([]block.Block, uint64)

GetBlocksAfterHeight gets unseen new blocks from database by height, including block with given height

func (*DB) GetBlocksBeforeHeight

func (db *DB) GetBlocksBeforeHeight(offset, limit uint64) ([]block.Block, uint64)

GetBlocksBeforeHeight gets old blocks from database by height, including block with given height

func (*DB) GetTransactionsFrom

func (db *DB) GetTransactionsFrom(from []byte, offset, limit uint64) (*block.Transactions, uint64)

GetTransactionsFrom gets transactions from DB sent from given address including transaction with given offset

func (*DB) GetTransactionsTo

func (db *DB) GetTransactionsTo(to []byte, offset, limit uint64) (*block.Transactions, uint64)

GetTransactionsTo gets transactions from DB received by given address including transaction with given offset

func (*DB) GetTxFromBlockByHeight

func (db *DB) GetTxFromBlockByHeight(height uint64, offset, limit uint64) (*block.Transactions, uint64)

GetTxFromBlockByHeight returns transactions associated with block given by height including transaction with given offset

func (*DB) SaveBlock

func (db *DB) SaveBlock(blk block.Block) error

SaveBlock saves given block to database

type DBMock

type DBMock struct {
	Trans  *block.Transactions
	Block  *block.Block
	Blocks []*block.Block
	From   []byte
	To     []byte
}

func (*DBMock) GetAccountTransactions

func (db *DBMock) GetAccountTransactions(account []byte, offset, limit uint64) (*block.Transactions, uint64)

func (*DBMock) GetBlockByHash

func (db *DBMock) GetBlockByHash(hash []byte) *block.Block

func (*DBMock) GetBlockByHeight

func (db *DBMock) GetBlockByHeight(height uint64) *block.Block

func (*DBMock) GetBlocksAfterHeight

func (db *DBMock) GetBlocksAfterHeight(offset, limit uint64) ([]block.Block, uint64)

func (*DBMock) GetBlocksBeforeHeight

func (db *DBMock) GetBlocksBeforeHeight(offset, limit uint64) ([]block.Block, uint64)

func (*DBMock) GetTransactionsFrom

func (db *DBMock) GetTransactionsFrom(from []byte, offset, limit uint64) (*block.Transactions, uint64)

func (*DBMock) GetTransactionsTo

func (db *DBMock) GetTransactionsTo(to []byte, offset, limit uint64) (*block.Transactions, uint64)

func (*DBMock) GetTxFromBlockByHeight

func (db *DBMock) GetTxFromBlockByHeight(height uint64, offset, limit uint64) (*block.Transactions, uint64)

func (*DBMock) SaveBlock

func (db *DBMock) SaveBlock(blk block.Block) error

type DataBase

type DataBase interface {
	SaveBlock(blk block.Block) error
	GetBlockByHash(hash []byte) *block.Block
	GetBlockByHeight(Height uint64) *block.Block
	GetBlocksAfterHeight(offset, limit uint64) ([]block.Block, uint64)
	GetBlocksBeforeHeight(offset, limit uint64) ([]block.Block, uint64)
	GetTxFromBlockByHeight(height uint64, offset, limit uint64) (*block.Transactions, uint64)
	GetTransactionsFrom(from []byte, offset, limit uint64) (*block.Transactions, uint64)
	GetTransactionsTo(to []byte, offset, limit uint64) (*block.Transactions, uint64)
	GetAccountTransactions(account []byte, offset, limit uint64) (*block.Transactions, uint64)
}

DataBase interface

type NodeDataModel

type NodeDataModel struct {
	Version  uint64
	Address  string
	NodeType string
	Name     string
}

NodeDataModel is the data model of the Ansiblock blockchain nodes. It is passed to the front end to display info of the nodes in the blockchain

type Stats

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

Stats struct stores global statistics

type StatsModel

type StatsModel struct {
	BlockHeight uint64
	TPS         uint64
	NodeCount   uint64
	BlockTime   uint64
}

StatsModel is the data model of the Ansiblock blockchain stats. It is passed to the front end to display

type TransactinListModel

type TransactinListModel struct {
	Ts     []TransactionModel
	Offset uint64
}

TransactinListModel stores transaction list and offset value, for gaping, to get next part of transactions

type TransactionModel

type TransactionModel struct {
	From          string
	To            string
	Token         int64
	Fee           int64
	ValidVDFValue string
	Signature     string
}

TransactionModel is the data model of the Ansiblock blockchain transaction. It is passed to the front end to display each transaction

Jump to

Keyboard shortcuts

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