blockchain

package
v0.0.0-...-27a570a Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2017 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GENESIS_DIFF = 20000000000000
	USD_REWARD   = 250
)

Variables

This section is empty.

Functions

func GetReward

func GetReward(usdPrice int) int

Finds reward for a usd price Each block has a fixed reward in USD. usdPrice is found by using schelling. We do this to keep the price of the coin somewhat stable. There is one huge flaw however: you will get a good hash about 2**256/difficulty times, thus with a higher difficulty the reward should grow.

func NewTransactionList

func NewTransactionList(transactions []wallet.Transaction) ([]byte, error)

Function that generates a Segwit list of transactions.

func SumDexmHashVOne

func SumDexmHashVOne(nonce, block []byte) (*big.Int, error)

First version of the PoW hash. Uses lyra2rev2

func VerifyTransactionSignature

func VerifyTransactionSignature(transaction wallet.Transaction) (bool, error)

Verify if a transaction has a valid signature

Types

type Block

type Block struct {
	Index             int64  `bson:"i"`
	Timestamp         int64  `bson:"t"`
	Hash              string `bson:"h"`
	PreviousBlockHash string `bson:"p"`
	TransactionList   []byte `bson:"l,omitempty"`
	ContractList      []byte `bson:"c,omitempty"`
	Miner             string `bson:"m"`
}

func (*Block) CalculateHash

func (b *Block) CalculateHash() string

func (*Block) GetBytes

func (b *Block) GetBytes() []byte

Turns a block into a []byte

func (*Block) GetDifficulty

func (b *Block) GetDifficulty(bc *BlockChain) *big.Int

Returns difficulty for a given block This function assumes the block is valid. TODO Implement adjustments based on Shelling results and hashing power

type BlockChain

type BlockChain struct {
	DB       *leveldb.DB
	Balances *leveldb.DB
}

func NewBlockChain

func NewBlockChain() *BlockChain

Generates a new blockchain with only the genesis block

func OpenBlockchain

func OpenBlockchain() *BlockChain

Opens the databases used internally by Dexm

func (*BlockChain) GenerateBalanceDB

func (bc *BlockChain) GenerateBalanceDB()

Generates database of all balances in the blockchain

func (*BlockChain) GetBalance

func (bc *BlockChain) GetBalance(wallet string) (int, int, int)

Given a wallet returns balance and nonce

func (*BlockChain) GetBlock

func (bc *BlockChain) GetBlock(index int64) (*Block, error)

Returns a block at index i

func (*BlockChain) GetLen

func (bc *BlockChain) GetLen() int64

Returns how many blocks are in the chain

func (*BlockChain) GetPoBWallets

func (bc *BlockChain) GetPoBWallets(nodes int) []string

Returns random wallets based on their burn. TODO Add PoB decay

func (*BlockChain) NewBlock

func (bc *BlockChain) NewBlock(transactionList, contractList []byte)

Turns transactions and contracts into a block without the proof of work. Then stores it in the DB TODO Only PoW blocks shold be on the DB

func (*BlockChain) ProcessBlock

func (bc *BlockChain) ProcessBlock(curr *Block) error

Takes in a block and then updates all balances

func (*BlockChain) SetBalance

func (bc *BlockChain) SetBalance(wallet string, amount, nonce, burn int) error

Stores amount, nonce, and burn for a given wallet

func (*BlockChain) VerifyNewBlockValidity

func (bc *BlockChain) VerifyNewBlockValidity(minedBlock *PoWBlock) (bool, error)

Verify that a PoW block is valid

type PoWBlock

type PoWBlock struct {
	Nonce      big.Int
	MinedBlock *Block
}

type SegwitTransaction

type SegwitTransaction struct {
	Sender    string `bson:"s"`
	Recipient string `bson:"r"`

	Amount      int   `bson:"a"`
	Gas         int   `bson:"g"`
	SenderNonce int   `bson:"n"`
	Timestamp   int64 `bson:"t"`
}

type WalletInfo

type WalletInfo struct {
	Balance int
	Nonce   int
	Burn    int
}

Jump to

Keyboard shortcuts

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