Documentation ¶
Index ¶
- Constants
- Variables
- func ArgsHaveOption(long, short string) (hasOption bool, foundAt int)
- func CheckSignature(signature, pubkey, message string) (bool, error)
- func DBInit()
- func DoubleShasumBytes(record []byte) []byte
- func EmojiToBytes(emoji string) ([addrBytesLen]byte, error)
- func GetAllBalances() map[Address]uint64
- func GetAllBalancesFloats() map[Address]float64
- func GetBalanceByAddr(addr Address) (uint64, error)
- func GetTarget(difficulty uint64) *big.Int
- func IsHashValid(hash string, target *big.Int) bool
- func IsHashValidBytes(hash []byte, target *big.Int) bool
- func IsValid(newBlock, oldBlock *Sblock, target *big.Int) error
- func IsValidBase64(s string) bool
- func IsValidNoCheckDB(newBlock, oldBlock *Sblock, target *big.Int) error
- func MakeKeyPair() (pub, priv string, err error)
- func MakeSignature(privkey, message string) (string, error)
- func SaveKeyPair(pubkey, privkey, pubfile, privfile string) error
- func TextToBytes(text string) ([addrBytesLen]byte, error)
- func ToJSON(v interface{}) string
- func WriteBlockDB(blks ...*Sblock)
- type Address
- func BytesToAddress(b [addrBytesLen]byte) Address
- func EmojiOrTextToAddress(addr string) (Address, error)
- func EmojiToAddress(emoji string) (Address, error)
- func KeyToAddress(key string) Address
- func LoadKeysAndAddr(pubfile, privfile string) (pub, priv string, addr Address, err error)
- func TextToAddress(text string) (Address, error)
- type Lblock
- type Sblock
- type Transaction
Constants ¶
const ( // MicroquacksPerDuck is the number of microquacks equal to one duck. // A microquack is a billionth of a quack, which is a hundredth of a duck. MicroquacksPerDuck uint64 = 1e8 )
Variables ¶
var (
Reward uint64 = 1e6
)
Functions ¶
func ArgsHaveOption ¶
ArgsHaveOption checks command line arguments for an option
func CheckSignature ¶
CheckSignature checks if signature decodes to message using pubkey. This is useful in verifying identities.
func DoubleShasumBytes ¶
DoubleShasumBytes returns sha256(sha256(record))
func EmojiToBytes ¶
func GetAllBalances ¶
GetAllBalances returns a map of addresses to the balance in microquacks
func GetAllBalancesFloats ¶
GetAllBalancesFloats returns a map of addresses to the balance in ducks
func GetBalanceByAddr ¶
func GetTarget ¶
GetTarget returns a "target" which block hashes must be lower than to be valid. This is calculated such that miners will need to compute difficulty hashes on average for a valid hash.
func IsHashValid ¶
IsHashValid checks if a hash is a valid block hash
func IsHashValidBytes ¶
IsHashValidBytes checks if a hash is a valid block hash
func IsValidBase64 ¶
IsValidBase64 checks if a string is valid base64
func MakeKeyPair ¶
MakeKeyPair creates a new public and private key pair
func MakeSignature ¶
MakeSignature signs a message with a private key.
func SaveKeyPair ¶
SaveKeyPair saves a key pair using the PEM format
func TextToBytes ¶
func ToJSON ¶
func ToJSON(v interface{}) string
ToJSON is a convenience method for serializing to JSON.
func WriteBlockDB ¶
func WriteBlockDB(blks ...*Sblock)
Types ¶
type Address ¶
type Address struct { Emoji string `json:",omitempty"` Text string `json:",omitempty"` // contains filtered or unexported fields }
func BytesToAddress ¶
func EmojiOrTextToAddress ¶
func EmojiToAddress ¶
func KeyToAddress ¶
KeyToAddress derives a Duckcoin Address from a Duckcoin Public Key
func LoadKeysAndAddr ¶
func TextToAddress ¶
func (*Address) IsValid ¶
IsValid verifies the checksum built into addresses, and checks the address format
func (*Address) UnmarshalJSON ¶
type Lblock ¶
type Lblock struct { // Index is the Lblock number Index uint64 // Timestamp is the Unix timestamp in milliseconds of the date of creation of this Lblock Timestamp uint64 // Data stores any (arbitrary) additional data <= 250 kb long. Data string // Hash stores the hash of this Lblock as computed by CalculateHash Hash string // PrevHash is the hash of the previous Lblock PrevHash string // Solution is the nonce value that makes the Hash be under some target value Solution uint64 // Solver is the address of the sender. Address format: Q + version char + base64(shasum(pubkey)[:20]) Solver Address `json:",omitempty"` // Sblocks contains the Sblocks part of this Lblock Sblocks []*Sblock }
func (*Lblock) CalculateHash ¶
CalculateHash calculates the hash of an Lblock.
func (*Lblock) CalculateHashBytes ¶
CalculateHashBytes calculates the hash of an Lblock.
func (*Lblock) PreimageWOSolution ¶
type Sblock ¶
type Sblock struct { // Index is the Sblock number Index uint64 // Timestamp is the Unix timestamp in milliseconds of the date of creation of this Sblock Timestamp uint64 // Data stores any (arbitrary) additional data <= 250 kb long. Data string // Hash stores the hash of this Sblock as computed by CalculateHash Hash string // PrevHash is the hash of the previous Sblock PrevHash string // Solution is the nonce value that makes the Hash be under some target value Solution uint64 // Solver is the address of the sender. Address format: Q + version char + base64(shasum(pubkey)[:20]) Solver Address `json:",omitempty"` Tx Transaction `json:",omitempty"` }
An Sblock is one block in the chain of some Lnode. It optionally contains a transaction and arbitrary data.
func GetNewestSblock ¶
func GetSblockByHash ¶
func GetSblockByIndex ¶
func (*Sblock) CalculateHash ¶
CalculateHash calculates the hash of a Sblock.
func (*Sblock) CalculateHashBytes ¶
CalculateHashBytes calculates the hash of a Sblock.
func (*Sblock) PreimageWOSolution ¶
PreimageWOSolution returns the data to be hashed to create the hash of an Sblock, but without the Solution field taken into account. This is useful when mining.
type Transaction ¶
type Transaction struct { // Data is any (arbitrary) additional data <= 250 kb long. Data string `json:",omitempty"` // Sender is the address of the sender. Sender Address `json:",omitempty"` // Receiver is the address of the receiver. Receiver Address `json:",omitempty"` // Amount is the amount to be payed by the Sender to the Receiver. It is always a positive number. Amount uint64 `json:",omitempty"` // PubKey is the Duckcoin formatted public key of the sender PubKey string `json:",omitempty"` // Signature is a base64 encoded cryptographic signature that uses the hash of the Sblock // as the data encrypted by the private key to prevent replay attacks Signature string `json:",omitempty"` }
A Transaction is a transfer of any amount of duckcoin from one address to another.