Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
func CreateGenesis ¶
func CreateGenesis() *Block
func NewBlock ¶
func NewBlock(privateKey crypto.PrivKey, parent *Block, transactions []Transaction, votes []Vote) *Block
Example ¶
viper.Set("reward", 50) priv, _, _ := NewKeys() t := Pay(priv, peer.ID("some"), 42) v := NewVote(priv, "other") parent := CreateGenesis() block := NewBlock(priv, parent, []Transaction{*t}, []Vote{*v}) verified, _ := block.Verify(&parent.BlockData) fmt.Println(verified) block.Reward = 100 verified, _ = block.Verify(&parent.BlockData) fmt.Println(verified) block.Reward = 50 block.Transactions[0].Amount = 0 verified, _ = block.Verify(&parent.BlockData) fmt.Println(verified) block.Transactions[0].Amount = 42 block.Votes[0].Candidate = "third" verified, _ = block.Verify(&parent.BlockData) fmt.Println(verified)
Output: true false false false
type BlockData ¶
type BlockData struct { Unit ParentHash string Transactions Transactions Votes Votes Reward uint }
type Transaction ¶
Example ¶
priv, _, _ := NewKeys() t := Pay(priv, peer.ID("some"), 42) verified, _ := verify(t) fmt.Println(verified) t.Amount++ verified, _ = verify(t) fmt.Println(verified)
Output: true false
func Pay ¶
func Pay(private crypto.PrivKey, recipient peer.ID, amount uint64) *Transaction
func (*Transaction) GetCorpus ¶
func (t *Transaction) GetCorpus() *bytes.Buffer
func (*Transaction) String ¶
func (t *Transaction) String() string
func (*Transaction) Verify ¶
func (t *Transaction) Verify() (result bool, err error)
type Transactions ¶
type Transactions []Transaction
type Unit ¶
type Unit struct { Signable Hash string Signer string Sign []byte PublicKey []byte TimeStamp int64 }
Basic Unit that can be presented in blockchain All fields should be public to be (de)serialize
func (*Unit) GetPublicKey ¶
func (*Unit) GetTimestamp ¶
Click to show internal directories.
Click to hide internal directories.