blockchain

package
v0.0.0-...-d1df423 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version            = byte(0x00)
	AddressChecksumLen = 4
)

Variables

View Source
var (
	RewardAmount uint64 = 50
)

Functions

func Base58Decode

func Base58Decode(input []byte) []byte

Base58Decode decodes Base58-encoded data

func Base58Encode

func Base58Encode(input []byte) []byte

Base58Encode encodes a byte array to Base58

func HashPublicKey

func HashPublicKey(publicKey []byte) []byte

func SignTransaction

func SignTransaction(c *BlockChain, tran *Transaction, privateKey ecdsa.PrivateKey)

func ValidateAddress

func ValidateAddress(address string) bool

func VerifyTransaction

func VerifyTransaction(c *BlockChain, tran *Transaction) bool

Types

type Block

type Block struct {
	Header BlockHeader
	Body   BlockData
}

func DeserializeBlock

func DeserializeBlock(data []byte) *Block

func NewBlock

func NewBlock(data []byte, prevBlockHash []byte, height uint64) *Block

func NewGenesisBlock

func NewGenesisBlock(to string, data string) *Block

func (*Block) Serialize

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

type BlockChain

type BlockChain struct {

	// 数据库连接
	DB *bolt.DB

	NewGenesisBlockFunc func(to string, data string) *Block
	// contains filtered or unexported fields
}
var GeneralChain *BlockChain

func InitBlockChain

func InitBlockChain(address string, config Config) *BlockChain

func NewBlockChain

func NewBlockChain(config Config) *BlockChain

func (*BlockChain) AddBlock

func (c *BlockChain) AddBlock(block *Block) (ok bool)

func (*BlockChain) GetBestHeight

func (c *BlockChain) GetBestHeight() uint64

func (*BlockChain) GetBlock

func (c *BlockChain) GetBlock(blockHash []byte) *Block

func (*BlockChain) Iterator

func (c *BlockChain) Iterator() *BlockChainIterator

func (*BlockChain) PackageBlock

func (c *BlockChain) PackageBlock(data []byte) *Block

type BlockChainIterator

type BlockChainIterator struct {
	// contains filtered or unexported fields
}

func (*BlockChainIterator) Next

func (it *BlockChainIterator) Next() *Block

type BlockData

type BlockData struct {
	Data []byte
}

type BlockHeader

type BlockHeader struct {
	PrevBlockHash []byte
	Hash          []byte
	Nonce         uint64
	Timestamp     uint64
	Height        uint64
}

type ChainState

type ChainState struct {
	BlockChain *BlockChain
}

func (ChainState) FindSpendableOutputs

func (s ChainState) FindSpendableOutputs(publicKeyHash []byte) (uint64, []Output)

func (ChainState) FindSpendableOutputsMapping

func (s ChainState) FindSpendableOutputsMapping(publicKeyHash []byte, amount uint64) (uint64, map[string][]int)

func (ChainState) Reindex

func (s ChainState) Reindex() error

func (ChainState) Update

func (s ChainState) Update(block *Block)

type Config

type Config struct {
	NewGenesisBlockFunc func(to string, data string) *Block
}

type Input

type Input struct {
	TransactionID []byte
	OutputIndex   int
	Signature     []byte
	PublicKey     []byte
	ScriptSig     string
}

func (*Input) IsLockedWithKey

func (in *Input) IsLockedWithKey(publicKeyHash []byte) bool

type MerkleNode

type MerkleNode struct {
	Left  *MerkleNode
	Right *MerkleNode
	Data  []byte
}

MerkleNode represent a Merkle tree node

func NewMerkleNode

func NewMerkleNode(left, right *MerkleNode, data []byte) *MerkleNode

NewMerkleNode creates a new Merkle tree node

type MerkleTree

type MerkleTree struct {
	RootNode *MerkleNode
}

MerkleTree represent a Merkle tree

func NewMerkleTree

func NewMerkleTree(data [][]byte) *MerkleTree

NewMerkleTree creates a new Merkle tree from a sequence of data

type Output

type Output struct {
	Amount        uint64
	PublicKeyHash []byte
	ScriptPubKey  string
}

func NewOutput

func NewOutput(amount uint64, address string) Output

func (*Output) IsLockedWithKey

func (out *Output) IsLockedWithKey(publicKeyHash []byte) bool

func (*Output) Lock

func (out *Output) Lock(address []byte)

type POW

type POW struct {
	// contains filtered or unexported fields
}

func NewPOW

func NewPOW(block *Block) *POW

func (*POW) Run

func (pow *POW) Run() (nonce uint64, hash []byte)

func (*POW) Validate

func (pow *POW) Validate() bool

type Transaction

type Transaction struct {
	ID      []byte
	Inputs  []Input
	Outputs []Output
}

func DeserializeTransaction

func DeserializeTransaction(data []byte) Transaction

func NewCoinbaseTransaction

func NewCoinbaseTransaction(to string, data string) Transaction

func NewTransaction

func NewTransaction(from, to string, amount uint64, c *BlockChain) Transaction

func (*Transaction) Hash

func (tx *Transaction) Hash()

func (*Transaction) IsCoinBase

func (tx *Transaction) IsCoinBase() bool

func (*Transaction) Serialize

func (tx *Transaction) Serialize() []byte

func (*Transaction) Sign

func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTrans map[string]*Transaction)

func (*Transaction) TrimmedCopy

func (tx *Transaction) TrimmedCopy() *Transaction

func (*Transaction) Verify

func (tx *Transaction) Verify(prevTrans map[string]*Transaction) bool

type TransactionContainer

type TransactionContainer []Transaction

func DeserializeTransactionContainer

func DeserializeTransactionContainer(data []byte) TransactionContainer

func (TransactionContainer) Hash

func (trans TransactionContainer) Hash() []byte

func (TransactionContainer) Serialize

func (trans TransactionContainer) Serialize() []byte

type Wallet

type Wallet struct {
	Alias      string
	PrivateKey ecdsa.PrivateKey
	PublicKey  []byte
}

func NewWallet

func NewWallet(alias string) *Wallet

func (Wallet) GetAddress

func (w Wallet) GetAddress() []byte

type WalletManager

type WalletManager struct {
	W map[string]*Wallet
}

func NewWalletManager

func NewWalletManager() (*WalletManager, error)

func (*WalletManager) CreateWallet

func (w *WalletManager) CreateWallet(alias string) string

func (*WalletManager) GetAddress

func (w *WalletManager) GetAddress() []string

func (*WalletManager) GetWallet

func (w *WalletManager) GetWallet(address string) *Wallet

func (*WalletManager) LoadFromFile

func (w *WalletManager) LoadFromFile() error

func (*WalletManager) SaveToFile

func (w *WalletManager) SaveToFile()

Jump to

Keyboard shortcuts

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