blocklib

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TxValidationCode_name = map[int32]string{
	0:   "VALID",
	1:   "NIL_ENVELOPE",
	2:   "BAD_PAYLOAD",
	3:   "BAD_COMMON_HEADER",
	4:   "BAD_CREATOR_SIGNATURE",
	5:   "INVALID_ENDORSER_TRANSACTION",
	6:   "INVALID_CONFIG_TRANSACTION",
	7:   "UNSUPPORTED_TX_PAYLOAD",
	8:   "BAD_PROPOSAL_TXID",
	9:   "DUPLICATE_TXID",
	10:  "ENDORSEMENT_POLICY_FAILURE",
	11:  "MVCC_READ_CONFLICT",
	12:  "PHANTOM_READ_CONFLICT",
	13:  "UNKNOWN_TX_TYPE",
	14:  "TARGET_CHAIN_NOT_FOUND",
	15:  "MARSHAL_TX_ERROR",
	16:  "NIL_TXACTION",
	17:  "EXPIRED_CHAINCODE",
	18:  "CHAINCODE_VERSION_CONFLICT",
	19:  "BAD_HEADER_EXTENSION",
	20:  "BAD_CHANNEL_HEADER",
	21:  "BAD_RESPONSE_PAYLOAD",
	22:  "BAD_RWSET",
	23:  "ILLEGAL_WRITESET",
	24:  "INVALID_WRITESET",
	25:  "INVALID_CHAINCODE",
	254: "NOT_VALIDATED",
	255: "INVALID_OTHER_REASON",
}

Functions

func BlockHeaderBytes

func BlockHeaderBytes(b *common.BlockHeader) []byte

func CheckIntegrity

func CheckIntegrity(previousblock, currentblock *Block) bool

CheckIntegrity checks that two blocks are 'connected'. This func compares current block header 'PreviousHash' (hash of block number, data and PreviousHash - think of it as a link to the previous block) with actual previous block header hash.

Types

type Action

type Action struct {
	Payload         *peer.ChaincodeActionPayload
	SignatureHeader *common.SignatureHeader
}

func (*Action) ChaincodeAction

func (a *Action) ChaincodeAction() (*peer.ChaincodeAction, error)

ChaincodeAction returns a pointer to peer.ChaincodeAction that contains and actions the events generated by the execution of the chaincode.

func (*Action) ChaincodeActionPayload

func (a *Action) ChaincodeActionPayload() *peer.ChaincodeActionPayload

ChaincodeActionPayload returns pointer to peer.ChaincodeActionPayload. ChaincodeActionPayload is the message to be used for the TransactionAction's payload when the Header's type is set to CHAINCODE. It carries the chaincodeProposalPayload and an endorsed action to apply to the ledger.

func (*Action) ChaincodeEvent

func (a *Action) ChaincodeEvent() (*peer.ChaincodeEvent, error)

ChaincodeEvent returns a pointer to peer.ChaincodeEvent that contains events info.

func (*Action) ChaincodeInput

func (a *Action) ChaincodeInput() ([]string, error)

ChaincodeInput retrieves chaincode input, format and returns it as string slice.

func (*Action) ChaincodeProposalPayload

func (a *Action) ChaincodeProposalPayload() (*peer.ChaincodeProposalPayload, error)

ChaincodeProposalPayload returns a pointer to peer.ChaincodeProposalPayload. This method should be used for retrieving input or transient data of the chaincode invocation.

func (*Action) CreatorCertBytes

func (a *Action) CreatorCertBytes() ([]byte, error)

CreatorCertBytes returns pem-encoded certificate of transaction creator.

func (*Action) CreatorCertHashHex

func (a *Action) CreatorCertHashHex() (string, error)

CreatorCertHashHex returns hex-encoded SHA256 hash of pem-encoded certificate of transaction creator.

func (*Action) CreatorMSPID

func (a *Action) CreatorMSPID() (string, error)

CreatorMSPID returns MSP ID of the organization the creator belongs to.

func (*Action) Decorations

func (a *Action) Decorations() (map[string][]byte, error)

Decorations returns additional data (if applicable) about the proposal that originated from the peer. This data is set by the decorators of the peer, which append or mutate the chaincode input passed to the chaincode.

unfortunately decorations are always nil in the current HLF versions https://github.com/hyperledger/fabric/blob/master/core/endorser/support.go#L121

func (*Action) Endorsements

func (a *Action) Endorsements() []*peer.Endorsement

Endorsements returns a slice of pointers to peer.Endorsement. An endorsement is a signature of an endorser over a proposal response. By producing an endorsement message, an endorser implicitly "approves" that proposal response and the actions contained therein. When enough endorsements have been collected, a transaction can be generated out of a set of proposal responses. Note that this message only contains an identity and a signature but no signed payload. This is intentional because endorsements are supposed to be collected in a transaction, and they are all expected to endorse a single proposal response/action (many endorsements over a single proposal response).

func (*Action) IsInit

func (a *Action) IsInit() (bool, error)

IsInit returns true (is Init invoked) or false (not Init invoked). is_init is used for the application to signal that an invocation is to be routed to the legacy 'Init' function for compatibility with chaincodes which handled Init in the old way. New applications should manage their initialized state themselves.

func (*Action) ProposalHash

func (a *Action) ProposalHash() ([]byte, error)

ProposalHash returns SHA256 hash of common.ChannelHeader, common.SignatureHeader and peer.ProposalResponsePayload.

func (*Action) ProposalResponsePayload

func (a *Action) ProposalResponsePayload() (*peer.ProposalResponsePayload, error)

ProposalResponsePayload returns a pointer to peer.ProposalResponsePayload. ProposalResponsePayload is the payload of a proposal response. This message is the "bridge" between the client's request and the endorser's action in response to that request. Concretely, for chaincodes, it contains a hashed representation of the proposal (proposalHash) and a representation of the chaincode state changes and events inside the extension field.

func (*Action) RWSets

func (a *Action) RWSets() ([]RwSet, error)

RWSets returns to a read-write sets slice.

func (*Action) TransientMap

func (a *Action) TransientMap() (map[string][]byte, error)

TransientMap contains data (e.g. cryptographic material) that might be used to implement some form of application-level confidentiality. The contents of this field are supposed to always be omitted from the transaction and excluded from the ledger.

type BFTSerializedIdentity

type BFTSerializedIdentity struct {
	ConsenterId uint64
	Identity    msp.SerializedIdentity
}

func GetBFTOrderersIdentities

func GetBFTOrderersIdentities(cli *ledger.Client, blk *common.Block) ([]BFTSerializedIdentity, error)

type Block

type Block struct {
	Data [][]byte

	Metadata [][]byte
	// contains filtered or unexported fields
}

Block contains all the necessary information about the blockchain block

func FromBFTFabricBlock

func FromBFTFabricBlock(cli *ledger.Client, block *common.Block) (*Block, error)

FromBFTFabricBlock converts common.Block produced by BFT-orderer to blocklib.Block.

func FromBFTFabricBlockWithoutOrdererIdenities

func FromBFTFabricBlockWithoutOrdererIdenities(block *common.Block) (*Block, error)

func FromFabricBlock

func FromFabricBlock(block *common.Block) (*Block, error)

FromFabricBlock converts common.Block to blocklib.Block. Such conversion is necessary for further comfortable work with information from the block.

func (*Block) DataHash

func (b *Block) DataHash() []byte

DataHash returns hash of the this block's data.

func (*Block) HeaderHash

func (b *Block) HeaderHash() []byte

HeaderHash returns hash of the this block's header.

func (*Block) IsConfig

func (b *Block) IsConfig() bool

IsConfig returns a boolean value that indicates whether the block is a configuration block.

func (*Block) LastConfig

func (b *Block) LastConfig() (uint64, error)

LastConfig returns last configuration block index for provided block.

func (*Block) Number

func (b *Block) Number() uint64

Number returns a block number.

func (*Block) OrderersSignatures

func (b *Block) OrderersSignatures() []BlockSignature

OrderersSignatures returns signatures of orderers, their cert, MSP ID and nonce.

func (*Block) PreviousHash

func (b *Block) PreviousHash() []byte

PreviousHash returns hash of the previous block.

func (*Block) Txs

func (b *Block) Txs() ([]Tx, error)

func (*Block) TxsFromOrdererBlock

func (b *Block) TxsFromOrdererBlock() ([]Tx, error)

TxsFromOrdererBlock returns transactions from orderer block without validation code and validation status, because odrerer ledger does not contain them.

type BlockSignature

type BlockSignature struct {
	Cert      []byte // pem-encoded
	MSPID     string
	Signature []byte
	Nonce     []byte
}

BlockSignature contains nonce, cert, MSP ID and signature of the orderer which signed the block

type RwSet

type RwSet struct {
	NameSpace                    string                                `json:"namespace"`
	KVRWSet                      kvrwset.KVRWSet                       `json:"kv_rw_set"`
	CollectionHashedReadWriteSet []*rwset.CollectionHashedReadWriteSet `json:"collection_hashed_rw_set"`
}

type Tx

type Tx struct {
	Data []byte
	// contains filtered or unexported fields
}

func GetTx

func GetTx(block *common.Block, txNumber int) *Tx

func (*Tx) Actions

func (tx *Tx) Actions() ([]Action, error)

GetTransaction returns slice of the Action structs

func (*Tx) CfgEnvLastUpdateCreatorSignatureBytes

func (tx *Tx) CfgEnvLastUpdateCreatorSignatureBytes() ([]byte, error)

CfgEnvLastUpdateCreatorSignatureBytes extracts signature of transaction creator as bytes slice.

func (*Tx) CfgEnvLastUpdateCreatorSignatureHex

func (tx *Tx) CfgEnvLastUpdateCreatorSignatureHex() (string, error)

CfgEnvLastUpdateCreatorSignatureHex extracts signature of transaction creator as hex-encoded string.

func (*Tx) ChaincodeId

func (tx *Tx) ChaincodeId() (*peer.ChaincodeID, error)

ChaincodeId returns peer.ChaincodeID (name, version and path) of the target chaincode (only if it's type is common.HeaderType_ENDORSER_TRANSACTION).

func (*Tx) ChannelHeader

func (tx *Tx) ChannelHeader() (*common.ChannelHeader, error)

ChannelHeader returns pointer to common.ChannelHeader of the transaction.

func (*Tx) ConfigEnvelope

func (tx *Tx) ConfigEnvelope() (*common.ConfigEnvelope, error)

ConfigEnvelope returns pointer to common.ConfigEnvelope. common.Envelope contains config and last update payload.

func (*Tx) ConfigEnvelopeLastUpdatePayload

func (tx *Tx) ConfigEnvelopeLastUpdatePayload() (*common.Payload, error)

ConfigEnvelopeLastUpdatePayload payload of last config update.

func (*Tx) ConfigGroup

func (tx *Tx) ConfigGroup() (*common.ConfigGroup, error)

ConfigGroup returns a pointer to common.ConfigGroup. ConfigGroup is the hierarchical data structure for holding config.

func (*Tx) ConfigSequence

func (tx *Tx) ConfigSequence() (uint64, error)

ConfigSequence returns sequence number of config.

func (*Tx) ConfigUpdate

func (tx *Tx) ConfigUpdate() (*common.ConfigUpdate, error)

ConfigUpdate extracts configuration transaction info from raw transaction.

func (*Tx) Creator

func (tx *Tx) Creator() (string, []byte, error)

Creator can be used to extract tx creator's MSP ID and PEM-encoded certificate.

func (*Tx) CreatorSignatureBytes

func (tx *Tx) CreatorSignatureBytes() ([]byte, error)

CreatorSignatureBytes extracts signature of transaction creator as bytes slice.

func (*Tx) CreatorSignatureHexString

func (tx *Tx) CreatorSignatureHexString() (string, error)

CreatorSignatureHexString extracts signature of transaction creator as hex-encoded string.

func (*Tx) Envelope

func (tx *Tx) Envelope() (*common.Envelope, error)

Envelope returns pointer to common.Envelope. common.Envelope contains payload with a signature.

func (*Tx) Epoch

func (tx *Tx) Epoch() (uint64, error)

Epoch returns the epoch in which this header was generated, where epoch is defined based on block height Epoch in which the response has been generated. This field identifies a logical window of time. A proposal response is accepted by a peer only if two conditions hold: 1. the epoch specified in the message is the current epoch 2. this message has been only seen once during this epoch (i.e. it hasn't been replayed)

Always equals to 0 because of this reason: https://github.com/hyperledger/fabric/blob/release-2.1/core/common/validation/msgvalidation.go#L110

func (*Tx) IsValid

func (tx *Tx) IsValid() bool

IsValid checks if transaction with specified number (txNumber int) in block (block *common.Block) is valid or not and returns corresponding bool value.

func (*Tx) Payload

func (tx *Tx) Payload() (*common.Payload, error)

Payload returns pointer to common.Payload. common.Payload is the message contents (and header to allow for signing).

func (*Tx) PeerTransaction

func (tx *Tx) PeerTransaction() (*peer.Transaction, error)

PeerTransaction returns pointer to peer.Transaction. The transaction to be sent to the ordering service. A transaction contains one or more TransactionAction. Each TransactionAction binds a proposal to potentially multiple actions. The transaction is atomic meaning that either all actions in the transaction will be committed or none will. Note that while a Transaction might include more than one Header, the Header.creator field must be the same in each. A single client is free to issue a number of independent Proposal, each with their header (Header) and request payload (ChaincodeProposalPayload). Each proposal is independently endorsed generating an action (ProposalResponsePayload) with one signature per Endorser. Any number of independent proposals (and their action) might be included in a transaction to ensure that they are treated atomically.

func (*Tx) SignatureHeader

func (tx *Tx) SignatureHeader() (*common.SignatureHeader, error)

SignatureHeader returns pointer to common.SignatureHeader that contains nonce and creator (msp.SerializedIdentity).

func (*Tx) Timestamp

func (tx *Tx) Timestamp() (time.Time, error)

Timestamp returns the local time when the message was created by the sender.

func (*Tx) TlsCertHash

func (tx *Tx) TlsCertHash() ([]byte, error)

TlsCertHash returns hash of the client's TLS certificate (if mutual TLS is employed).

func (*Tx) TxId

func (tx *Tx) TxId() (string, error)

TxId returns transaction ID.

func (*Tx) ValidationCode

func (tx *Tx) ValidationCode() int32

ValidationCode returns validation code for transaction with specified number (txNumber int) in block (block *common.Block).

func (*Tx) ValidationStatus

func (tx *Tx) ValidationStatus() string

ValidationStatus returns string representation of validation code for transaction with specified number (txNumber int) in block (block *common.Block).

type TxValidationCode

type TxValidationCode int32
const (
	TxValidationCode_VALID                        TxValidationCode = 0
	TxValidationCode_NIL_ENVELOPE                 TxValidationCode = 1
	TxValidationCode_BAD_PAYLOAD                  TxValidationCode = 2
	TxValidationCode_BAD_COMMON_HEADER            TxValidationCode = 3
	TxValidationCode_BAD_CREATOR_SIGNATURE        TxValidationCode = 4
	TxValidationCode_INVALID_ENDORSER_TRANSACTION TxValidationCode = 5
	TxValidationCode_INVALID_CONFIG_TRANSACTION   TxValidationCode = 6
	TxValidationCode_UNSUPPORTED_TX_PAYLOAD       TxValidationCode = 7
	TxValidationCode_BAD_PROPOSAL_TXID            TxValidationCode = 8
	TxValidationCode_DUPLICATE_TXID               TxValidationCode = 9
	TxValidationCode_ENDORSEMENT_POLICY_FAILURE   TxValidationCode = 10
	TxValidationCode_MVCC_READ_CONFLICT           TxValidationCode = 11
	TxValidationCode_PHANTOM_READ_CONFLICT        TxValidationCode = 12
	TxValidationCode_UNKNOWN_TX_TYPE              TxValidationCode = 13
	TxValidationCode_TARGET_CHAIN_NOT_FOUND       TxValidationCode = 14
	TxValidationCode_MARSHAL_TX_ERROR             TxValidationCode = 15
	TxValidationCode_NIL_TXACTION                 TxValidationCode = 16
	TxValidationCode_EXPIRED_CHAINCODE            TxValidationCode = 17
	TxValidationCode_CHAINCODE_VERSION_CONFLICT   TxValidationCode = 18
	TxValidationCode_BAD_HEADER_EXTENSION         TxValidationCode = 19
	TxValidationCode_BAD_CHANNEL_HEADER           TxValidationCode = 20
	TxValidationCode_BAD_RESPONSE_PAYLOAD         TxValidationCode = 21
	TxValidationCode_BAD_RWSET                    TxValidationCode = 22
	TxValidationCode_ILLEGAL_WRITESET             TxValidationCode = 23
	TxValidationCode_INVALID_WRITESET             TxValidationCode = 24
	TxValidationCode_INVALID_CHAINCODE            TxValidationCode = 25
	TxValidationCode_NOT_VALIDATED                TxValidationCode = 254
	TxValidationCode_INVALID_OTHER_REASON         TxValidationCode = 255
)

type TxValidationFlags

type TxValidationFlags []uint8

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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