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
)
Variables ¶
This section is empty.
Functions ¶
func Base64Decode ¶
func Base64Encode ¶
func GeneratePrivate ¶
func GeneratePrivate(bits uint) *rsa.PrivateKey
func GenerateRandomBytes ¶
func ParsePrivate ¶
func ParsePrivate(privData string) *rsa.PrivateKey
func ParsePublic ¶
func SerializeBlock ¶
func SerializeTX ¶
func SerializeTX(tx *Transaction) string
func StringPrivate ¶
func StringPrivate(priv *rsa.PrivateKey) string
func StringPublic ¶
Types ¶
type Block ¶
type Block struct { Nonce uint64 Difficulty uint8 CurrHash []byte PrevHash []byte Transactions []Transaction Mapping map[string]uint64 Miner string Signature []byte TimeStamp string }
func DeserializeBlock ¶
func (*Block) Accept ¶
func (block *Block) Accept(chain *BlockChain, user *User, ch chan bool) error
func (*Block) AddTransaction ¶
func (block *Block) AddTransaction(chain *BlockChain, tx *Transaction) error
type BlockChain ¶
func LoadChain ¶
func LoadChain(filename string) *BlockChain
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(block *Block)
func (*BlockChain) LastHash ¶
func (chain *BlockChain) LastHash() []byte
func (*BlockChain) Size ¶
func (chain *BlockChain) Size() uint64
type Transaction ¶
type Transaction struct { RandBytes []byte PrevBlock []byte Sender string Receiver string Value uint64 ToStorage uint64 CurrHash []byte Signature []byte }
func DeserializeTX ¶
func DeserializeTX(data string) *Transaction
func NewTransaction ¶
func NewTransaction(user *User, lasthash []byte, to string, value uint64) *Transaction
type User ¶
type User struct {
PrivateKey *rsa.PrivateKey
}
func (*User) Private ¶
func (user *User) Private() *rsa.PrivateKey
Click to show internal directories.
Click to hide internal directories.