util

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

ZooBC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. util package contain basic utilities commonly used across the core package

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

ZooBC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Package util (core/util) handle block and transaction common used utility. Transaction Bytes is represented as: {TransactionType(2), Timestamp(8), SenderAccountID(32), RecipientAccountID(32), Fee(8), TransactionBodyLength(8), TransactionBodyBytes(tbl), Signature(64)} tbl: transaction body length Block Bytes is represented as: {Version(4), Timestamp(8), NumberOfTransaction(txNumber), TotalAmount(8), TotalFee(8), TotalCoinbase(8), PayloadLength(8), PayloadHash(custom), BlocksmithPublicKey(32), BlockSeed(custom), PreviousBlockHash(custom), Signature(64)}

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

ZooBC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

ZooBC Copyright (C) 2020 Quasisoft Limited - Hong Kong This file is part of ZooBC <https://github.com/zoobc/zoobc-core>

ZooBC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

ZooBC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ZooBC. If not, see <http://www.gnu.org/licenses/>.

Additional Permission Under GNU GPL Version 3 section 7. As the special exception permitted under Section 7b, c and e, in respect with the Author’s copyright, please refer to this section:

  1. You are free to convey this Program according to GNU GPL Version 3, as long as you respect and comply with the Author’s copyright by showing in its user interface an Appropriate Notice that the derivate program and its source code are “powered by ZooBC”. This is an acknowledgement for the copyright holder, ZooBC, as the implementation of appreciation of the exclusive right of the creator and to avoid any circumvention on the rights under trademark law for use of some trade names, trademarks, or service marks.
  1. Complying to the GNU GPL Version 3, you may distribute the program without any permission from the Author. However a prior notification to the authors will be appreciated.

ZooBC is architected by Roberto Capodieci & Barton Johnston

contact us at roberto.capodieci[at]blockchainzoo.com
and barton.johnston[at]blockchainzoo.com

Core developers that contributed to the current implementation of the software are:

Ahmad Ali Abdilah ahmad.abdilah[at]blockchainzoo.com
Allan Bintoro allan.bintoro[at]blockchainzoo.com
Andy Herman
Gede Sukra
Ketut Ariasa
Nawi Kartini nawi.kartini[at]blockchainzoo.com
Stefano Galassi stefano.galassi[at]blockchainzoo.com

IMPORTANT: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateCumulativeDifficulty

func CalculateCumulativeDifficulty(
	previousBlock *model.Block,
	blocksmithIndex int64,
) (string, error)

CalculateCumulativeDifficulty get the cumulative difficulty of the incoming block based on its blocksmith index

func CalculateNodeOrder

func CalculateNodeOrder(score *big.Int, blockSeed, nodeID int64) *big.Int

CalculateNodeOrder calculate the Node order parameter, used to sort/select the group of blocksmith rewarded for a given block

func GetAddRemoveSpineKeyAction

func GetAddRemoveSpineKeyAction(nodeRegistrationStatus uint32) (publicKeyAction model.SpinePublicKeyAction)

GetAddRemoveSpineKeyAction transcode nodeRegistrationStatus into relative spinekeypublickey acion eg. if node is deleted, the action for this spine public key is "RemoveKey", if registered "AddKey"

func GetBlockID

func GetBlockID(block *model.Block, ct chaintype.ChainType) int64

GetBlockID generate block ID value if haven't return the assigned ID if assigned

func GetBlockIDFromHash

func GetBlockIDFromHash(blockHash []byte) int64

GetBlockIdFromHash returns blockID from given hash

func GetBlockSeed

func GetBlockSeed(nodeID int64, block *model.Block) (int64, error)

GetBlockSeed calculate seed value, the first 8 byte of the digest(previousBlockSeed, nodeID)

func IsBlockIDExist

func IsBlockIDExist(blockIds []int64, expectedBlockID int64) bool

func IsGenesis

func IsGenesis(previousBlockID int64, block *model.Block) bool

Types

type PublishedReceiptUtil

type PublishedReceiptUtil struct {
	PublishedReceiptQuery query.PublishedReceiptQueryInterface
	QueryExecutor         query.ExecutorInterface
}

func NewPublishedReceiptUtil

func NewPublishedReceiptUtil(
	publishedReceiptQuery query.PublishedReceiptQueryInterface,
	queryExecutor query.ExecutorInterface,
) *PublishedReceiptUtil

func (*PublishedReceiptUtil) GetPublishedReceiptByLinkedRMR

func (psu *PublishedReceiptUtil) GetPublishedReceiptByLinkedRMR(root []byte) (*model.PublishedReceipt, error)

func (*PublishedReceiptUtil) GetPublishedReceiptsByBlockHeight

func (psu *PublishedReceiptUtil) GetPublishedReceiptsByBlockHeight(blockHeight uint32) ([]*model.PublishedReceipt, error)

GetPublishedReceiptByBlockHeight get data from published_receipt table by the block height they were published / broadcasted

func (*PublishedReceiptUtil) GetPublishedReceiptsByBlockHeightRange

func (psu *PublishedReceiptUtil) GetPublishedReceiptsByBlockHeightRange(fromBlockHeight, toBlockHeight uint32) ([]*model.PublishedReceipt, error)

GetPublishedReceiptByBlockHeightRange get data from published_receipt table by the block height they were published / broadcasted

func (*PublishedReceiptUtil) InsertPublishedReceipt

func (psu *PublishedReceiptUtil) InsertPublishedReceipt(publishedReceipt *model.PublishedReceipt, tx bool) error

type PublishedReceiptUtilInterface

type PublishedReceiptUtilInterface interface {
	GetPublishedReceiptsByBlockHeight(blockHeight uint32) ([]*model.PublishedReceipt, error)
	GetPublishedReceiptsByBlockHeightRange(fromBlockHeight, toBlockHeight uint32) ([]*model.PublishedReceipt, error)
	GetPublishedReceiptByLinkedRMR(root []byte) (*model.PublishedReceipt, error)
	InsertPublishedReceipt(publishedReceipt *model.PublishedReceipt, tx bool) error
}

PublishedReceiptUtilInterface act as interface for data getter on published_receipt entity

type ReceiptUtil

type ReceiptUtil struct{}

func (*ReceiptUtil) GenerateReceipt

func (ru *ReceiptUtil) GenerateReceipt(
	ct chaintype.ChainType,
	referenceBlock *storage.BlockCacheObject,
	senderPublicKey, recipientPublicKey, datumHash, rmrLinked []byte,
	datumType uint32,
) (*model.Receipt, error)

GenerateReceipt generate receipt object that act as proof of receipt on data. Data received can be block, transaction, etc. generated receipt will not be signed yet (RecipientSignature = nil), will need to be signed using SignReceipt method.

func (*ReceiptUtil) GetNumberOfMaxReceipts

func (ru *ReceiptUtil) GetNumberOfMaxReceipts(numberOfSortedBlocksmiths int) uint32

func (*ReceiptUtil) GetReceiptKey

func (ru *ReceiptUtil) GetReceiptKey(
	dataHash, senderPublicKey []byte,
) ([]byte, error)

func (*ReceiptUtil) GetSignedReceiptBytes

func (ru *ReceiptUtil) GetSignedReceiptBytes(receipt *model.Receipt) []byte

GetSignedReceiptBytes Client task before store into database batch_receipt

func (*ReceiptUtil) GetUnsignedReceiptBytes

func (ru *ReceiptUtil) GetUnsignedReceiptBytes(receipt *model.Receipt) []byte

GetUnsignedReceiptBytes Client task while doing validation signature

type ReceiptUtilInterface

type ReceiptUtilInterface interface {
	GetNumberOfMaxReceipts(numberOfSortedBlocksmiths int) uint32
	GenerateReceipt(
		ct chaintype.ChainType,
		referenceBlock *storage.BlockCacheObject,
		senderPublicKey, recipientPublicKey, datumHash, rmrLinked []byte,
		datumType uint32,
	) (*model.Receipt, error)
	GetUnsignedReceiptBytes(receipt *model.Receipt) []byte
	GetSignedReceiptBytes(receipt *model.Receipt) []byte
	GetReceiptKey(
		dataHash, senderPublicKey []byte,
	) ([]byte, error)
}

Jump to

Keyboard shortcuts

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