blockreader

package module
v0.0.0-...-5c80a74 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2021 License: MIT Imports: 13 Imported by: 0

README

BlockReader

GitHub last commit GitHub language count GitHub top language

BlockReader application extract and showcase the complete data structure of a Block that contains several details for a transaction. The application will require a transaction id to query the ledger to retrieve the associated block. Then the application will follow the Block data structure to read the content of the Block.

Medium writeup : https://medium.com/@deeptiman/whats-inside-the-block-in-hyperledger-fabric-69a0934fef08

Run the application

  1. Compile the application using following commands
    cd /go/src/github.com/blockreader
    go build            
    

    You can see blockreader executable is generated.

  2. Now type following commands to read the Block.

     ./blockreader -txnId="cd2b072c880cdefbea66c5f9d73a5a5eb3c3977e77772fba42cec59204ca2980" -channelId="employeeledger"            
     -txnId : The transaction id to be query to retrieve the Block for that transaction from the ledger.
     -channelId: The network ChannelId
    
  3. After that, you will see the Block details in a JSON format.
    ************* BLOCK READER JSON ************* 
    {
        "BlockHeader": {
            "number": 2,
            "previous_hash": "2e8ddbf2dfd6b90fdadd0f2653f932f9f8bb7922244f991b66fc9ebeff3c63c1",
            "data_hash": "6df36db3c31ac485754d7e840574bf53639539d9b810c433cec143fe234557e8"
        },
        "BlockData": {
            "envelope": {
                "header": {
                    "payload": {
                        "channel_header": {
                            "type": "ENDORSER_TRANSACTION",
                            "version": 0,
                            "channelid": "employeeledger",
                            "txid": "c3d95a4e5606cae3a1aabced9fe532f7f628b2930eb09452f2b0db62f6e6ee0b",
                            "epoch": 0,
                            "extension": {
                                "chaincode_id": {
                                    "path": "",
                                    "name": "employeeledger",
                                    "version": ""
                                }
                            }
                        },
                        "signature_header": {
                            "creator": {
                                "msp_id": "org1.employee.ledger.com",
                                "cert_hash": "-----BEGIN CERTIFICATE-----\nMIICyjCCAnGgAwIBAgIUGjzRUXjNaP8bpU/9B2xjpDRPWRYwCgYIKoZIzj0EAwIw\ngYMxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMSEwHwYDVQQKExhvcmcxLmVtcGxveWVlLmxlZGdlci5jb20x\nJDAiBgNVBAMTG2NhLm9yZzEuZW1wbG95ZWUubGVkZ2VyLmNvbTAeFw0yMDAxMTky\nMDE3MDBaFw0yMTAxMTgyMDIyMDBaMDYxGjALBgNVBAsTBHVzZXIwCwYDVQQLEwRv\ncmcxMRgwFgYDVQQDDA90ZXN0MUBnbWFpbC5jb20wWTATBgcqhkjOPQIBBggqhkjO\nPQMBBwNCAARifA6/HyRpmvTk6oNRCeB8QRWgysaxIxaTd36YHgTqFWlSA0oUE2PI\n2HZ7EiY/AOixTtQGzrAoxYgwpz219LBLo4IBDTCCAQkwDgYDVR0PAQH/BAQDAgeA\nMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFEvpcBUx2KVrXK3HJ/d7wLbYOsWRMCsG\nA1UdIwQkMCKAIGDnIjkscY/5fSt5a+QeZtR7sLnSYbI6t10GiS1huLBJMCQGA1Ud\nEQQdMBuCGWRlZXB0aW1hbnBjLUxlbm92by1HNTAtNDUwdwYIKgMEBQYHCAEEa3si\nYXR0cnMiOnsiaGYuQWZmaWxpYXRpb24iOiJvcmcxIiwiaGYuRW5yb2xsbWVudElE\nIjoidGVzdDFAZ21haWwuY29tIiwiaGYuVHlwZSI6InVzZXIiLCJ1c2VybW9kZSI6\nIkFkbWluIn19MAoGCCqGSM49BAMCA0cAMEQCIDUqcBCkezNYkoOpXzJb5F7ZMsaF\nkamc0bRNCLZy4nlSAiBYodLyCs7iivVonEn49L5GaH7c6zUmQw1hcL9AoGttVw==\n-----END CERTIFICATE-----\n",
                                "certificate": {
                                    "country": [
                                        "US"
                                    ],
                                    "organization": [
                                        "org1.employee.ledger.com"
                                    ],
                                    "organization_unit": null,
                                    "locality": [
                                        "San Francisco"
                                    ],
                                    "province": [
                                        "California"
                                    ],
                                    "serial_number": "",
                                    "not_before": "2020-01-19T20:17:00Z",
                                    "not_after": "2021-01-18T20:22:00Z"
                                }
                            }
                        }
                    }
                },
                "data": {
                    "transaction": {
                        "chaincode_proposal_payload": {
                            "chaincode_invocation_spec": {
                                "chaincode_spec": {
                                    "chaincode_id": "employeeledger",
                                    "chaincode_type": "GOLANG",
                                    "chaincode_args": [
                                        "invoke",
                                        "createUser",
                                        "Deeptiman Pattnaik",
                                        "test1@gmail.com",
                                        "Personal",
                                        "Software",
                                        "90,000",
                                        "Admin"
                                    ]
                                }
                            }
                        },
                        "chaincode_endorsed_action": {
                            "proposal_response_payload": {
                                "proposal_hash": "0597a5c323fa68d26e3063ccf640f8658c19f80454b573866cf0614fc2d57f11",
                                "chaincode_kv_rw_set": {
                                    "reads": {
                                        "Key": "employeeledger",
                                        "version": {
                                            "block_num": 1,
                                            "txnum": 0
                                        }
                                    },
                                    "range_queries_info": {
                                        "startkey": "",
                                        "endkey": "",
                                        "itr_exhausted": false
                                    },
                                    "writes": {
                                        "key": "",
                                        "is_delete": false
                                    },
                                    "metadata_writes": {
                                        "key": "",
                                        "name": ""
                                    }
                                },
                                "chaincode_events": {
                                    "chaincode_id": "employeeledger",
                                    "txid": "c3d95a4e5606cae3a1aabced9fe532f7f628b2930eb09452f2b0db62f6e6ee0b",
                                    "event_name": "addUserInvoke",
                                    "payload": ""
                                }
                            }
                        }
                    }
                }
            }
        },
        "BlockMetaData": {
            "value": null,
            "signature": "MEQCICshHeJiB1d1SdBmOyVaQLBrgmAOsrxwEEUO3ZkbB/gDAiAuGcyGDC/i8ExrfZg0p5zzSP/HnBODqSOe5kucVA0ZQg==",
            "signature_header": {
                "creator": {
                    "msp_id": "employee.ledger.com",
                    "cert_hash": "-----BEGIN CERTIFICATE-----\nMIICJDCCAcqgAwIBAgIQCNM0iKIvFrsC0jQGmS98nzAKBggqhkjOPQQDAjB5MQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEcMBoGA1UEChMTZW1wbG95ZWUubGVkZ2VyLmNvbTEfMB0GA1UEAxMW\nY2EuZW1wbG95ZWUubGVkZ2VyLmNvbTAeFw0yMDAxMTgwODA0MDFaFw0zMDAxMTUw\nODA0MDFaMGAxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYD\nVQQHEw1TYW4gRnJhbmNpc2NvMSQwIgYDVQQDExtvcmRlcmVyLmVtcGxveWVlLmxl\nZGdlci5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASmE81Sa568qPkJHZR5\nsHtTpF7cLqyhNiHg8Qroq1xlZrdUNxBhIKpT1KMEWA8N1e2sr8HgTLZCL+6s/AHp\nKUXRo00wSzAOBgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAi\ngCDdKLH7Qvi6j2qO/O4Qb9iZHSAxS1KcLt/XePcoVfHz4jAKBggqhkjOPQQDAgNI\nADBFAiEA2i5wlHfoVlpPKVTinqcO6a9mqmWoPVf67f6V9XV16kICIDhgn18/hRXD\n7PYTnIUfx6l7ruLU+LuJywzxkKD0AScR\n-----END CERTIFICATE-----\n",
                    "certificate": {
                        "country": [
                            "US"
                        ],
                        "organization": [
                            "employee.ledger.com"
                        ],
                        "organization_unit": null,
                        "locality": [
                            "San Francisco"
                        ],
                        "province": [
                            "California"
                        ],
                        "serial_number": "",
                        "not_before": "2020-01-18T08:04:01Z",
                        "not_after": "2030-01-15T08:04:01Z"
                    }
                }
            }
        }
    }
    
  4. License

    This project is licensed under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CToGoString

func CToGoString(c []byte) string

func GetEnvelopeFromBlock

func GetEnvelopeFromBlock(data []byte) (*common.Envelope, error)

Types

type Block

type Block struct {
	BlockHeader   BlockHeader   `json:block_header`
	BlockData     BlockData     `json:block_data`
	BlockMetaData BlockMetaData `json:block_metadata`
}

type BlockData

type BlockData struct {
	Envelope Envelope `json:"envelope"`
}

func GetBlockData

func GetBlockData(block *common.Block) (BlockData, error)

type BlockHeader

type BlockHeader struct {
	Number       uint64 `json:"number"`
	PreviousHash string `json:"previous_hash"`
	DataHash     string `json:"data_hash"`
}

type BlockMetaData

type BlockMetaData struct {
	Value           []byte          `json:"value"`
	Signature       []byte          `json:"signature"`
	SignatureHeader SignatureHeader `json:"signature_header"`
}

type Certificate

type Certificate struct {
	Country            []string  `json:"country"`
	Organization       []string  `json:"organization"`
	OrganizationalUnit []string  `json:"organization_unit"`
	Locality           []string  `json:"locality"`
	Province           []string  `json:"province"`
	SerialNumber       string    `json:"serial_number"`
	NotBefore          time.Time `json:"not_before"`
	NotAfter           time.Time `json:"not_after"`
}

type ChaincodeEndorsedAction

type ChaincodeEndorsedAction struct {
	ProposalResponsePayload ProposalResponsePayload `json:"proposal_response_payload"`
}

func GetChainCodeEndorsedAction

func GetChainCodeEndorsedAction(chaincodeActionPayload *peer.ChaincodeActionPayload) (ChaincodeEndorsedAction, error)

type ChaincodeEvents

type ChaincodeEvents struct {
	ChaincodeId string `json:"chaincode_id"`
	TxId        string `json:"txid"`
	EventName   string `json:"event_name"`
	Payload     string `json:"payload"`
}

type ChaincodeHeaderExtension

type ChaincodeHeaderExtension struct {
	ChaincodeId ChaincodeID `json:"chaincode_id"`
}

type ChaincodeID

type ChaincodeID struct {
	Path    string `json:"path"`
	Name    string `json:"name"`
	Version string `json:"version"`
}

type ChaincodeInvocationSpec

type ChaincodeInvocationSpec struct {
	ChaincodeSpec ChaincodeSpec `json:"chaincode_spec"`
}

type ChaincodeKVRWSet

type ChaincodeKVRWSet struct {
	Reads            KVRead             `json:"reads"`
	RangeQueriesInfo RangeQueryInfo     `json:"range_queries_info"`
	Writes           []*kvrwset.KVWrite `json:"writes"`
	MetadataWrites   KVMetadataWrite    `json:"metadata_writes"`
}

func GetKVRWSetJson

func GetKVRWSetJson(chaincodeAction *peer.ChaincodeAction) (ChaincodeKVRWSet, error)

type ChaincodeProposalPayload

type ChaincodeProposalPayload struct {
	ChaincodeInvocationSpec ChaincodeInvocationSpec `json:"chaincode_invocation_spec"`
}

func GetChainCodeProposalPayload

func GetChainCodeProposalPayload(chaincodeActionPayload *peer.ChaincodeActionPayload) (ChaincodeProposalPayload, error)

type ChaincodeSpec

type ChaincodeSpec struct {
	ChaincodeId   string   `json:"chaincode_id"`
	ChaincodeType string   `json:"chaincode_type"`
	ChaincodeArgs []string `json:"chaincode_args"`
}

type ChannelHeader

type ChannelHeader struct {
	Type      string                   `json:"type"`
	Version   int32                    `json:"version"`
	ChannelId string                   `json:"channelid"`
	TxId      string                   `json:"txid"`
	Epoch     uint64                   `json:"epoch"`
	Extension ChaincodeHeaderExtension `json:"extension"`
}

func GetChannelHeaderJson

func GetChannelHeaderJson(channelHeader *common.ChannelHeader) (ChannelHeader, error)

type Creator

type Creator struct {
	Mspid       string      `json:"msp_id"`
	CertHash    string      `json:"cert_hash"`
	Certificate Certificate `json:"certificate"`
}

type Data

type Data struct {
	Transactions []Transaction `json:"transaction"`
}

type Envelope

type Envelope struct {
	Header Header `json:"header"`
	Data   Data   `json:"data"`
}
type Header struct {
	Payload Payload `json:"payload"`
}

type KVMetadataWrite

type KVMetadataWrite struct {
	Key  string `json:"key"`
	Name string `json:"name"`
}

type KVRead

type KVRead struct {
	Key     string  `json:"key`
	Version Version `json:"version"`
}

type KVWrite

type KVWrite struct {
	Key      string `json:"key"`
	IsDelete bool   `json:"is_delete"`
}

type Payload

type Payload struct {
	ChannelHeader   ChannelHeader   `json:"channel_header"`
	SignatureHeader SignatureHeader `json:"signature_header"`
}

func GetPayloadJson

func GetPayloadJson(payload *common.Payload) (Payload, error)

type ProposalResponsePayload

type ProposalResponsePayload struct {
	ProposalHash     string           `json:"proposal_hash"`
	ChaincodeKVRWSet ChaincodeKVRWSet `json:"chaincode_kv_rw_set"`
	ChaincodeEvents  ChaincodeEvents  `json:"chaincode_events"`
}

type RangeQueryInfo

type RangeQueryInfo struct {
	StartKey     string `json:"startkey"`
	EndKey       string `json:"endkey"`
	ItrExhausted bool   `json:"itr_exhausted"`
}

type SignatureHeader

type SignatureHeader struct {
	Creator Creator `json:"creator"`
}

func GetSignatureHeaderJson

func GetSignatureHeaderJson(signatureHeader *common.SignatureHeader) (SignatureHeader, error)

type Transaction

type Transaction struct {
	ChaincodeProposalPayload ChaincodeProposalPayload `json:"chaincode_proposal_payload"`
	ChaincodeEndorsedAction  ChaincodeEndorsedAction  `json:"chaincode_endorsed_action"`
}

func GetTransactionJson

func GetTransactionJson(chaincodeActionPayload *peer.ChaincodeActionPayload) (Transaction, error)

type Version

type Version struct {
	BlockNum uint64 `json:"block_num"`
	TxNum    uint64 `json:"txnum"`
}

Jump to

Keyboard shortcuts

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