hyperledger / fabric-sdk-go

https://wiki.hyperledger.org/display/fabric
Apache License 2.0
910 stars 510 forks source link

How to calculate the block size ? #241

Open s-nadesh opened 1 year ago

s-nadesh commented 1 year ago

One block can have multiple transactions. So i want to calculate the size of the block.

Is it possible ? Kindly guide me.

Thank you !!

iamlzw commented 1 year ago

I think it's a viable solution

        block ,err := ledgerClient.QueryBlock(uint64(0))
        if err != nil{
            fmt.Println(err)
        }
        buf := new (bytes.Buffer)
        err = protolator.DeepMarshalJSON(buf, block)
        fmt.Println(len(buf.Bytes()))

more detail you can refer https://github.com/iamlzw/fabric-sdk-go-samples/blob/master/setup.go queryLedger function.

s-nadesh commented 1 year ago

Okay Thank you . I will check this.