blockchain

package
v0.0.0-...-d1a1a8e Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COMMAND_CUSTOM_GET_INFO = iota
	COMMAND_CUSTOM_NEW_TRANSACTION
	COMMAND_CUSTOM_NEW_BLOCK
)
View Source
const (
	HASH_SIZE   = 256
	BUCKET_SIZE = HASH_SIZE / 8
)

Variables

View Source
var EXPECTED_10_BLOCKS_TIME int64 = 600

Functions

func GetWallets

func GetWallets(bc *Blockchain) error

func HasDoubleSpend

func HasDoubleSpend(transactions []Transaction) bool

func LoadStoredHeaders

func LoadStoredHeaders(bc *Blockchain) error

1000 headers by files

func LoadUnspent

func LoadUnspent(bc *Blockchain) error

func NewHash

func NewHash(val []byte) []byte

func NewRandomHash

func NewRandomHash() []byte

func SanitizePubKey

func SanitizePubKey(pub []byte) string

func SetupStorage

func SetupStorage(bc *Blockchain) error

func StoreLastHeaders

func StoreLastHeaders(bc *Blockchain) error

func StoreUnspent

func StoreUnspent(bc *Blockchain) error

Types

type Block

type Block struct {
	Header       BlockHeader
	Transactions []Transaction
}

func NewBlock

func NewBlock(bc *Blockchain) *Block

func OriginBlock

func OriginBlock(bc *Blockchain) *Block

func (*Block) Mine

func (this *Block) Mine(stats *Stats, mustStop *bool)

func (*Block) Verify

func (this *Block) Verify(bc *Blockchain) bool

func (*Block) VerifyOld

func (this *Block) VerifyOld(bc *Blockchain) bool

type BlockHeader

type BlockHeader struct {
	Height     int64
	Hash       []byte
	PrecHash   []byte
	MerkelHash []byte
	Target     []byte
	Timestamp  int64
	Nonce      int64
}

type Blockchain

type Blockchain struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(options BlockchainOptions) *Blockchain

func (*Blockchain) AddBlock

func (this *Blockchain) AddBlock(block *Block) bool

func (*Blockchain) AddTransationToWaiting

func (this *Blockchain) AddTransationToWaiting(tx *Transaction) bool

func (*Blockchain) AreHeadersGood

func (this *Blockchain) AreHeadersGood() bool

func (*Blockchain) BlocksHeight

func (this *Blockchain) BlocksHeight() int64

func (*Blockchain) Difficulty

func (this *Blockchain) Difficulty() int64

func (*Blockchain) Dispatch

func (this *Blockchain) Dispatch(cmd *dht.Custom) interface{}

func (*Blockchain) GetAvailableFunds

func (this *Blockchain) GetAvailableFunds(wallet []byte) int

func (*Blockchain) GetConnectedNodesNb

func (this *Blockchain) GetConnectedNodesNb() int

func (*Blockchain) GetEnoughOwnUnspentOut

func (this *Blockchain) GetEnoughOwnUnspentOut(value int) []UnspentTxOut

func (*Blockchain) GetInOutFromUnspent

func (this *Blockchain) GetInOutFromUnspent(value int, destWallet []byte, outs []UnspentTxOut) ([]TxIn, []TxOut)

Used to create a transaction without loss

func (*Blockchain) GetOwnHistory

func (this *Blockchain) GetOwnHistory() []HistoryTx

func (*Blockchain) GetOwnWaitingTx

func (this *Blockchain) GetOwnWaitingTx() []HistoryTx

func (*Blockchain) Init

func (this *Blockchain) Init()

func (*Blockchain) Logger

func (this *Blockchain) Logger() *logging.Logger

func (*Blockchain) Mine

func (this *Blockchain) Mine()

func (*Blockchain) NextDifficulty

func (this *Blockchain) NextDifficulty() int64

func (*Blockchain) ProcessingTransactionCount

func (this *Blockchain) ProcessingTransactionCount() int

func (*Blockchain) RemovePendingTransaction

func (this *Blockchain) RemovePendingTransaction(insTx []Transaction)

func (*Blockchain) RemoveUnspentOut

func (this *Blockchain) RemoveUnspentOut(wallet []byte, out *UnspentTxOut)

func (*Blockchain) Running

func (this *Blockchain) Running() bool

func (*Blockchain) SendTo

func (this *Blockchain) SendTo(value string) error

func (*Blockchain) ShowWallets

func (this *Blockchain) ShowWallets()

func (*Blockchain) Start

func (this *Blockchain) Start() error

func (*Blockchain) Stats

func (this *Blockchain) Stats() *Stats

func (*Blockchain) StatsLoop

func (this *Blockchain) StatsLoop()

func (*Blockchain) Stop

func (this *Blockchain) Stop()

func (*Blockchain) StoredKeys

func (this *Blockchain) StoredKeys() int

func (*Blockchain) Sync

func (this *Blockchain) Sync()

func (*Blockchain) Synced

func (this *Blockchain) Synced() bool

func (*Blockchain) TimeSinceLastBlock

func (this *Blockchain) TimeSinceLastBlock() int64

func (*Blockchain) UpdateUnspentTxOuts

func (this *Blockchain) UpdateUnspentTxOuts(block *Block)

func (*Blockchain) Wait

func (this *Blockchain) Wait()

func (*Blockchain) WaitingTransactionCount

func (this *Blockchain) WaitingTransactionCount() int

func (*Blockchain) Wallets

func (this *Blockchain) Wallets() map[string]*Wallet

type BlockchainOptions

type BlockchainOptions struct {
	BootstrapAddr string
	ListenAddr    string
	Folder        string
	Send          string
	Interactif    bool
	Wallets       bool
	Stats         bool
	Verbose       int
	Mine          bool
	NoGui         bool
	Cluster       int
}

type HistoryTx

type HistoryTx struct {
	Address   string `json:"address"`
	Timestamp int64  `json:"timestamp"`
	Amount    int    `json:"amount"`
}

type Stamp

type Stamp struct {
	R         []byte
	S         []byte
	Pub       []byte
	Hash      []byte
	Timestamp int64
}

type Stats

type Stats struct {
	HashesPerSecAvg int
	HashesPerSec    []int
	// contains filtered or unexported fields
}

func (*Stats) Update

func (this *Stats) Update()

type Transaction

type Transaction struct {
	Ins   []TxIn
	Outs  []TxOut
	Stamp Stamp
}

func NewCoinBaseTransaction

func NewCoinBaseTransaction(bc *Blockchain) *Transaction

func NewTransaction

func NewTransaction(value int, dest []byte, bc *Blockchain) *Transaction

func (*Transaction) Verify

func (this *Transaction) Verify(bc *Blockchain) bool

type TxIn

type TxIn struct {
	PrevHash []byte
	PrevIdx  int
}

type TxOut

type TxOut struct {
	Value   int
	Address []byte
}

type UnspentTxOut

type UnspentTxOut struct {
	Out        TxOut
	TxHash     []byte
	InIdx      int
	IsTargeted bool
}

type Wallet

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

func CreateWallet

func CreateWallet(name string, bc *Blockchain) (*Wallet, error)

func (*Wallet) Name

func (this *Wallet) Name() string

func (*Wallet) Pub

func (this *Wallet) Pub() []byte

Jump to

Keyboard shortcuts

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