Documentation ¶
Index ¶
- Constants
- func Base64Decode(data string) []byte
- func Base64Encode(data []byte) string
- func GeneratePrivate(bits uint) *rsa.PrivateKey
- func GenerateRandomBytes(max uint) []byte
- func HashSum(data []byte) []byte
- func NewChain(filename, receiver string) error
- func ParsePrivate(privData string) *rsa.PrivateKey
- func ParsePublic(pubData string) *rsa.PublicKey
- func ProofOfWork(blockHash []byte, difficulty uint8, ch chan bool) uint64
- func SerializeBlock(block *Block) string
- func SerializeTX(tx *Transaction) string
- func Sign(priv *rsa.PrivateKey, data []byte) []byte
- func StringPrivate(priv *rsa.PrivateKey) string
- func StringPublic(pub *rsa.PublicKey) string
- func ToBytes(num uint64) []byte
- func Verify(pub *rsa.PublicKey, data, sign []byte) error
- type Block
- type BlockChain
- type Transaction
- type User
Constants ¶
View Source
const ( GENESIS_BLOCK = "GENESIS-BLOCK" STORAGE_VALUE = 100 GENESIS_REWARD = 100 STORAGE_CHAIN = "STORAGE-CHAIN" )
View Source
const ( RAND_BYTES = 32 START_PERCENT = 10 STORAGE_REWARD = 1 )
View Source
const (
CREATE_TABLE = `
CREATE TABLE BlockChain (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Hash VARCHAR(44) UNIQUE,
Block TEXT
);
`
)
View Source
const (
DEBUG = true
)
View Source
const (
DIFFICULTY = 20
)
View Source
const (
KEY_SIZE = 512
)
View Source
const (
TXS_LIMIT = 2 // Defines the maximum number of transactions in one block.
)
Variables ¶
This section is empty.
Functions ¶
func Base64Decode ¶
func Base64Encode ¶
func GeneratePrivate ¶
func GeneratePrivate(bits uint) *rsa.PrivateKey
func GenerateRandomBytes ¶
Returns a slice of pseudo-random bytes //
func ParsePrivate ¶
func ParsePrivate(privData string) *rsa.PrivateKey
func ParsePublic ¶
func SerializeBlock ¶
func SerializeTX ¶
func SerializeTX(tx *Transaction) string
func Sign ¶
func Sign(priv *rsa.PrivateKey, data []byte) []byte
Signs the data based on the private key //
func StringPrivate ¶
func StringPrivate(priv *rsa.PrivateKey) string
func StringPublic ¶
Translates the public key into a set of bytes, then applies base64 encoding to translate to a string //
Types ¶
type Block ¶
type Block struct { Nonce uint64 // Confirmation result Difficulty uint8 // Block difficulty CurrHash []byte // Hash of current block PrevHash []byte // Hash of previous block Transactions []Transaction // User Transaction Mapping map[string]uint64 // User Balance Miner string // User who mined block Signature []byte // Miner signature pointing to CurrHash TimeStamp string // TimeStamp of block creation }
func DeserializeBlock ¶
func (*Block) Accept ¶
func (block *Block) Accept(chain *BlockChain, user *User, ch chan bool) error
After placing all transactions in a block, it must be confirmed //
func (*Block) AddTransaction ¶
func (block *Block) AddTransaction(chain *BlockChain, tx *Transaction) error
Adding a transaction to the block //
type BlockChain ¶
type BlockChain struct {
DB *sql.DB // Pointer to the database to add to and from which takes blocks
}
func LoadChain ¶
func LoadChain(filename string) *BlockChain
Load function to use the already created blockchain//
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(block *Block)
Adding new block in DB //
func (*BlockChain) Balance ¶
func (chain *BlockChain) Balance(address string, size uint64) uint64
User balance //
func (*BlockChain) LastHash ¶
func (chain *BlockChain) LastHash() []byte
func (*BlockChain) Size ¶
func (chain *BlockChain) Size() uint64
Returns the number of blocks in the local database //
type Transaction ¶
type Transaction struct { RandBytes []byte // Random bytes PrevBlock []byte // Hash of last block Sender string // Sender's name Receiver string // Receiver's name Value uint64 // The amount of money transferred to the receiver ToStorage uint64 // The amount of money transferred to the storage CurrHash []byte // Current transaction hash Signature []byte // Sender's signature }
func DeserializeTX ¶
func DeserializeTX(data string) *Transaction
func NewTransaction ¶
func NewTransaction(user *User, lasthash []byte, to string, value uint64) *Transaction
After creating a block, user transactions need to be entered into it //
type User ¶
type User struct {
PrivateKey *rsa.PrivateKey // Private Key of User
}
func (*User) Private ¶
func (user *User) Private() *rsa.PrivateKey
Click to show internal directories.
Click to hide internal directories.