Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliqun committed Aug 20, 2024
1 parent dfd45f3 commit b40ce67
Show file tree
Hide file tree
Showing 16 changed files with 685 additions and 903 deletions.
22 changes: 21 additions & 1 deletion core/file.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package core

import (
"errors"
"io"
"os"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -74,6 +76,24 @@ func Open(name string) (*File, error) {
}, nil
}

// MerkleRoot returns the merkle root hash of a file on disk
func MerkleRoot(filename string) (common.Hash, error) {
file, err := Open(filename)
if err != nil {
return common.Hash{}, errors.WithMessage(err, "failed to open file")
}
defer file.Close()

// Generate the Merkle tree from the file content
tree, err := MerkleTree(file)
if err != nil {
return common.Hash{}, errors.WithMessage(err, "failed to create merkle tree")
}

// Return the root hash of the Merkle tree
return tree.Root(), nil
}

func (file *File) Close() error {
return file.underlying.Close()
}
Expand Down
27 changes: 1 addition & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require (
github.com/gin-contrib/cors v1.7.2
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.22.0
github.com/google/btree v1.1.2
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/ipfs/go-unixfsnode v1.9.0
github.com/openweb3/go-rpc-provider v0.3.3
github.com/openweb3/web3go v0.2.9
github.com/pkg/errors v0.9.1
Expand All @@ -24,7 +24,6 @@ require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd v0.24.0 // indirect
Expand Down Expand Up @@ -76,41 +75,24 @@ require (
github.com/holiman/uint256 v1.3.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-bitfield v1.1.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-ipfs-chunker v0.0.5 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipld/go-codec-dagpb v1.6.0 // indirect
github.com/ipld/go-ipld-prime v0.21.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mcuadros/go-defaults v1.2.0 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/mitchellh/pointerstructure v1.2.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/openweb3/go-ethereum-hdwallet v0.1.0 // indirect
github.com/openweb3/go-sdk-common v0.0.0-20240627072707-f78f0155ab34 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
Expand All @@ -124,7 +106,6 @@ require (
github.com/rs/cors v1.7.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
Expand All @@ -137,12 +118,7 @@ require (
github.com/urfave/cli/v2 v2.25.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.40.0 // indirect
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
Expand All @@ -154,6 +130,5 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading

0 comments on commit b40ce67

Please sign in to comment.