MCPcopy Create free account
hub / github.com/ethstorage/es-node / GetBlob

Method GetBlob

ethstorage/node/es_api.go:42–86  ·  view source on GitHub ↗
(kvIndex uint64, blobHash common.Hash, decodeType DecodeType, off, size uint64)

Source from the content-addressed store, hash-verified

40}
41
42func (api *esAPI) GetBlob(kvIndex uint64, blobHash common.Hash, decodeType DecodeType, off, size uint64) (hexutil.Bytes, error) {
43 blob := api.dl.Cache.GetKeyValueByIndex(kvIndex, blobHash)
44
45 if blob == nil {
46 commit, _, err := api.sm.TryReadMeta(kvIndex)
47 if err != nil {
48 return nil, err
49 }
50
51 if err := ethstorage.CompareCommits(blobHash.Bytes(), commit); err != nil {
52 return nil, err
53 }
54
55 readCommit := common.Hash{}
56 copy(readCommit[0:ethstorage.HashSizeInContract], blobHash[0:ethstorage.HashSizeInContract])
57
58 var found bool
59 blob, found, err = api.sm.TryRead(kvIndex, int(api.sm.MaxKvSize()), readCommit)
60 if err != nil {
61 return nil, err
62 }
63 if !found {
64 return nil, ethereum.NotFound
65 }
66 } else {
67 blob = api.sm.DecodeBlob(blob, blobHash, kvIndex, api.sm.MaxKvSize())
68 }
69
70 ret := blob
71
72 if decodeType == PaddingPer31Bytes {
73 ret = utils.DecodeBlob(blob)
74 } else if decodeType == OptimismCompact {
75 var err error
76 if ret, err = utils.ToData(blob); err != nil {
77 return nil, err
78 }
79 }
80
81 if len(ret) < int(off+size) {
82 return nil, errors.New("beyond the range of blob size")
83 }
84
85 return ret[off : off+size], nil
86}

Callers

nothing calls this directly

Calls 8

CompareCommitsFunction · 0.92
DecodeBlobFunction · 0.92
ToDataFunction · 0.92
DecodeBlobMethod · 0.80
GetKeyValueByIndexMethod · 0.65
TryReadMetaMethod · 0.65
TryReadMethod · 0.65
MaxKvSizeMethod · 0.65

Tested by

no test coverage detected