Documentation ¶
Index ¶
- Constants
- func Decode(encodedData []byte, sliceSize int) (data [][]byte)
- func Encode(data [][]byte, sliceSize int) []byte
- func RandomBytes() []byte
- func RandomBytesWithLength(length int) []byte
- func SerializeHashContent(data interface{}) (hash [32]byte)
- type AccTx
- func (tx *AccTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
- func (*AccTx) Decode(encoded []byte) (tx *AccTx)
- func (tx *AccTx) Encode() []byte
- func (tx *AccTx) GetCheckString() *crypto.ChameleonHashCheckString
- func (tx *AccTx) GetData() []byte
- func (tx *AccTx) Hash() [32]byte
- func (tx *AccTx) Receiver() [32]byte
- func (tx *AccTx) SHA3() [32]byte
- func (tx *AccTx) Sender() [32]byte
- func (tx *AccTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
- func (tx *AccTx) SetData(data []byte)
- func (tx *AccTx) SetSignature(signature [64]byte)
- func (tx *AccTx) Size() uint64
- func (tx AccTx) String() string
- func (tx *AccTx) TxFee() uint64
- type Account
- type AggTx
- func (tx *AggTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
- func (*AggTx) Decode(encodedTx []byte) *AggTx
- func (tx *AggTx) Encode() (encodedTx []byte)
- func (tx *AggTx) GetCheckString() *crypto.ChameleonHashCheckString
- func (tx *AggTx) GetData() []byte
- func (tx *AggTx) Hash() (hash [32]byte)
- func (tx *AggTx) Receiver() [32]byte
- func (tx *AggTx) SHA3() [32]byte
- func (tx *AggTx) Sender() [32]byte
- func (tx *AggTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
- func (tx *AggTx) SetData(data []byte)
- func (tx *AggTx) SetSignature(signature [64]byte)
- func (tx *AggTx) Size() uint64
- func (tx AggTx) String() string
- func (tx *AggTx) TxFee() uint64
- type Block
- func (block *Block) Decode(encoded []byte) (b *Block)
- func (block *Block) Encode() []byte
- func (block *Block) EncodeHeader() []byte
- func (block *Block) GetBloomFilterSize() uint64
- func (block *Block) GetBodySize() uint64
- func (block *Block) GetHeaderSize() uint64
- func (block *Block) GetSize() uint64
- func (block *Block) GetTxDataSize() uint64
- func (block *Block) HashBlock() [32]byte
- func (block *Block) HashBlockWithoutMerkleRoot() [32]byte
- func (block *Block) InitBloomFilter(txPubKeys [][32]byte)
- func (block Block) String() string
- type ByteArray
- type Change
- type ConfigTx
- func (tx *ConfigTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
- func (*ConfigTx) Decode(encodedTx []byte) (tx *ConfigTx)
- func (tx *ConfigTx) Encode() (encodedTx []byte)
- func (tx *ConfigTx) GetCheckString() *crypto.ChameleonHashCheckString
- func (tx *ConfigTx) GetData() []byte
- func (tx *ConfigTx) Hash() (hash [32]byte)
- func (tx *ConfigTx) Receiver() [32]byte
- func (tx *ConfigTx) SHA3() [32]byte
- func (tx *ConfigTx) Sender() [32]byte
- func (tx *ConfigTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
- func (tx *ConfigTx) SetData(data []byte)
- func (tx *ConfigTx) SetSignature(signature [64]byte)
- func (tx *ConfigTx) Size() uint64
- func (tx ConfigTx) String() string
- func (tx *ConfigTx) TxFee() uint64
- type Context
- func (c *Context) GetAddress() [64]byte
- func (c *Context) GetAmount() uint64
- func (c *Context) GetBalance() uint64
- func (c *Context) GetContract() []byte
- func (c *Context) GetContractVariable(index int) ([]byte, error)
- func (c *Context) GetFee() uint64
- func (c *Context) GetIssuer() [32]byte
- func (c *Context) GetSender() [32]byte
- func (c *Context) GetSig1() [64]byte
- func (c *Context) GetTransactionData() []byte
- func (c *Context) PersistChanges()
- func (c *Context) SetContractVariable(index int, value []byte) error
- type FundsTx
- func (tx *FundsTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
- func (*FundsTx) Decode(encodedTx []byte) *FundsTx
- func (tx *FundsTx) Encode() (encodedTx []byte)
- func (tx *FundsTx) GetCheckString() *crypto.ChameleonHashCheckString
- func (tx *FundsTx) GetData() []byte
- func (tx *FundsTx) Hash() (hash [32]byte)
- func (tx *FundsTx) Receiver() [32]byte
- func (tx *FundsTx) SHA3() [32]byte
- func (tx *FundsTx) Sender() [32]byte
- func (tx *FundsTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
- func (tx *FundsTx) SetData(data []byte)
- func (tx *FundsTx) SetSignature(signature [64]byte)
- func (tx *FundsTx) Size() uint64
- func (tx FundsTx) String() string
- func (tx *FundsTx) TxFee() uint64
- type MerkleTree
- type Node
- type StakeTx
- func (tx *StakeTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
- func (*StakeTx) Decode(encodedTx []byte) (tx *StakeTx)
- func (tx *StakeTx) Encode() (encodedTx []byte)
- func (tx *StakeTx) GetCheckString() *crypto.ChameleonHashCheckString
- func (tx *StakeTx) GetData() []byte
- func (tx *StakeTx) Hash() (hash [32]byte)
- func (tx *StakeTx) Receiver() [32]byte
- func (tx *StakeTx) SHA3() [32]byte
- func (tx *StakeTx) Sender() [32]byte
- func (tx *StakeTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
- func (tx *StakeTx) SetData(data []byte)
- func (tx *StakeTx) SetSignature(signature [64]byte)
- func (tx *StakeTx) Size() uint64
- func (tx StakeTx) String() string
- func (tx *StakeTx) TxFee() uint64
- type Transaction
- type UpdateTx
- func (tx *UpdateTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
- func (*UpdateTx) Decode(encodedTx []byte) *UpdateTx
- func (tx *UpdateTx) Encode() (encodedTx []byte)
- func (tx *UpdateTx) GetCheckString() *crypto.ChameleonHashCheckString
- func (tx *UpdateTx) GetData() []byte
- func (tx *UpdateTx) Hash() (hash [32]byte)
- func (tx *UpdateTx) Receiver() [32]byte
- func (tx *UpdateTx) SHA3() [32]byte
- func (tx *UpdateTx) Sender() [32]byte
- func (tx *UpdateTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
- func (tx *UpdateTx) SetData(data []byte)
- func (tx *UpdateTx) SetSignature(signature [64]byte)
- func (tx *UpdateTx) Size() uint64
- func (tx UpdateTx) String() string
- func (tx *UpdateTx) TxFee() uint64
Constants ¶
const ( BLOCK_HASH_LEN = 32 HEIGHT_LEN = 4 //All fixed sizes form the Block struct are 254 MIN_BLOCKSIZE = 393 + crypto.COMM_PROOF_LENGTH + 1 // = 650 bytes MIN_BLOCKHEADER_SIZE = 104 BLOOM_FILTER_ERROR_RATE = 0.1 )
const ( CONFIGTX_SIZE = 83 BLOCK_SIZE_ID = 1 DIFF_INTERVAL_ID = 2 FEE_MINIMUM_ID = 3 BLOCK_INTERVAL_ID = 4 BLOCK_REWARD_ID = 5 STAKING_MINIMUM_ID = 6 WAITING_MINIMUM_ID = 7 ACCEPTANCE_TIME_DIFF_ID = 8 SLASHING_WINDOW_SIZE_ID = 9 SLASHING_REWARD_ID = 10 MIN_BLOCK_SIZE = 1000 //1KB MAX_BLOCK_SIZE = 100000000 //100MB MIN_DIFF_INTERVAL = 3 //amount in seconds MAX_DIFF_INTERVAL = 9223372036854775807 MIN_FEE_MINIMUM = 0 MAX_FEE_MINIMUM = 9223372036854775807 MIN_BLOCK_INTERVAL = 3 //30 seconds MAX_BLOCK_INTERVAL = 86400 //24 hours MIN_BLOCK_REWARD = 0 MAX_BLOCK_REWARD = 1152921504606846976 //2^60 MIN_STAKING_MINIMUM = 5 //minimum number of coins for staking MAX_STAKING_MINIMUM = 9223372036854775807 //2^60 MIN_WAITING_TIME = 0 //number of blocks that must a new validator must wait before it can start validating MAX_WAITING_TIME = 100000 MIN_ACCEPTANCE_TIME_DIFF = 0 //semi-synchronous time difference between local clock of validators MAX_ACCEPTANCE_TIME_DIFF = 60 //1min MIN_SLASHING_WINDOW_SIZE = 0 //window size where a node has to commit itself to a competing branch in case of a fork MAX_SLASHING_WINDOW_SIZE = 10000 //1000 Blocks (totally random) MIN_SLASHING_REWARD = 0 // reward for providing a valid slashing proof MAX_SLASHING_REWARD = 1152921504606846976 //2^60 )
const ( TRANSACTION_HASH_SIZE = 32 TRANSACTION_SENDER_SIZE = 32 TRANSACTION_RECEIVER_SIZE = 32 )
const (
ACCOUNT_ADDRESS_SIZE = 64
)
const (
ACCTX_SIZE = 169
)
const (
AGGTX_SIZE = 85 //Only constant Values --> Without To, From & AggregatedTxSlice
)
const (
FUNDSTX_SIZE = 246
)
const (
STAKETX_SIZE = 106 + crypto.COMM_KEY_LENGTH
)
const UPDATE_TX_SIZE = 42
Variables ¶
This section is empty.
Functions ¶
func RandomBytes ¶
func RandomBytes() []byte
func RandomBytesWithLength ¶
func SerializeHashContent ¶
func SerializeHashContent(data interface{}) (hash [32]byte)
Serializes the input and returns the SHA3 hash function applied on ths input
Types ¶
type AccTx ¶
type AccTx struct { Header byte Fee uint64 Issuer [32]byte PubKey [64]byte Sig [64]byte Contract []byte ContractVariables []ByteArray Parameters *crypto.ChameleonHashParameters // Chameleon hash parameters associated with this account. CheckString *crypto.ChameleonHashCheckString // Chameleon hash check string associated with this tx. Data []byte }
func ConstrAccTx ¶
func (*AccTx) ChameleonHash ¶
func (tx *AccTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
Returns the chameleon hash but takes the chameleon hash parameters as input. This method should be called in the context of bazo-client as the client doesn't maintain a state holding the chameleon hash parameters of each account.
func (*AccTx) GetCheckString ¶
func (tx *AccTx) GetCheckString() *crypto.ChameleonHashCheckString
func (*AccTx) SetCheckString ¶
func (tx *AccTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
func (*AccTx) SetSignature ¶
type Account ¶
type Account struct { Address [ACCOUNT_ADDRESS_SIZE]byte // 64 Byte Issuer [32]byte // 32 Byte Balance uint64 // 8 Byte TxCnt uint32 // 4 Byte IsStaking bool // 1 Byte CommitmentKey [crypto.COMM_KEY_LENGTH]byte // represents the modulus N of the RSA public key StakingBlockHeight uint32 // 4 Byte Contract []byte // Arbitrary length ContractVariables []ByteArray // Arbitrary length Parameters *crypto.ChameleonHashParameters // Parameter set for chameleon hashing }
func NewAccount ¶
func NewAccount( address [ACCOUNT_ADDRESS_SIZE]byte, issuer [32]byte, balance uint64, isStaking bool, commitmentKey [crypto.COMM_KEY_LENGTH]byte, contract []byte, contractVariables []ByteArray, parameters *crypto.ChameleonHashParameters, ) Account
type AggTx ¶
type AggTx struct { Amount uint64 Fee uint64 From [][32]byte To [][32]byte AggregatedTxSlice [][32]byte Aggregated bool Block [32]byte //This saves the blockHashWithoutTransactions into which the transaction was usually validated. Needed for rollback. MerkleRoot [32]byte CheckString *crypto.ChameleonHashCheckString // Chameleon hash check string associated with this tx. Data []byte }
func ConstrAggTx ¶
func (*AggTx) ChameleonHash ¶
func (tx *AggTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
As we don't use chameleon hashing on config tx, we simply return an SHA3 hash
func (*AggTx) Encode ¶
when we serialize the struct with binary.Write, unexported field get serialized as well, undesired behavior. Therefore, writing own encoder/decoder
func (*AggTx) GetCheckString ¶
func (tx *AggTx) GetCheckString() *crypto.ChameleonHashCheckString
func (*AggTx) SetCheckString ¶
func (tx *AggTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
func (*AggTx) SetSignature ¶
type Block ¶
type Block struct { //Header Header byte Hash [32]byte PrevHash [32]byte HashWithoutTx [32]byte //valid hash once all tx are aggregated PrevHashWithoutTx [32]byte //valid hash of ancestor once all tx are aggregated NrElementsBF uint16 BloomFilter *bloom.BloomFilter //8 byte Height uint32 Beneficiary [32]byte Aggregated bool //Indicates if All transactions are aggregated with a boolean. NrUpdates uint16 // Indicates how many txs of this block were updated. //Body Nonce [8]byte Timestamp int64 MerkleRoot [32]byte NrAccTx uint16 NrConfigTx uint8 NrFundsTx uint16 NrStakeTx uint16 NrAggTx uint16 NrUpdateTx uint16 SlashedAddress [32]byte CommitmentProof [crypto.COMM_PROOF_LENGTH]byte ConflictingBlockHash1 [32]byte ConflictingBlockHash2 [32]byte ConflictingBlockHashWithoutTx1 [32]byte ConflictingBlockHashWithoutTx2 [32]byte StateCopy map[[32]byte]*Account //won't be serialized, just keeping track of local state changes AccTxData [][32]byte FundsTxData [][32]byte ConfigTxData [][32]byte StakeTxData [][32]byte AggTxData [][32]byte UpdateTxData [][32]byte }
func (*Block) EncodeHeader ¶
func (*Block) GetBloomFilterSize ¶
func (*Block) GetBodySize ¶
func (*Block) GetHeaderSize ¶
func (*Block) GetTxDataSize ¶
func (*Block) HashBlockWithoutMerkleRoot ¶
func (*Block) InitBloomFilter ¶
type ConfigTx ¶
type ConfigTx struct { Header byte Id uint8 Payload uint64 Fee uint64 TxCnt uint8 Sig [64]byte CheckString *crypto.ChameleonHashCheckString // Chameleon hash check string associated with this tx. Data []byte }
func ConstrConfigTx ¶
func (*ConfigTx) ChameleonHash ¶
func (tx *ConfigTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
As we don't use chameleon hashing on config tx, we simply return an SHA3 hash
func (*ConfigTx) GetCheckString ¶
func (tx *ConfigTx) GetCheckString() *crypto.ChameleonHashCheckString
func (*ConfigTx) SetCheckString ¶
func (tx *ConfigTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
func (*ConfigTx) SetSignature ¶
type Context ¶
func NewContext ¶
func (*Context) GetAddress ¶
func (*Context) GetBalance ¶
func (*Context) GetContract ¶
func (*Context) GetContractVariable ¶
func (*Context) GetTransactionData ¶
func (*Context) PersistChanges ¶
func (c *Context) PersistChanges()
type FundsTx ¶
type FundsTx struct { Header byte Amount uint64 Fee uint64 TxCnt uint32 From [32]byte To [32]byte Sig1 [64]byte Sig2 [64]byte Aggregated bool Block [32]byte // This saves the blockHashWithoutTransactions into which the transaction was usually validated. Needed for rollback. CheckString *crypto.ChameleonHashCheckString // Chameleon hash check string associated with this tx. Data []byte }
func ConstrFundsTx ¶
func (*FundsTx) ChameleonHash ¶
func (tx *FundsTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
Returns the chameleon hash but takes the chameleon hash parameters as input. This method should be called in the context of bazo-client as the client doesn't maintain a copy of the chameleon hash parameters of each account.
func (*FundsTx) Encode ¶
when we serialize the struct with binary.Write, unexported field get serialized as well, undesired behavior. Therefore, writing own encoder/decoder
func (*FundsTx) GetCheckString ¶
func (tx *FundsTx) GetCheckString() *crypto.ChameleonHashCheckString
func (*FundsTx) Hash ¶
Returns the chameleon hash without chameleon hash parameters as input. This can be called in the context of bazo-miner as the miner keeps a state with the chameleon hash parameters of all accounts.
func (*FundsTx) SetCheckString ¶
func (tx *FundsTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
func (*FundsTx) SetSignature ¶
type MerkleTree ¶
MerkleTree is the container for the tree. It holds a pointer to the root of the tree, a list of pointers to the leaf nodes, and the merkle root.
func BuildAggTxMerkleTree ¶
func BuildAggTxMerkleTree(txHashes [][32]byte) *MerkleTree
func BuildMerkleTree ¶
func BuildMerkleTree(b *Block) *MerkleTree
func (*MerkleTree) MerkleRoot ¶
func (m *MerkleTree) MerkleRoot() [32]byte
MerkleRoot returns the unverified Merkle Root (hash of the root node) of the tree.
func (*MerkleTree) String ¶
func (m *MerkleTree) String() string
String returns a string representation of the tree. Only leaf nodes are included in the output.
func (*MerkleTree) VerifyTree ¶
func (m *MerkleTree) VerifyTree() bool
VerifyTree verify tree validates the hashes at each level of the tree and returns true if the resulting hash at the root of the tree matches the resulting root hash; returns false otherwise.
type Node ¶
type Node struct { Parent *Node Left *Node Right *Node Hash [32]byte // contains filtered or unexported fields }
Node represents a node, root, or leaf in the tree. It stores pointers to its immediate relationships, a hash, the content stored if it is a leaf, and other metadata.
func GetIntermediate ¶
VerifyContent indicates whether a given content is in the tree and the hashes are valid for that content. Returns true if the expected Merkle Root is equivalent to the Merkle root calculated on the critical path for a given content. Returns true if valid and false otherwise.
func GetLeaf ¶
func GetLeaf(merkleTree *MerkleTree, leafHash [32]byte) *Node
type StakeTx ¶
type StakeTx struct { Header byte // 1 Byte Fee uint64 // 8 Byte IsStaking bool // 1 Byte Account [32]byte // 32 Byte Sig [64]byte // 64 Byte CommitmentKey [crypto.COMM_KEY_LENGTH]byte // the modulus N of the RSA public key CheckString *crypto.ChameleonHashCheckString // Chameleon hash check string associated with this tx. Data []byte }
func ConstrStakeTx ¶
func (*StakeTx) ChameleonHash ¶
func (tx *StakeTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
As we don't use chameleon hashing on config tx, we simply return an SHA3 hash
func (*StakeTx) Encode ¶
when we serialize the struct with binary.Write, unexported field get serialized as well, undesired behavior. Therefore, writing own encoder/decoder
func (*StakeTx) GetCheckString ¶
func (tx *StakeTx) GetCheckString() *crypto.ChameleonHashCheckString
func (*StakeTx) SetCheckString ¶
func (tx *StakeTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)
func (*StakeTx) SetSignature ¶
type Transaction ¶
type Transaction interface { Hash() [TRANSACTION_HASH_SIZE]byte ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte SHA3() [32]byte Encode() []byte //Decoding is not listed here, because it returns a different type for each tx (return value Transaction itself //is apparently not allowed) TxFee() uint64 Size() uint64 Sender() [TRANSACTION_SENDER_SIZE]byte Receiver() [TRANSACTION_RECEIVER_SIZE]byte String() string SetData(data []byte) // Set the data field to the new value GetData() []byte SetCheckString(checkString *crypto.ChameleonHashCheckString) GetCheckString() *crypto.ChameleonHashCheckString SetSignature(signature [64]byte) }
type UpdateTx ¶
type UpdateTx struct { Fee uint64 TxToUpdateHash [32]byte // Hash of the tx to be updated. TxToUpdateCheckString *crypto.ChameleonHashCheckString // New Chameleon hash check string for the tx to be updated. TxToUpdateData []byte // Holds the data to be updated on the TxToUpdate's data field. Issuer [32]byte // Address of the issuer of the update request. Sig [64]byte // Signature of the issuer of the update request. CheckString *crypto.ChameleonHashCheckString // Chameleon hash check string associated with this tx. Data []byte // Data field for user-related data. }
func ConstrUpdateTx ¶
func (*UpdateTx) ChameleonHash ¶
func (tx *UpdateTx) ChameleonHash(parameters *crypto.ChameleonHashParameters) [32]byte
Returns the chameleon hash but takes the chameleon hash parameters as input. This method should be called in the context of bazo-client as the client doesn't maintain a state holding the chameleon hash parameters of each account.
func (*UpdateTx) GetCheckString ¶
func (tx *UpdateTx) GetCheckString() *crypto.ChameleonHashCheckString
func (*UpdateTx) SetCheckString ¶
func (tx *UpdateTx) SetCheckString(checkString *crypto.ChameleonHashCheckString)