Documentation ¶
Index ¶
- Constants
- func Base58Decode(input []byte) []byte
- func Base58Encode(input []byte) []byte
- func CheckSum(bytes []byte) []byte
- func IntToHex(num int64) []byte
- func IsDBExists(dbName string) bool
- func IsValidForAddress(address []byte) bool
- func Json2Array(jsonString string) []string
- func ReverseBytes(data []byte)
- func Ripemd160Hash(publicKey []byte) []byte
- func StartServer(nodeID string, minerAdd string)
- type Block
- type BlockData
- type Blockchain
- func (blc *Blockchain) AddBlock(block *Block) error
- func (blc *Blockchain) FindSpendableUTXOs(address string, amount int, txs []*Transaction) (int64, map[string][]int)
- func (blc *Blockchain) FindTransaction(TxHash []byte, txs []*Transaction) (Transaction, error)
- func (blc *Blockchain) FindUTXOMap() map[string]*TXOutputs
- func (blc *Blockchain) GetBalance(address string) int64
- func (blc *Blockchain) GetBestHeight() int64
- func (blc *Blockchain) GetBlock(bHash []byte) ([]byte, error)
- func (blc *Blockchain) GetBlockHashes() [][]byte
- func (blc *Blockchain) Iterator() *BlockchainIterator
- func (blc *Blockchain) MineNewBlock(from []string, to []string, amount []string, nodeID string) *Block
- func (blc *Blockchain) Printchain()
- func (blc *Blockchain) SignTransaction(tx *Transaction, privKey ecdsa.PrivateKey, txs []*Transaction)
- func (blc *Blockchain) UTXOs(address string, txs []*Transaction) []*UTXO
- func (blc *Blockchain) VerifyTransaction(tx *Transaction, txs []*Transaction) bool
- type BlockchainIterator
- type CLI
- type GetBlocks
- type GetData
- type Inv
- type MerkleNode
- type MerkleTree
- type ProofOfWork
- type TXInput
- type TXOutput
- type TXOutputs
- type Transaction
- func (tx *Transaction) Hash() []byte
- func (tx *Transaction) HashTransactions()
- func (tx *Transaction) IsCoinbaseTransaction() bool
- func (tx *Transaction) PrintTx()
- func (tx *Transaction) Serialize() []byte
- func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTxs map[string]Transaction)
- func (tx *Transaction) TrimmedCopy() Transaction
- func (tx *Transaction) Verify(prevTxs map[string]Transaction) bool
- type TxData
- type UTXO
- type UTXOSet
- func (utxoSet *UTXOSet) FindSpendableUTXOs(address string, amount int64, txs []*Transaction) (int64, map[string][]int)
- func (utxoSet *UTXOSet) FindUTXOsForAddress(address string) []*UTXO
- func (utxoSet *UTXOSet) FindUnPackageSpendableUTXOS(address string, txs []*Transaction) []*UTXO
- func (utxoSet *UTXOSet) GetBalance(address string) int64
- func (utxoSet *UTXOSet) ResetUTXOSet()
- func (utxoSet *UTXOSet) Update()
- type Version
- type Wallet
- type Wallets
Constants ¶
View Source
const AddVersion = byte(0x00)
用于生成地址的版本
View Source
const AddressChecksumLen = 4
用于生成地址的校验和位数
View Source
const BLOCK_TYPE = "block"
类型
View Source
const COMMANDLENGTH = 12
发送消息的前12个字节指定了命令名(version)
View Source
const COMMAND_ADDR = "addr"
View Source
const COMMAND_BLOCK = "block"
View Source
const COMMAND_GETBLOCKS = "getblocks"
View Source
const COMMAND_GETDATA = "getdata"
View Source
const COMMAND_INV = "inv"
View Source
const COMMAND_TX = "tx"
View Source
const COMMAND_VERSION = "version"
命令
View Source
const NODE_VERSION = 1
View Source
const PROTOCOL = "tcp"
View Source
const TX_TYPE = "tx"
View Source
const UTXOTableName = "UTXOTableName"
存储未花费交易输出的数据库表
View Source
const WalletFile = "Wallets_%s.dat"
存储钱包集的文件名
Variables ¶
This section is empty.
Functions ¶
func StartServer ¶
Types ¶
type Block ¶
type Block struct { //1.区块高度 Height int64 //2.上一个区块HAsh PrevBlockHash []byte //3.交易数据 Txs []*Transaction //4.时间戳 Timestamp int64 //5.Hash Hash []byte //6.Nonce 符合工作量证明的随机数 Nonce int64 }
type Blockchain ¶
func CreateBlockchainWithGensisBlock ¶
func CreateBlockchainWithGensisBlock(address string, nodeID string) *Blockchain
1.创建创世区块
func (*Blockchain) AddBlock ¶
func (blc *Blockchain) AddBlock(block *Block) error
func (*Blockchain) FindSpendableUTXOs ¶
func (blc *Blockchain) FindSpendableUTXOs(address string, amount int, txs []*Transaction) (int64, map[string][]int)
转账时查找可用的用于消费的UTXO
func (*Blockchain) FindTransaction ¶
func (blc *Blockchain) FindTransaction(TxHash []byte, txs []*Transaction) (Transaction, error)
获取某个交易
func (*Blockchain) FindUTXOMap ¶
func (blc *Blockchain) FindUTXOMap() map[string]*TXOutputs
查找未花费的UTXO[string]*TXOutputs 返回字典 键为所属交易的哈希,值为TXOutput数组
func (*Blockchain) GetBlock ¶
func (blc *Blockchain) GetBlock(bHash []byte) ([]byte, error)
获取对应哈希的区块
func (*Blockchain) Iterator ¶
func (blc *Blockchain) Iterator() *BlockchainIterator
func (*Blockchain) MineNewBlock ¶
func (blc *Blockchain) MineNewBlock(from []string, to []string, amount []string, nodeID string) *Block
2.新增一个区块到区块链 --> 包含交易的挖矿
func (*Blockchain) SignTransaction ¶
func (blc *Blockchain) SignTransaction(tx *Transaction, privKey ecdsa.PrivateKey, txs []*Transaction)
交易签名
func (*Blockchain) UTXOs ¶
func (blc *Blockchain) UTXOs(address string, txs []*Transaction) []*UTXO
5.返回一个地址对应的UTXO的交易UTXOs func (blc *Blockchain) UnSpentTransactionsWithAddress(address string) []*Transaction {
func (*Blockchain) VerifyTransaction ¶
func (blc *Blockchain) VerifyTransaction(tx *Transaction, txs []*Transaction) bool
交易验签
type BlockchainIterator ¶
区块链迭代器
func (*BlockchainIterator) Next ¶
func (blcIterator *BlockchainIterator) Next() *Block
type GetData ¶
type GetData struct { // 节点地址 AddrFrom string // 请求类型 是block还是tx Type string // 区块哈希或交易哈希 Hash []byte }
用于请求区块或交易
type MerkleNode ¶
type MerkleNode struct { //做节点 Left *MerkleNode //右节点 Right *MerkleNode //节点数据 Data []byte }
默克尔树节点
type ProofOfWork ¶
type ProofOfWork struct { //求工作量的block Block *Block // contains filtered or unexported fields }
type TXInput ¶
type TXInput struct { //交易ID TxHash []byte //存储TXOutput在Vouts里的索引 Vout int //数字签名 Signature []byte //公钥 PublicKey []byte }
func (*TXInput) UnlockWithAddress ¶
验证当前输入是否是当前地址的
type Transaction ¶
func DeserializeTransaction ¶
func DeserializeTransaction(data []byte) Transaction
func NewTransaction ¶
func NewTransaction(from string, to string, amount int64, utxoSet *UTXOSet, txs []*Transaction, nodeID string) *Transaction
2.普通交易
func (*Transaction) IsCoinbaseTransaction ¶
func (tx *Transaction) IsCoinbaseTransaction() bool
创币交易判断
func (*Transaction) PrintTx ¶
func (tx *Transaction) PrintTx()
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(privateKey ecdsa.PrivateKey, prevTxs map[string]Transaction)
数字签名
func (*Transaction) TrimmedCopy ¶
func (tx *Transaction) TrimmedCopy() Transaction
拷贝一份新的Transaction用于签名,包含所有的输入输出,但TXInput.Signature 和 TXIput.PubKey 被设置为 nil T
type UTXOSet ¶
type UTXOSet struct {
Blockchain *Blockchain
}
func (*UTXOSet) FindSpendableUTXOs ¶
func (utxoSet *UTXOSet) FindSpendableUTXOs(address string, amount int64, txs []*Transaction) (int64, map[string][]int)
转账时查找可用的用于消费的UTXO组合
func (*UTXOSet) FindUTXOsForAddress ¶
2.查询某个地址的UTXO
func (*UTXOSet) FindUnPackageSpendableUTXOS ¶
func (utxoSet *UTXOSet) FindUnPackageSpendableUTXOS(address string, txs []*Transaction) []*UTXO
返回要凑多少钱,对应TXOutput的TX的Hash和index ???Set本身就是UTXO集合,里面的不全是未花费吗????
type Wallet ¶
type Wallet struct { //私钥 PrivateKey ecdsa.PrivateKey //公钥 PublicKey []byte }
Source Files ¶
- Base58.go
- Block.go
- Blockchain.go
- BlockchainIterator.go
- Constant.go
- FUU.go
- FUU_StartNode.go
- FUU_creatBlockchain.go
- FUU_createWallet.go
- FUU_getAddrestList.go
- FUU_getBlance.go
- FUU_printchain.go
- FUU_send.go
- FUU_testMethod.go
- MerkleTree.go
- ProofOfwork.go
- Server.go
- Server_BlockData.go
- Server_GetBlocks.go
- Server_GetData.go
- Server_Handle.go
- Server_Inv.go
- Server_TxData.go
- Server_Version.go
- Server_send.go
- Server_var.go
- TXInput.go
- TXOutput.go
- TXOutputs.go
- Transaction.go
- UTXO.go
- UTXOSet.go
- Utils.go
- Wallet.go
- Wallets.go
Click to show internal directories.
Click to hide internal directories.