Documentation ¶
Index ¶
- Constants
- Variables
- func Run(ctx context.Context, c Config, repo Repository, bookkeeping Bookkeeper, ...) error
- type AddressReaderWriterModifier
- type AliveResponse
- type AwaitedIssuedTransactionRequest
- type AwaitedTransactionResponse
- type Bookkeeper
- type Config
- type CreateAddressRequest
- type CreateAddressResponse
- type DataToSignRequest
- type DataToSignResponse
- type GenerateTokenRequest
- type GenerateTokenResponse
- type IssuedTransactionResponse
- type Message
- type RandomDataProvideValidator
- type ReactiveSubscriberProvider
- type Register
- type Repository
- type SearchAddressRequest
- type SearchAddressResponse
- type SearchBlockRequest
- type SearchBlockResponse
- type TokenWriteInvalidateChecker
- type TransactionConfirmProposeResponse
- type TransactionProposeRequest
- type Verifier
Constants ¶
const ( ApiVersion = "1.0.0" Header = "Computantis-Central" )
const ( AliveURL = "/alive" // URL to check if server is alive and version. SearchAddressURL = searchGroupURL + addressURL // URL to search for address. SearchBlockURL = searchGroupURL + blockURL // URL to search for block that contains transaction hash. ProposeTransactionURL = transactionGroupURL + proposeURL // URL to propose transaction signed by the issuer. ConfirmTransactionURL = transactionGroupURL + confirmURL // URL to confirm transaction signed by the receiver. AwaitedTransactionURL = transactionGroupURL + awaitedURL // URL to get awaited transactions for the receiver. IssuedTransactionURL = transactionGroupURL + issuedURL // URL to get issued transactions for the issuer. DataToValidateURL = validatorGroupURL + dataURL // URL to get data to validate address by signing rew message. CreateAddressURL = addressGroupURL + createURL // URL to create new address. GenerateTokenURL = tokenGroupURL + generateURL // URL to generate new token. WsURL = "/ws" // URL to connect to websocket. )
const ( CommandEcho = "echo" CommandSocketList = "socketlist" CommandNewBlock = "command_new_block" CommandNewTransaction = "command_new_transaction" )
Variables ¶
var ( ErrWrongPortSpecified = errors.New("port must be between 1 and 65535") ErrWrongMessageSize = errors.New("message size must be between 1024 and 15000000") )
Functions ¶
func Run ¶
func Run( ctx context.Context, c Config, repo Repository, bookkeeping Bookkeeper, pv RandomDataProvideValidator, log logger.Logger, rx ReactiveSubscriberProvider, ) error
Run initializes routing and runs the server. To stop the server cancel the context. It blocks until the context is canceled.
Types ¶
type AddressReaderWriterModifier ¶
type AddressReaderWriterModifier interface { FindAddress(ctx context.Context, search string, limit int) ([]string, error) CheckAddressExists(ctx context.Context, address string) (bool, error) WriteAddress(ctx context.Context, address string) error IsAddressSuspended(ctx context.Context, addr string) (bool, error) IsAddressStandard(ctx context.Context, addr string) (bool, error) IsAddressTrusted(ctx context.Context, addr string) (bool, error) IsAddressAdmin(ctx context.Context, addr string) (bool, error) }
AddressReaderWriterModifier abstracts address operations.
type AliveResponse ¶
type AliveResponse struct { Alive bool `json:"alive"` APIVersion string `json:"api_version"` APIHeader string `json:"api_header"` }
AliveResponse is a response for alive and version check.
type AwaitedIssuedTransactionRequest ¶
type AwaitedIssuedTransactionRequest struct { Address string `json:"address"` Data []byte `json:"data"` Hash [32]byte `json:"hash"` Signature []byte `json:"signature"` }
AwaitedIssuedTransactionRequest is a request to get awaited or issued transactions for given address. Request contains of Address for which Transactions are requested, Data in binary format, Hash of Data and Signature of the Data to prove that entity doing the request is an Address owner.
type AwaitedTransactionResponse ¶
type AwaitedTransactionResponse struct { Success bool `json:"success"` AwaitedTransactions []transaction.Transaction `json:"awaited_transactions"` }
AwaitedTransactionResponse is a response for awaited transactions request.
type Bookkeeper ¶
type Bookkeeper interface { Verifier Run(ctx context.Context) WriteCandidateTransaction(ctx context.Context, tx *transaction.Transaction) error WriteIssuerSignedTransactionForReceiver(ctx context.Context, trx *transaction.Transaction) error }
Bookkeeper abstracts methods of the bookkeeping of a blockchain.
type Config ¶
type Config struct { Port int `yaml:"port"` // Port to listen on. DataSizeBytes int `yaml:"data_size_bytes"` // Size of the data to be stored in the transaction. WebsocketAddress string `yaml:"websocket_address"` // Address of the websocket server. }
Config contains configuration of the server.
type CreateAddressRequest ¶
type CreateAddressRequest struct { Address string `json:"address"` Token string `json:"token"` Data []byte `json:"data"` Hash [32]byte `json:"hash"` Signature []byte `json:"signature"` }
CreateAddressRequest is a request to create an address.
type CreateAddressResponse ¶
Response for address creation request. If Success is true, Address contains created address in base58 format.
type DataToSignRequest ¶
type DataToSignRequest struct {
Address string `json:"address"`
}
DataToSignRequest is a request to get data to sign for proving identity.
type DataToSignResponse ¶
type DataToSignResponse struct {
Data []byte `json:"message"`
}
DataToSignRequest is a response containing data to sign for proving identity.
type GenerateTokenRequest ¶
type GenerateTokenRequest struct { Address string `json:"address"` Expiration int64 `json:"expiration"` Data []byte `json:"data"` Hash [32]byte `json:"hash"` Signature []byte `json:"signature"` }
GenerateTokenRequest is a request for token generation.
type GenerateTokenResponse ¶
GenerateTokenResponse is a response containing generated token.
type IssuedTransactionResponse ¶
type IssuedTransactionResponse struct { Success bool `json:"success"` IssuedTransactions []transaction.Transaction `json:"issued_transactions"` }
AwaitedTransactionResponse is a response for issued transactions request.
type Message ¶
type Message struct { Command string `json:"command"` // Command is the command that refers to the action handler in websocket protocol. Error string `json:"error,omitempty"` // Error is the error message that is sent to the client. Block block.Block `json:"block,omitempty"` // Block is the block that is sent to the client. Transaction transaction.Transaction `json:"transaction,omitempty"` // Transaction is the transaction validated by the central server and will be added to the next block. Sockets []string `json:"sockets,omitempty"` // sockets is the list of central nodes web-sockets addresses. }
Message is the message that is used to exchange information between the server and the client.
type RandomDataProvideValidator ¶
type RandomDataProvideValidator interface { ProvideData(address string) []byte ValidateData(address string, data []byte) bool }
RandomDataProvideValidator provides random binary data for signing to prove identity and the validator of data being valid and not expired.
type ReactiveSubscriberProvider ¶
ReactiveSubscriberProvider provides reactive subscription to the blockchain. It allows to listen for the new blocks created by the Ladger.
type Register ¶
type Register interface { RegisterNode(ctx context.Context, n, ws string) error UnregisterNode(ctx context.Context, n string) error ReadRegisteredNodesAddresses(ctx context.Context) ([]string, error) CountRegistered(ctx context.Context) (int, error) }
Register abstracts node registration operations.
type Repository ¶
type Repository interface { Register AddressReaderWriterModifier TokenWriteInvalidateChecker FindTransactionInBlockHash(ctx context.Context, trxHash [32]byte) ([32]byte, error) ReadAwaitingTransactionsByIssuer(ctx context.Context, address string) ([]transaction.Transaction, error) ReadAwaitingTransactionsByReceiver(ctx context.Context, address string) ([]transaction.Transaction, error) }
Repository is the interface that wraps the basic CRUD and Search methods. Repository should be properly indexed to allow for transaction and block hash. as well as address public keys to be and unique and the hash lookup should be fast. Repository holds the blocks and transaction that are part of the blockchain.
type SearchAddressRequest ¶
type SearchAddressRequest struct {
Address string `json:"address"`
}
SearchAddressRequest is a request to search for address.
type SearchAddressResponse ¶
type SearchAddressResponse struct {
Addresses []string `json:"addresses"`
}
SearchAddressResponse is a response for address search.
type SearchBlockRequest ¶
type SearchBlockRequest struct { Address string `json:"address"` RawTrxHash [32]byte `json:"raw_trx_hash"` }
SearchBlockRequest is a request to search for block.
type SearchBlockResponse ¶
type SearchBlockResponse struct {
RawBlockHash [32]byte `json:"raw_block_hash"`
}
SearchBlockResponse is a response for block search.
type TokenWriteInvalidateChecker ¶
type TokenWriteInvalidateChecker interface { WriteToken(ctx context.Context, tkn string, expirationDate int64) error CheckToken(ctx context.Context, token string) (bool, error) InvalidateToken(ctx context.Context, token string) error }
TokenWriteInvalidateChecker abstracts token operations.
type TransactionConfirmProposeResponse ¶
type TransactionConfirmProposeResponse struct { Success bool `json:"success"` TrxHash [32]byte `json:"trx_hash"` }
TransactionConfirmProposeResponse is a response for transaction propose.
type TransactionProposeRequest ¶
type TransactionProposeRequest struct { ReceiverAddr string `json:"receiver_addr"` Transaction transaction.Transaction `json:"transaction"` }
TransactionProposeRequest is a request to propose a transaction.