Documentation
¶
Index ¶
- Constants
- Variables
- func Base58Decode(input []byte) []byte
- func Base58Encode(input []byte) []byte
- func HashPublicKey(publicKey []byte) []byte
- func SignTransaction(c *BlockChain, tran *Transaction, privateKey ecdsa.PrivateKey)
- func ValidateAddress(address string) bool
- func VerifyTransaction(c *BlockChain, tran *Transaction) bool
- type Block
- type BlockChain
- type BlockChainIterator
- type BlockData
- type BlockHeader
- type ChainState
- type Config
- type Input
- type MerkleNode
- type MerkleTree
- type Output
- type POW
- type Transaction
- func (tx *Transaction) Hash()
- func (tx *Transaction) IsCoinBase() bool
- func (tx *Transaction) Serialize() []byte
- func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTrans map[string]*Transaction)
- func (tx *Transaction) TrimmedCopy() *Transaction
- func (tx *Transaction) Verify(prevTrans map[string]*Transaction) bool
- type TransactionContainer
- type Wallet
- type WalletManager
Constants ¶
View Source
const ( Version = byte(0x00) AddressChecksumLen = 4 )
Variables ¶
View Source
var (
RewardAmount uint64 = 50
)
Functions ¶
func Base58Encode ¶
Base58Encode encodes a byte array to Base58
func HashPublicKey ¶
func SignTransaction ¶
func SignTransaction(c *BlockChain, tran *Transaction, privateKey ecdsa.PrivateKey)
func ValidateAddress ¶
func VerifyTransaction ¶
func VerifyTransaction(c *BlockChain, tran *Transaction) bool
Types ¶
type Block ¶
type Block struct {
Header BlockHeader
Body BlockData
}
func DeserializeBlock ¶
func NewGenesisBlock ¶
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 BlockHeader ¶
type ChainState ¶
type ChainState struct {
BlockChain *BlockChain
}
func (ChainState) FindSpendableOutputs ¶
func (s ChainState) FindSpendableOutputs(publicKeyHash []byte) (uint64, []Output)
func (ChainState) FindSpendableOutputsMapping ¶
func (ChainState) Reindex ¶
func (s ChainState) Reindex() error
func (ChainState) Update ¶
func (s ChainState) Update(block *Block)
type Input ¶
type Input struct {
TransactionID []byte
OutputIndex int
Signature []byte
PublicKey []byte
ScriptSig string
}
func (*Input) IsLockedWithKey ¶
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 ¶
func (*Output) IsLockedWithKey ¶
type Transaction ¶
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 (Wallet) GetAddress ¶
type WalletManager ¶
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()
Click to show internal directories.
Click to hide internal directories.