blockchain

package
v0.0.0-...-2cefb57 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2015 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HASH_GENESIS_BLOCK = "hwm5tjMI9ZsvG2VwNKeMtJq7PDLDvPM/hLFQ2VYdE88="
)
View Source
const (
	REGISTRATION_FEE = uint64(1000)
)
View Source
const (
	REVOKE_FEE = uint64(100)
)
View Source
const (
	UPDATE_FEE = uint64(100)
)

Variables

View Source
var (
	CURRENT_DIFFICULTY   = uint64(16)
	CURRENT_BLOCK_REWARD = uint64(50000000)
)

Functions

func Mine

func Mine()

Types

type Block

type Block struct {
	Header BlockHeader `json:"header"`
	Txns   []Txn       `json:"txns"`
}

func GenesisBlock

func GenesisBlock() Block

func NewBlock

func NewBlock(prev BlockHeader, minerAddress crypto.SHA256Sum) Block

func (Block) Json

func (b Block) Json() []byte

type BlockHeader

type BlockHeader struct {
	SeqNum     uint64           `json:"seq_num"`
	PrevHash   crypto.SHA256Sum `json:"prev_hash"`
	TxnAcc     asm.AsyncAcc     `json:"txn_acc"`
	PKIAcc     asm.AsyncAcc     `json:"pki_acc"`
	Time       time.Time        `json:"time"`
	Difficulty uint64           `json:"difficulty"`
	Nonce      uint64           `json:"nonce:"`
}

func (BlockHeader) Hash

func (b BlockHeader) Hash() crypto.SHA256Sum

func (BlockHeader) Json

func (b BlockHeader) Json() []byte

func (BlockHeader) ValidPoW

func (bh BlockHeader) ValidPoW() bool

type Blockchain

type Blockchain struct {
	SVP
	BlockDBPath string
	UTxnDBPath  string
}

func NewBlockchain

func NewBlockchain() Blockchain

func (*Blockchain) ValidBlock

func (bc *Blockchain) ValidBlock(b Block) bool

func (*Blockchain) ValidGenerationTxn

func (bc *Blockchain) ValidGenerationTxn(t Txn) bool

func (*Blockchain) ValidPaymentTxn

func (bc *Blockchain) ValidPaymentTxn(t Txn) bool

func (*Blockchain) ValidRegisterTxn

func (bc *Blockchain) ValidRegisterTxn(t Txn) bool

func (*Blockchain) ValidRevokeTxn

func (bc *Blockchain) ValidRevokeTxn(t Txn) bool

func (*Blockchain) ValidTxns

func (bc *Blockchain) ValidTxns(b Block) bool

func (*Blockchain) ValidUpdateTxn

func (bc *Blockchain) ValidUpdateTxn(t Txn) bool

func (*Blockchain) WriteBlock

func (bc *Blockchain) WriteBlock(b Block) error

type GenerationTxn

type GenerationTxn struct {
	TxnType TxnType
	Ins     []Input
	Outs    []Output
}

type Identity

type Identity struct {
	Domain    crypto.SHA256Sum
	Subdomain crypto.SHA256Sum
}

func NewIdentity

func NewIdentity(domain, subdomain string) (Identity, error)

func (Identity) FullName

func (i Identity) FullName() string

type Input

type Input struct {
	PrevHash  crypto.SHA256Sum         `json:"hash"`
	PublicKey crypto.CertcoinPublicKey `json:"public"`
	Signature crypto.CertcoinSignature `json:"sig"`
}

type Output

type Output struct {
	Address crypto.SHA256Sum `json:"address"`
	Value   uint64           `json:"value"`
}

type SVP

type SVP struct {
	HeaderDBPath string
	LastHeader   BlockHeader
}

func NewSVP

func NewSVP() SVP

func (*SVP) ValidHeader

func (s *SVP) ValidHeader(header BlockHeader) bool

func (*SVP) WriteHeader

func (s *SVP) WriteHeader(header BlockHeader) error

type Txn

type Txn struct {
	Type    TxnType  `json:"txn_type"`
	Inputs  []Input  `json:"inputs"`
	Outputs []Output `json:"outputs"`
}

func NewGenerationTxn

func NewGenerationTxn(to crypto.SHA256Sum) Txn

func NewPaymentTxn

func NewPaymentTxn(from crypto.CertcoinPublicKey, to crypto.SHA256Sum, value uint64) Txn

func NewRegisterTxn

func NewRegisterTxn(onlineSecret, offlineSecret crypto.CertcoinSecretKey,
	source crypto.CertcoinPublicKey,
	identity Identity) Txn

func NewRevokeTxn

func NewRevokeTxn(onlineSecret, offlineSecret crypto.CertcoinSecretKey,
	source crypto.CertcoinPublicKey,
	identity Identity) Txn

func NewUpdateTxn

func NewUpdateTxn(onlineSecret, offlineSecret crypto.CertcoinSecretKey,
	source crypto.CertcoinPublicKey,
	identity Identity) Txn

func (Txn) Hash

func (t Txn) Hash() crypto.SHA256Sum

func (Txn) Json

func (t Txn) Json() []byte

func (Txn) ValidNumInputs

func (t Txn) ValidNumInputs(reserved int) bool

func (Txn) ValidNumOutputs

func (t Txn) ValidNumOutputs() bool

type TxnType

type TxnType uint8
const (
	Generation TxnType = iota
	Payment
	Register
	Update
	Revoke
)

Jump to

Keyboard shortcuts

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