block

package
v0.0.0-...-cec0596 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

utxo数据库创建的意义在于,不会每次进行转帐时遍历整个区块链, 而是去utxo数据库查找未消费的交易输出,这样会大大降低性能问题

Index

Constants

View Source
const ADDR_LIST_KEY = "addressList"

钱包地址在数据库中的键

View Source
const CHECKSUM = 4

两次sha256(公钥hash)后截取的字节数量

View Source
const DEATH_PUNISHMENT = 200

death in a duel delays agent movement for this value in millisecond. 1 second = 1000 millisecond

View Source
const GENESIS_SEED int64 = 8601066706715

random seed used in genesis block

View Source
const LATEST_BLOCK_HASH_KEY = "lastHash"

最新区块Hash在数据库中的键

View Source
const MAXINT = math.MaxInt64

随机数不能超过的最大值

View Source
const REWARD_ADDR_KEY = "rewardAddress"

奖励地址在数据库中的键

View Source
const VERSION = byte(0x00)

公链版本信息默认为0

Variables

View Source
var LISTEN_PORT string

当前本地监听端口

View Source
var MNWORD_PATH string

中文助记词地址

View Source
var NEWEST_BLOCK_HEIGHT int

当前节点发现的网络中最新区块高度

View Source
var NEWEST_BLOCK_KILL uint64

当前节点发现的网络中最新区块高度

View Source
var REWARD_AMOUNT int

挖矿奖励代币数量

View Source
var ROUND_BIT uint64

determine how many rounds of duel must be faught

View Source
var VERIFY_BIT uint64

Functions

func CreateBitcoinKeysByMnemonicWord

func CreateBitcoinKeysByMnemonicWord(mnemonicWord []string) *bitcoinKeys

根据助记词创建公私钥

func GetAddressFromPublicKey

func GetAddressFromPublicKey(publickey []byte) string

通过公钥信息获得地址

func GetAddressFromPublicKeyHash

func GetAddressFromPublicKeyHash(publickeyHash []byte) string

通过公钥信息获得地址

func GetAllAddress

func GetAllAddress(bd *database.BlockchainDB) *addressList

获取全部地址信息

func IsVaildBitcoinAddress

func IsVaildBitcoinAddress(address string) bool

判断是否是有效的比特币地址

func NewBitcoinKeys

func NewBitcoinKeys(nothing []string) *bitcoinKeys

创建公私钥实例

func NewBlockchain

func NewBlockchain() *blockchain

创建区块链实例

func NewBlockchainIterator

func NewBlockchainIterator(bc *blockchain) *blockchainIterator

获取区块迭代器实例

func NewProofOfKill

func NewProofOfKill(block *Block) *proofOfKill

return PoK instance

func NewProofOfWork

func NewProofOfWork(block *Block) *proofOfWork

获取POW实例

func NewWallets

func NewWallets(bd *database.BlockchainDB) *wallets

创建一个新钱包实例

Types

type Block

type Block struct {
	//hash of the provious block
	PreHash      []byte
	Transactions []Transaction
	TimeStamp    int64
	Height       int
	//hash of this block
	Hash []byte
	//for verification
	Agent agent.Agent
	//recording wins or loses for mining fights
	Proof []bool
	//how many kills this block includes
	Kill uint64
}

func (*Block) Deserialize

func (v *Block) Deserialize(d []byte)

func (*Block) Serialize

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

将Block对象序列化成[]byte

type Sender

type Sender interface {
	SendVersionToPeers(height int, kill uint64)
	SendTransToPeers(tss []Transaction)
}

用于network包向对等节点发送信息

type TXInput

type TXInput struct {
	TxHash    []byte
	Index     int
	Signature []byte
	PublicKey []byte
}

UTXO输入

type TXOutput

type TXOutput struct {
	Value         int
	PublicKeyHash []byte
}

UTXO输出

type Transaction

type Transaction struct {
	TxHash []byte
	Vint   []TXInput
	Vout   []TXOutput
	Agent  agent.Agent
}

交易列表信息

func (*Transaction) Serialize

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

将transaction序列化成[]byte

type UTXO

type UTXO struct {
	Hash  []byte
	Index int
	Vout  TXOutput
}

UTXO输出的详细信息,便于直接在utxo数据库查找输出

type UTXOHandle

type UTXOHandle struct {
	BC *blockchain
}

func (*UTXOHandle) ResetUTXODataBase

func (u *UTXOHandle) ResetUTXODataBase()

重置UTXO数据库

func (*UTXOHandle) Synchrodata

func (u *UTXOHandle) Synchrodata(tss []Transaction)

传入交易信息,将交易里的输出添加进utxo数据库,并剔除输入信息

Jump to

Keyboard shortcuts

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