Documentation
¶
Index ¶
- Constants
- func BlockFromJson(r []byte) (b block, e error)
- func CalculateMerkleRoot(hashList []string) (root string)
- type Blockchain
- type Transaction
- func (t *Transaction) AddressFrom() uint64
- func (t *Transaction) AddressTo() uint64
- func (t *Transaction) CalculateHash() string
- func (t *Transaction) CheckHash(inputHash string) bool
- func (t *Transaction) Fee() float64
- func (t *Transaction) GetSign() []byte
- func (t *Transaction) Quantity() float64
- func (t *Transaction) Sign(privateKey *rsa.PrivateKey) (e error)
- func (t *Transaction) Stringify() (s string)
- func (t *Transaction) ToJson() ([]byte, error)
- func (t *Transaction) Verify(publicKey *rsa.PublicKey) error
- type Wallet
- func (w *Wallet) Address() []byte
- func (w *Wallet) Balance() float64
- func (w *Wallet) PrivateKey() *rsa.PrivateKey
- func (w *Wallet) PublicKey() *rsa.PublicKey
- func (w *Wallet) SendTransaction(amount float64, address uint64)
- func (w *Wallet) SetAddress(address []byte)
- func (w *Wallet) SetBalance(balance float64)
- func (w *Wallet) SetPrivateKey(privateKey *rsa.PrivateKey)
- func (w *Wallet) SetPublicKey(publicKey *rsa.PublicKey)
- func (w *Wallet) Unlock(pk uint64)
Constants ¶
const REDIS_PATH = "localhost"
const REDIS_PORT = "6379"
const SEED_SIZE = 512 //bytes
const WALLET_FOLDER = ".ncoin"
Variables ¶
This section is empty.
Functions ¶
func BlockFromJson ¶
func CalculateMerkleRoot ¶
Types ¶
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain struct contains all blockchain blocks and reference to last block
func (*Blockchain) AddBlock ¶
func (b *Blockchain) AddBlock(n block)
AddBlock function appends new block to the blockchain and reference that block as lastBlock.
func (*Blockchain) GetMerkleTreeRoot ¶
func (b *Blockchain) GetMerkleTreeRoot() (hash string)
GetMerkleTreeRoot function iterates over whole blockchain blocks and generates its hash. Then combines that hash and returns the root of blcks hash Merkle Tree.
func (*Blockchain) Load ¶
func (b *Blockchain) Load()
func (*Blockchain) Store ¶
func (b *Blockchain) Store()
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction struct contains all the attributes necessary for one transaction of the blockchain.
func NewTransaction ¶
func NewTransaction(addressTo uint64, addressFrom uint64, quantity float64, fee float64) Transaction
NewTransaction its a constructor for a new Transaction struct, receive all the attribute of the Transaction except the sign
func TransactionFromJson ¶
func TransactionFromJson(r []byte) (t *Transaction, e error)
func (*Transaction) AddressFrom ¶
func (t *Transaction) AddressFrom() uint64
AddressFrom its the getter for the addressFrom attribute
func (*Transaction) AddressTo ¶
func (t *Transaction) AddressTo() uint64
AddressTo its the getter for the addressTo attribute
func (*Transaction) CalculateHash ¶
func (t *Transaction) CalculateHash() string
func (*Transaction) CheckHash ¶
func (t *Transaction) CheckHash(inputHash string) bool
func (*Transaction) Fee ¶
func (t *Transaction) Fee() float64
Fee its the getter for the Fee attribute
func (*Transaction) GetSign ¶
func (t *Transaction) GetSign() []byte
GetSign its the getter for the sign attribute
func (*Transaction) Quantity ¶
func (t *Transaction) Quantity() float64
Quantity its the getter for the quantity attribute
func (*Transaction) Sign ¶
func (t *Transaction) Sign(privateKey *rsa.PrivateKey) (e error)
func (*Transaction) Stringify ¶
func (t *Transaction) Stringify() (s string)
Stringify return the Transaction in string format
func (*Transaction) ToJson ¶
func (t *Transaction) ToJson() ([]byte, error)
type Wallet ¶
type Wallet struct {
// contains filtered or unexported fields
}
Cartera
func (*Wallet) PrivateKey ¶
func (w *Wallet) PrivateKey() *rsa.PrivateKey
Devuelve la private_key de la cartera.
func (*Wallet) SendTransaction ¶
Envía la cantidad de NCoin indicada a la dirección indicada. Requiere candidad y dirección como parámetros .
func (*Wallet) SetAddress ¶
func (*Wallet) SetBalance ¶
func (*Wallet) SetPrivateKey ¶
func (w *Wallet) SetPrivateKey(privateKey *rsa.PrivateKey)