app

package
v0.0.0-...-c1f1bd4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBlockSize is the maximum size of a block in bytes
	MaxBlockSize = 5000000
	// MinBlockSize is the minimum size of a block in bytes
	MinBlockSize = 1000
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(cipherText []byte, password string) ([]byte, error)

Decrypt decrypts cipherText with a given password

func Encrypt

func Encrypt(plainText []byte, password string) ([]byte, error)

Encrypt encrypts cipherText with a given password

func InvalidPassword

func InvalidPassword(err error) bool

InvalidPassword is returned from Decrypt if an invalid password is used to decrypt the ciphertext

func Run

func Run(cfg conf.Config)

Run sets up and starts a new Cumulus node with the given configuration. This should only be called once (except in tests)

func RunConsole

func RunConsole(a *App) *ishell.Shell

RunConsole starts the Cumulus console. This should be run only once as a goroutine, and logging should be redirected away from stdout before it is run. It takes a pointer to a PeerStore so we can use the PeerStore to interact with other peers and give the user info about the running instance.

func VerifyPasswordComplexity

func VerifyPasswordComplexity(password string) bool

VerifyPasswordComplexity verifies password complexity

Types

type App

type App struct {
	CurrentUser *User
	PeerStore   *peer.PeerStore
	Chain       *blockchain.BlockChain
	Miner       *miner.Miner
	Pool        *pool.Pool
	// contains filtered or unexported fields
}

App contains information about a running instance of a Cumulus node

func New

func New(user *User, pStore *peer.PeerStore, chain *blockchain.BlockChain, pool *pool.Pool) *App

New returns a new user with the given parameters

func (*App) ConnectAndDiscover

func (a *App) ConnectAndDiscover(target string)

ConnectAndDiscover tries to connect to a target and discover its peers.

func (*App) HandleBlock

func (a *App) HandleBlock(blk *blockchain.Block)

HandleBlock handles new blocks.

func (*App) HandleTransaction

func (a *App) HandleTransaction(txn *blockchain.Transaction)

HandleTransaction handles new transactions.

func (*App) HandleWork

func (a *App) HandleWork()

HandleWork continually collects new work from existing work channels.

func (*App) Pay

func (a *App) Pay(to string, amount uint64) error

Pay pays an amount of coin to an address `to`.

func (*App) PushHandler

func (a *App) PushHandler(push *msg.Push)

PushHandler is called every time a peer sends us a Push message except on peers whos PushHandlers have been overridden.

func (*App) RequestHandler

func (a *App) RequestHandler(req *msg.Request) msg.Response

RequestHandler is called every time a peer sends us a request message expect on peers whos PushHandlers have been overridden.

func (*App) ResumeMiner

func (a *App) ResumeMiner(restart bool)

ResumeMiner resumes the current mining job if restart is false, otherwise it restarts the miner with a new mining job.

func (*App) RunMiner

func (a *App) RunMiner()

RunMiner continuously pulls transactions form the transaction pool, uses them to create blocks, and mines those blocks. When a block is mined it is added to the blockchain and broadcasted into the network. RunMiner returns when miner.StopMining() or miner.PauseIfRunning() are called.

func (*App) SyncBlockChain

func (a *App) SyncBlockChain() (bool, error)

SyncBlockChain updates the local copy of the blockchain by requesting missing blocks from peers. Returns true if the blockchain changed as a result of calling this function, false if it didn't and an error if we are not connected to any peers.

type User

type User struct {
	Wallet       *blockchain.Wallet
	Name         string
	BlockSize    uint32
	CryptoWallet bool
}

User holds basic user information.

func LoadUser

func LoadUser(fileName string) (*User, error)

LoadUser attempts to read user info from the file with the given name in the current working directory in JSON format. On success this returns a pointer to a new user constructed from the information in the file. If an error occurrs it is returned.

func NewUser

func NewUser() *User

NewUser creates a new user

func (*User) DecryptPrivateKey

func (u *User) DecryptPrivateKey(password string) error

DecryptPrivateKey decrypts the user's private key

func (*User) EncryptPrivateKey

func (u *User) EncryptPrivateKey(password string) error

EncryptPrivateKey encrypts the user's private key

func (*User) Public

func (u *User) Public() blockchain.Address

Public returns the public key of the given user

func (*User) Save

func (u *User) Save(fileName string) error

Save writes the user to a file of the given name in the current working directory in JSON format. It returns an error if one occurred, or a pointer to the file that was written to on success.

Jump to

Keyboard shortcuts

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