Documentation ¶
Overview ¶
block is just a tx mass, but can be treat as a block it means that after the vault summary, the data in previous block chain can be throw we just need to keep the latest some block and treasuries to make the chain safe
Package ngtype implements the block structure and related types.
bare -(+ops&mtree)-> Unsealing -(+nonce)-> Sealed
Index ¶
- Constants
- Variables
- func TotalFee(ops []*Operation) (totalFee *big.Int)
- type Account
- func (*Account) Descriptor() ([]byte, []int)
- func (m *Account) GetBalance() []byte
- func (m *Account) GetID() uint64
- func (m *Account) GetNonce() uint64
- func (m *Account) GetOwner() []byte
- func (m *Account) GetSubState() []byte
- func (m *Account) Marshal() (dAtA []byte, err error)
- func (m *Account) MarshalTo(dAtA []byte) (int, error)
- func (m *Account) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Account) ProtoMessage()
- func (m *Account) Reset()
- func (m *Account) Size() (n int)
- func (m *Account) String() string
- func (m *Account) Unmarshal(dAtA []byte) error
- func (m *Account) XXX_DiscardUnknown()
- func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Account) XXX_Merge(src proto.Message)
- func (m *Account) XXX_Size() int
- func (m *Account) XXX_Unmarshal(b []byte) error
- type Block
- func (m *Block) CalculateHash() ([]byte, error)
- func (m *Block) CheckError() error
- func (m *Block) Copy() *Block
- func (*Block) Descriptor() ([]byte, []int)
- func (m *Block) GetBeneficiary() []byte
- func (m *Block) GetBlob() ([]byte, error)
- func (m *Block) GetDifficulty() []byte
- func (m *Block) GetHash() []byte
- func (m *Block) GetHeight() uint64
- func (m *Block) GetNonce() []byte
- func (m *Block) GetOperations() []*Operation
- func (m *Block) GetPrevBlockHash() []byte
- func (m *Block) GetPrevVaultHash() []byte
- func (m *Block) GetTimestamp() int64
- func (m *Block) GetTrieHash() []byte
- func (m *Block) IsCheckpoint() bool
- func (m *Block) IsGenesisBlock() bool
- func (m *Block) IsSealed() bool
- func (m *Block) IsUnsealing() bool
- func (m *Block) Marshal() (dAtA []byte, err error)
- func (m *Block) MarshalTo(dAtA []byte) (int, error)
- func (m *Block) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Block) ProtoMessage()
- func (m *Block) Reset()
- func (m *Block) Size() (n int)
- func (m *Block) String() string
- func (m *Block) ToSealed(nonce []byte, hash []byte) *Block
- func (m *Block) ToUnsealing(ops []*Operation) *Block
- func (m *Block) Unmarshal(dAtA []byte) error
- func (m *Block) VerifyHash() bool
- func (m *Block) XXX_DiscardUnknown()
- func (m *Block) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Block) XXX_Merge(src proto.Message)
- func (m *Block) XXX_Size() int
- func (m *Block) XXX_Unmarshal(b []byte) error
- type OpBucket
- type OpTrie
- func (ot *OpTrie) Append(op *Operation)
- func (ot *OpTrie) Contain(op *Operation) bool
- func (ot *OpTrie) Copy() *OpTrie
- func (ot *OpTrie) Del(op *Operation) error
- func (ot *OpTrie) Len() int
- func (ot *OpTrie) Less(i, j int) bool
- func (ot *OpTrie) ReverseSort() *OpTrie
- func (ot *OpTrie) Sort() *OpTrie
- func (ot *OpTrie) Swap(i, j int)
- func (ot *OpTrie) TrieRoot() []byte
- type OpType
- type Operation
- func (m *Operation) CalculateHash() ([]byte, error)
- func (m *Operation) Copy() *Operation
- func (*Operation) Descriptor() ([]byte, []int)
- func (m *Operation) Equals(other merkletree.Content) (bool, error)
- func (m *Operation) GetExtra() []byte
- func (m *Operation) GetFee() []byte
- func (m *Operation) GetFrom() uint64
- func (m *Operation) GetNonce() uint64
- func (m *Operation) GetPrevVaultHash() []byte
- func (m *Operation) GetR() []byte
- func (m *Operation) GetS() []byte
- func (m *Operation) GetTo() uint64
- func (m *Operation) GetType() OpType
- func (m *Operation) GetValue() []byte
- func (m *Operation) IsSigned() bool
- func (m *Operation) Marshal() (dAtA []byte, err error)
- func (m *Operation) MarshalTo(dAtA []byte) (int, error)
- func (m *Operation) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Operation) ProtoMessage()
- func (m *Operation) ReadableHex() string
- func (m *Operation) Reset()
- func (m *Operation) Signature(privKey *ecdsa.PrivateKey) (R, S *big.Int, err error)
- func (m *Operation) Size() (n int)
- func (m *Operation) String() string
- func (m *Operation) Unmarshal(dAtA []byte) error
- func (m *Operation) Verify(pubKey ecdsa.PublicKey) bool
- func (m *Operation) XXX_DiscardUnknown()
- func (m *Operation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Operation) XXX_Merge(src proto.Message)
- func (m *Operation) XXX_Size() int
- func (m *Operation) XXX_Unmarshal(b []byte) error
- type Sheet
- func (m *Sheet) ApplyBlock(block *Block) (*Sheet, error)
- func (m *Sheet) Copy() *Sheet
- func (m *Sheet) DelAccount(accountID uint64) error
- func (*Sheet) Descriptor() ([]byte, []int)
- func (m *Sheet) ExportAccounts() []*Account
- func (m *Sheet) GetAccountByID(accountID uint64) (*Account, error)
- func (m *Sheet) GetAccountByKey(publicKey ecdsa.PublicKey) ([]*Account, error)
- func (m *Sheet) GetAccountByKeyBytes(bPublicKey []byte) ([]*Account, error)
- func (m *Sheet) GetPrevVaultHash() []byte
- func (m *Sheet) GetRows() map[uint64]*Account
- func (m *Sheet) HasAccount(accountID uint64) bool
- func (m *Sheet) Marshal() (dAtA []byte, err error)
- func (m *Sheet) MarshalTo(dAtA []byte) (int, error)
- func (m *Sheet) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Sheet) ProtoMessage()
- func (m *Sheet) RegisterAccount(account *Account) error
- func (m *Sheet) Reset()
- func (m *Sheet) Size() (n int)
- func (m *Sheet) String() string
- func (m *Sheet) Unmarshal(dAtA []byte) error
- func (m *Sheet) XXX_DiscardUnknown()
- func (m *Sheet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Sheet) XXX_Merge(src proto.Message)
- func (m *Sheet) XXX_Size() int
- func (m *Sheet) XXX_Unmarshal(b []byte) error
- type Vault
- func (m *Vault) CalculateHash() ([]byte, error)
- func (m *Vault) Copy() *Vault
- func (*Vault) Descriptor() ([]byte, []int)
- func (m *Vault) GetHash() []byte
- func (m *Vault) GetHeight() uint64
- func (m *Vault) GetHookBlockHash() []byte
- func (m *Vault) GetNewAccount() *Account
- func (m *Vault) GetPrevVaultHash() []byte
- func (m *Vault) GetSheet() *Sheet
- func (m *Vault) GetTimestamp() int64
- func (m *Vault) Marshal() (dAtA []byte, err error)
- func (m *Vault) MarshalTo(dAtA []byte) (int, error)
- func (m *Vault) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Vault) ProtoMessage()
- func (m *Vault) Reset()
- func (m *Vault) Size() (n int)
- func (m *Vault) String() string
- func (m *Vault) Unmarshal(dAtA []byte) error
- func (m *Vault) XXX_DiscardUnknown()
- func (m *Vault) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Vault) XXX_Merge(src proto.Message)
- func (m *Vault) XXX_Size() int
- func (m *Vault) XXX_Unmarshal(b []byte) error
Constants ¶
const ( GenesisPK = "" /* 132-byte string literal not displayed */ GenesisBalance = math.MaxInt64 GenesisData = "NGIN TESTNET" GenesisHash = "123" )
Variables ¶
var ( ErrInvalidLengthAccount = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowAccount = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupAccount = fmt.Errorf("proto: unexpected end of group") )
var ( ErrBlockIsBare = errors.New("the block is bare") ErrBlockIsUnsealing = errors.New("the block is unsealing") ErrBlockHeightInvalid = errors.New("the block's height is invalid") ErrBlockMTreeInvalid = errors.New("the merkle tree in block is invalid") ErrBlockPrevBlockHash = errors.New("the block's previous block hash is invalid") ErrBlockPrevTreasuryHash = errors.New("the block's backend vault is invalid") ErrBlockDiffInvalid = errors.New("the block's difficulty is invalid") ErrBlockHashInvalid = errors.New("the block's hash is invalid") ErrBlockNonceInvalid = errors.New("the block's Nonce is invalid") ErrMalformedBlock = errors.New("the block structure is malformed") )
var ( ErrInvalidLengthBlock = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowBlock = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupBlock = fmt.Errorf("proto: unexpected end of group") )
var ( MaxDiff = [32]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255} // new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0)) // Target = MaxDiff / diff GenesisDifficulty = new(big.Int).SetBytes([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255}) GenesisNonce = new(big.Int).SetUint64(5577006791947779410) Big1 = big.NewInt(1) Big0 = big.NewInt(0) TargetTime = 1e10 )
var ( OneNGIN = new(big.Int).SetUint64(1000000) //MinimalUnit = big.NewInt(1) OneBlockReward = new(big.Int).Mul(OneNGIN, big.NewInt(10)) // 10NG )
Units
var ( ErrInvalidOpNonce = errors.New("the nonce in operation is smaller than the account's record") ErrIsNotSigned = errors.New("the operation is not signed") ErrBalanceInsufficient = errors.New("balance is insufficient for payment") ErrWrongSign = errors.New("the signer of operation is not the own of the account") ErrMalformedOperation = errors.New("the operation structure is malformed") )
var ( ErrInvalidLengthOperation = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowOperation = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupOperation = fmt.Errorf("proto: unexpected end of group") )
var ( ErrAccountNotExists = errors.New("the account does not exist") ErrMalformedSheet = errors.New("the sheet structure is malformed") )
var ( ErrInvalidLengthSheet = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowSheet = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupSheet = fmt.Errorf("proto: unexpected end of group") )
var ( ErrNotCheckpoint = errors.New("not proper time for building new vault") ErrInvalidHookBlock = errors.New("the vault's hook_block is invalid") ErrMalformedVault = errors.New("the vault structure is malformed") )
var ( ErrInvalidLengthVault = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowVault = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupVault = fmt.Errorf("proto: unexpected end of group") )
var OpType_name = map[int32]string{
0: "TX",
}
var OpType_value = map[string]int32{
"TX": 0,
}
Functions ¶
Types ¶
type Account ¶
type Account struct { ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` Balance []byte `protobuf:"bytes,2,opt,name=balance,proto3" json:"balance,omitempty"` Owner []byte `protobuf:"bytes,3,opt,name=owner,proto3" json:"owner,omitempty"` Nonce uint64 `protobuf:"varint,4,opt,name=nonce,proto3" json:"nonce,omitempty"` SubState []byte `protobuf:"bytes,5,opt,name=sub_state,json=subState,proto3" json:"sub_state,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func GetGenesisAccount ¶
func GetGenesisAccount() *Account
func NewAccount ¶
AccountID will receive an ID and PK then return a Account without SubState and Balance(0
func NewRewardAccount ¶
func (*Account) Descriptor ¶
func (*Account) GetBalance ¶
func (*Account) GetSubState ¶
func (*Account) MarshalToSizedBuffer ¶
func (*Account) ProtoMessage ¶
func (*Account) ProtoMessage()
func (*Account) XXX_DiscardUnknown ¶
func (m *Account) XXX_DiscardUnknown()
func (*Account) XXX_Marshal ¶
func (*Account) XXX_Unmarshal ¶
type Block ¶
type Block struct { Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` TrieHash []byte `protobuf:"bytes,3,opt,name=trie_hash,json=trieHash,proto3" json:"trie_hash,omitempty"` PrevBlockHash []byte `protobuf:"bytes,4,opt,name=prev_block_hash,json=prevBlockHash,proto3" json:"prev_block_hash,omitempty"` PrevVaultHash []byte `protobuf:"bytes,5,opt,name=prev_vault_hash,json=prevVaultHash,proto3" json:"prev_vault_hash,omitempty"` Beneficiary []byte `protobuf:"bytes,6,opt,name=beneficiary,proto3" json:"beneficiary,omitempty"` Difficulty []byte `protobuf:"bytes,7,opt,name=difficulty,proto3" json:"difficulty,omitempty"` Nonce []byte `protobuf:"bytes,8,opt,name=nonce,proto3" json:"nonce,omitempty"` Operations []*Operation `protobuf:"bytes,9,rep,name=operations,proto3" json:"operations,omitempty"` Hash []byte `protobuf:"bytes,10,opt,name=hash,proto3" json:"hash,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func GetGenesisBlock ¶
func GetGenesisBlock() *Block
GetGenesisBlock will return a complete sealed GenesisBlock
func NewBareBlock ¶
func NewBareBlock(height uint64, prevBlockHash, prevVaultHash []byte, PublicKey []byte, diff *big.Int) *Block
NewBareBlock will return an unsealing block and then you need to add ops and seal with the correct Nonce
func (*Block) CalculateHash ¶
GetHash will help you get the hash of block
func (*Block) CheckError ¶
CheckError will check the errors in block inner fields
func (*Block) Descriptor ¶
func (*Block) GetBeneficiary ¶
func (*Block) GetDifficulty ¶
func (*Block) GetOperations ¶
func (*Block) GetPrevBlockHash ¶
func (*Block) GetPrevVaultHash ¶
func (*Block) GetTimestamp ¶
func (*Block) GetTrieHash ¶
func (*Block) IsCheckpoint ¶
IsCheckpoint will check whether the Block is the
func (*Block) IsGenesisBlock ¶
func (*Block) IsUnsealing ¶
func (*Block) ProtoMessage ¶
func (*Block) ProtoMessage()
func (*Block) ToUnsealing ¶
ToUnsealing converts a bare block to an unsealing block
func (*Block) VerifyHash ¶
GetHash will help you get the hash of block
func (*Block) XXX_DiscardUnknown ¶
func (m *Block) XXX_DiscardUnknown()
func (*Block) XXX_Marshal ¶
func (*Block) XXX_Unmarshal ¶
type OpBucket ¶
OpBucket is an operation container with unfixed order, mainly for implementing queuing
func NewOpBucket ¶
func NewOpBucket() *OpBucket
func (*OpBucket) GetSortedTrie ¶
type OpTrie ¶
type OpTrie struct {
Ops []*Operation
}
OpTrie is an fixed ordered operation container, mainly for pending OpTrie is an advanced type, aiming to get the trie root hash
func (*OpTrie) ReverseSort ¶
ReverseSort the ops from higher priority to lower priority
type Operation ¶
type Operation struct { Type OpType `protobuf:"varint,1,opt,name=type,proto3,enum=ngtype.OpType" json:"type,omitempty"` From uint64 `protobuf:"varint,2,opt,name=from,proto3" json:"from,omitempty"` To uint64 `protobuf:"varint,3,opt,name=to,proto3" json:"to,omitempty"` Fee []byte `protobuf:"bytes,4,opt,name=fee,proto3" json:"fee,omitempty"` Value []byte `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"` Nonce uint64 `protobuf:"varint,6,opt,name=nonce,proto3" json:"nonce,omitempty"` PrevVaultHash []byte `protobuf:"bytes,7,opt,name=prev_vault_hash,json=prevVaultHash,proto3" json:"prev_vault_hash,omitempty"` // sign R []byte `protobuf:"bytes,8,opt,name=r,proto3" json:"r,omitempty"` S []byte `protobuf:"bytes,9,opt,name=s,proto3" json:"s,omitempty"` // extension Extra []byte `protobuf:"bytes,10,opt,name=extra,proto3" json:"extra,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func NewUnsignedOperation ¶
func NewUnsignedOperation(t OpType, sender, target, n uint64, value, fee *big.Int, prevVaultHash, extraData []byte) *Operation
NewUnsignedOperation will return an Unsigned Operation, must using Signature()
func (*Operation) CalculateHash ¶
CalculateHash mainly for calculating the tire root of ops
func (*Operation) Descriptor ¶
func (*Operation) Equals ¶
func (m *Operation) Equals(other merkletree.Content) (bool, error)
Equals mainly for calculating the tire root of ops
func (*Operation) GetPrevVaultHash ¶
func (*Operation) MarshalToSizedBuffer ¶
func (*Operation) ProtoMessage ¶
func (*Operation) ProtoMessage()
func (*Operation) XXX_DiscardUnknown ¶
func (m *Operation) XXX_DiscardUnknown()
func (*Operation) XXX_Marshal ¶
func (*Operation) XXX_Unmarshal ¶
type Sheet ¶
type Sheet struct { PrevVaultHash []byte `protobuf:"bytes,1,opt,name=prev_vault_hash,json=prevVaultHash,proto3" json:"prev_vault_hash,omitempty"` Rows map[uint64]*Account `` /* 150-byte string literal not displayed */ XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func NewEmptySheet ¶
func (*Sheet) DelAccount ¶
func (*Sheet) Descriptor ¶
func (*Sheet) ExportAccounts ¶
func (*Sheet) GetAccountByKey ¶
func (*Sheet) GetAccountByKeyBytes ¶
func (*Sheet) GetPrevVaultHash ¶
func (*Sheet) HasAccount ¶
func (*Sheet) ProtoMessage ¶
func (*Sheet) ProtoMessage()
func (*Sheet) RegisterAccount ¶
func (*Sheet) XXX_DiscardUnknown ¶
func (m *Sheet) XXX_DiscardUnknown()
func (*Sheet) XXX_Marshal ¶
func (*Sheet) XXX_Unmarshal ¶
type Vault ¶
type Vault struct { Height uint64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` NewAccount *Account `protobuf:"bytes,2,opt,name=new_account,json=newAccount,proto3" json:"new_account,omitempty"` Timestamp int64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"` PrevVaultHash []byte `protobuf:"bytes,4,opt,name=prev_vault_hash,json=prevVaultHash,proto3" json:"prev_vault_hash,omitempty"` HookBlockHash []byte `protobuf:"bytes,5,opt,name=hook_block_hash,json=hookBlockHash,proto3" json:"hook_block_hash,omitempty"` Sheet *Sheet `protobuf:"bytes,6,opt,name=sheet,proto3" json:"sheet,omitempty"` Hash []byte `protobuf:"bytes,7,opt,name=hash,proto3" json:"hash,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func GetGenesisVault ¶
func GetGenesisVault() *Vault
func (*Vault) CalculateHash ¶
func (*Vault) Descriptor ¶
func (*Vault) GetHookBlockHash ¶
func (*Vault) GetNewAccount ¶
func (*Vault) GetPrevVaultHash ¶
func (*Vault) GetTimestamp ¶
func (*Vault) ProtoMessage ¶
func (*Vault) ProtoMessage()
func (*Vault) XXX_DiscardUnknown ¶
func (m *Vault) XXX_DiscardUnknown()