basic

package
v0.0.0-...-d0e3281 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2019 License: GPL-3.0 Imports: 15 Imported by: 5

Documentation

Index

Constants

View Source
const Delay int = 10

Delay the communication delay(ms)

View Source
const GenesisTxBlock = "First TxBlock"

GenesisTxBlock is the predefined hash of TDS

View Source
const SHash int = 12

SHash is the shortcut length of hash

Variables

This section is empty.

Functions

func ByteSlice

func ByteSlice(x uint32) []byte

ByteSlice returns a slice of a integer

func Decode

func Decode(tmp *[]byte, out interface{}) error

Decode is the general function of decoding

func DecodeBig

func DecodeBig(current *[]byte, out *big.Int) error

DecodeBig decodes a byte[] into a big number

func DecodeByte

func DecodeByte(d *[]byte, out *[]byte) error

DecodeByte Decode bytes with a uint32 preamble

func DecodeByteL

func DecodeByteL(d *[]byte, out *[]byte, l int) error

DecodeByteL Decode bytes with a uint32 preamble

func DecodeDoubleBig

func DecodeDoubleBig(current *[]byte, a *big.Int, b *big.Int) error

DecodeDoubleBig encodes a signature into data

func DecodeInt

func DecodeInt(d *[]byte, out interface{}) error

DecodeInt Decode the data to uint32

func Deserialize

func Deserialize(buf *[]byte, a interface{}) error

Deserialize is the general encoding function

func DoubleHash256

func DoubleHash256(a *[]byte, b *[32]byte)

DoubleHash256 returns the double hash result of hash256

func Encode

func Encode(tmp *[]byte, out interface{}) error

Encode is the general function of decoding

func EncodeBig

func EncodeBig(current *[]byte, d *big.Int) error

EncodeBig encodes a big number into byte[]

func EncodeByte

func EncodeByte(current *[]byte, d *[]byte) error

EncodeByte add length bit at the head of the byte array

func EncodeByteL

func EncodeByteL(current *[]byte, d []byte, l int) error

EncodeByteL add length bit at the head of the byte array with specific length

func EncodeDoubleBig

func EncodeDoubleBig(current *[]byte, a *big.Int, b *big.Int) error

EncodeDoubleBig encodes a signature into data

func EncodeInt

func EncodeInt(current *[]byte, d interface{}) error

EncodeInt Encode the data

func FindBigInt

func FindBigInt(a int) big.Int

FindBigInt gives a bigInt data with the input int

func FindByte32

func FindByte32(a int) [32]byte

FindByte32 gives a [32]byte data with the input int

func GenMerkTree

func GenMerkTree(d *[]Transaction, out *[32]byte) error

GenMerkTree generates the merkleroot tree given the transactions

func HashCut

func HashCut(x [32]byte) [SHash]byte

HashCut returns the part of the hash

func MakeTx

func MakeTx(a *[]InType, b *[]OutType, out *Transaction, kind int) error

MakeTx implements the method to create a new transaction

func Serialize

func Serialize(a interface{}, b *[]byte) error

Serialize is the general encoding function

func ShardIndex

func ShardIndex(str [32]byte) uint32

ShardIndex returns the shard index

Types

type AccCache

type AccCache struct {
	ID    [32]byte
	Value uint32
}

AccCache is the cache of account

type InType

type InType struct {
	PrevTx [32]byte
	Index  uint32
	Sig    RCSign
	PukX   *big.Int
	PukY   *big.Int
}

InType is the format of the input address data in the transaction

func (*InType) Acc

func (a *InType) Acc() bool

Acc returns whether the input address is an account or utxo

func (*InType) Byte

func (a *InType) Byte(b *[]byte)

Byte return the []byte of the input address used for hash

func (*InType) DataToIn

func (a *InType) DataToIn(data *[]byte) error

DataToIn converts bytes into input address data

func (*InType) InToData

func (a *InType) InToData(b *[]byte)

InToData converts the input address data into bytes

func (*InType) Init

func (a *InType) Init()

Init initial the big.Int parameters

func (*InType) Print

func (a *InType) Print()

Print is

func (*InType) Puk

func (a *InType) Puk() ecdsa.PublicKey

Puk returns the public key

func (*InType) ShardIndex

func (a *InType) ShardIndex() uint32

ShardIndex returns the target shard of the input address

func (*InType) SignTxIn

func (a *InType) SignTxIn(prk *ecdsa.PrivateKey, h [32]byte)

SignTxIn make the signature given the transaction

func (*InType) VerifyIn

func (a *InType) VerifyIn(b *OutType, h [32]byte) bool

VerifyIn using the UTXO to verify the in address

type Miner

type Miner struct {
	ID        string
	Rep       int
	Prk       ecdsa.PublicKey
	LastGroup int
}

Miner is the miner

type OutType

type OutType struct {
	Value   uint32
	Address [32]byte
}

OutType is the format of the output address data in the transaction

func (*OutType) DataToOut

func (a *OutType) DataToOut(data *[]byte) error

DataToOut converts bytes into output address data

func (*OutType) OutToData

func (a *OutType) OutToData(b *[]byte)

OutToData converts the output address data into bytes

func (*OutType) Print

func (a *OutType) Print()

Print is

func (*OutType) ShardIndex

func (a *OutType) ShardIndex() uint32

ShardIndex returns the target shard of the output address

type RCSign

type RCSign struct {
	R *big.Int
	S *big.Int
}

RCSign is the signature type in our design

func (*RCSign) DataToSign

func (a *RCSign) DataToSign(b *[]byte) error

DataToSign decode the []byte into signature

func (*RCSign) New

func (a *RCSign) New(b *RCSign)

New assign a new value

func (*RCSign) Sign

func (a *RCSign) Sign(b []byte, prk *ecdsa.PrivateKey)

Sign returns the signature

func (*RCSign) SignToData

func (a *RCSign) SignToData(b *[]byte)

SignToData encode the signature into []byte

func (*RCSign) Verify

func (a *RCSign) Verify(b []byte, puk *ecdsa.PublicKey) bool

Verify return the verification

type Transaction

type Transaction struct {
	Timestamp uint64
	TxinCnt   uint32
	In        []InType
	TxoutCnt  uint32
	Out       []OutType
	Kind      uint32
	Locktime  uint32
	Hash      [32]byte
}

Transaction is the transaction data which sent by the sender

func (*Transaction) AddIn

func (a *Transaction) AddIn(b InType)

AddIn increases one input of transaction a

func (*Transaction) AddOut

func (a *Transaction) AddOut(b OutType)

AddOut increases one output of transaction a

func (*Transaction) Decode

func (a *Transaction) Decode(buf *[]byte) error

Decode decodes the packets into transaction format

func (*Transaction) Encode

func (a *Transaction) Encode(tmp *[]byte)

Encode converts the transaction into bytes

func (*Transaction) HashTx

func (a *Transaction) HashTx() [32]byte

HashTx is come out the hash

func (*Transaction) New

func (a *Transaction) New(kind int, seed int64, writer uint32) error

New is to initialize a transaction

func (*Transaction) Print

func (a *Transaction) Print()

Print is

func (*Transaction) SignTx

func (a *Transaction) SignTx(i uint32, prk *ecdsa.PrivateKey) error

SignTx sign the ith in-address with the private key

func (*Transaction) VerifyTx

func (a *Transaction) VerifyTx(i uint32, b *OutType) bool

VerifyTx sign the ith in-address with the private key

type TransactionBatch

type TransactionBatch struct {
	TxCnt   uint32
	TxArray []Transaction
}

TransactionBatch a set of multiple transactions

func (*TransactionBatch) Add

func (a *TransactionBatch) Add(b *Transaction) error

Add is to add a transactionbatch

func (*TransactionBatch) Decode

func (a *TransactionBatch) Decode(buf *[]byte) error

Decode is to encode a transactionbatch

func (*TransactionBatch) Encode

func (a *TransactionBatch) Encode() []byte

Encode is to encode a transactionbatch

func (*TransactionBatch) New

func (a *TransactionBatch) New(b *[]Transaction) error

New is to initialize a transactionbatch

type TxBlock

type TxBlock struct {
	ID            uint32
	PrevHash      [32]byte
	PrevFinalHash [32]byte
	ShardID       uint32
	HashID        [32]byte
	MerkleRoot    [32]byte
	Kind          uint32
	Timestamp     int64
	Height        uint32
	TxCnt         uint32
	TxArray       []Transaction
	TxHash        [][32]byte
	TxArrayX      [][SHash]byte
	Sig           RCSign
}

TxBlock introduce the struct of the transaction block

func NewGensisFinalTxBlock

func NewGensisFinalTxBlock(shardID uint32) TxBlock

NewGensisFinalTxBlock is the gensis block

func NewGensisTxBlock

func NewGensisTxBlock() TxBlock

NewGensisTxBlock is the gensis block

func (*TxBlock) Decode

func (a *TxBlock) Decode(buf *[]byte, full int) error

Decode converts bytes into block data

func (*TxBlock) Encode

func (a *TxBlock) Encode(tmp *[]byte, full int)

Encode converts the block data into bytes

func (*TxBlock) Hash

func (a *TxBlock) Hash() [32]byte

Hash generates the 32bits hash of one Tx block

func (*TxBlock) MakeStartBlock

func (a *TxBlock) MakeStartBlock(ID uint32, b *[][32]byte, preHash [32]byte, prk *ecdsa.PrivateKey, h uint32) error

MakeStartBlock creates the transaction blocks given verified transactions

func (*TxBlock) MakeTxBlock

func (a *TxBlock) MakeTxBlock(ID uint32, b *[]Transaction, preHash [32]byte, prk *ecdsa.PrivateKey, h uint32, kind uint32, preFH *[32]byte, shardID uint32) error

MakeTxBlock creates the transaction blocks given verified transactions

func (*TxBlock) Print

func (a *TxBlock) Print()

Print output the block data

func (*TxBlock) Serial

func (a *TxBlock) Serial() []byte

Serial outputs a serial of []byte

func (*TxBlock) Transform

func (a *TxBlock) Transform() error

Transform is to minimize the txdecset size

func (*TxBlock) Verify

func (a *TxBlock) Verify(puk *ecdsa.PublicKey) (bool, error)

Verify verify the signature of the Txblock

type TxDecSet

type TxDecSet struct {
	ID         uint32
	Round      uint32
	HashID     [32]byte
	MemCnt     uint32
	ShardIndex uint32
	MemD       []TxDecision
	TxCnt      uint32
	TxArray    [][32]byte
	TxArrayX   [][SHash]byte
	Sig        RCSign
}

TxDecSet is the set of all decisions from one shard, signed by leader

func (*TxDecSet) Add

func (a *TxDecSet) Add(b *TxDecision)

Add adds a TxDecision

func (*TxDecSet) Decode

func (a *TxDecSet) Decode(buf *[]byte) error

Decode decode the []byte into TxDecSet

func (*TxDecSet) Encode

func (a *TxDecSet) Encode(tmp *[]byte)

Encode encode the TxDecSet into []byte

func (*TxDecSet) Hash

func (a *TxDecSet) Hash() [32]byte

Hash returns the ID of the TxList

func (*TxDecSet) Print

func (a *TxDecSet) Print()

Print is

func (*TxDecSet) Result

func (a *TxDecSet) Result(index uint32) bool

Result is the result of the index-th transaction

func (*TxDecSet) ResultMiner

func (a *TxDecSet) ResultMiner(index uint32, miner uint32) byte

ResultMiner is the specific result of a miner

func (*TxDecSet) Set

func (a *TxDecSet) Set(b *TxList, x uint32, y int)

Set init an instance of TxDecSet given those parameters

func (*TxDecSet) Sign

func (a *TxDecSet) Sign(prk *ecdsa.PrivateKey)

Sign signs the TxDecSet

func (*TxDecSet) Verify

func (a *TxDecSet) Verify(puk *ecdsa.PublicKey) bool

Verify verifies the TxDecSet

type TxDecision

type TxDecision struct {
	ID       uint32   // miner id what id?  hash256(pubkey)
	HashID   [32]byte // transaction list id
	TxCnt    uint32
	Decision []byte
	Target   uint32
	Single   uint32
	Sig      []RCSign
}

TxDecision is the decisions based on given TxList

func (*TxDecision) Add

func (a *TxDecision) Add(x byte) error

Add adds one decision given the result

func (*TxDecision) Decode

func (a *TxDecision) Decode(buf *[]byte) error

Decode decodes the []byte into TxDecision

func (*TxDecision) Encode

func (a *TxDecision) Encode(tmp *[]byte)

Encode encodes the TxDecision into []byte

func (*TxDecision) Print

func (a *TxDecision) Print()

Print is

func (*TxDecision) Set

func (a *TxDecision) Set(ID uint32, target uint32, single uint32) error

Set initiates the TxDecision given the TxList and the account

func (*TxDecision) Sign

func (a *TxDecision) Sign(prk *ecdsa.PrivateKey, x uint32)

Sign signs the TxDecision

func (*TxDecision) Verify

func (a *TxDecision) Verify(puk *ecdsa.PublicKey, x uint32) bool

Verify the signature using public key

type TxList

type TxList struct {
	ID       uint32
	HashID   [32]byte
	Round    uint32
	TxCnt    uint32
	TxArray  [][32]byte
	TxArrayX [][SHash]byte
	Sig      RCSign
}

TxList is the list of tx sent by Leader to miner for their verification

func (*TxList) AddTx

func (a *TxList) AddTx(tx *Transaction)

AddTx adds the tx into transaction list

func (*TxList) Decode

func (a *TxList) Decode(buf *[]byte) error

Decode decodes the TxList with []byte

func (*TxList) Encode

func (a *TxList) Encode(tmp *[]byte)

Encode returns the byte of a TxList

func (*TxList) Hash

func (a *TxList) Hash() [32]byte

Hash returns the ID of the TxList

func (*TxList) Print

func (a *TxList) Print()

Print is

func (*TxList) Set

func (a *TxList) Set(ID uint32, height uint32)

Set init an instance of TxList given those parameters

func (*TxList) Sign

func (a *TxList) Sign(prk *ecdsa.PrivateKey)

Sign signs the TxList with the leader's private key

func (*TxList) Verify

func (a *TxList) Verify(puk *ecdsa.PublicKey) bool

Verify verify the signature

type UserClient

type UserClient struct {
	IPaddress string
	Prk       ecdsa.PublicKey
	// contains filtered or unexported fields
}

UserClient is the struct for miner and client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL