Skip to content

Commit

Permalink
Merge pull request #1419 from 0chain/sprint-1.13
Browse files Browse the repository at this point in the history
Sprint 1.13
  • Loading branch information
dabasov authored Mar 5, 2024
2 parents 3e80614 + a488b0e commit cfe9bea
Show file tree
Hide file tree
Showing 71 changed files with 1,739 additions and 817 deletions.
42 changes: 29 additions & 13 deletions core/sys/fs_mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (mfs *MemFS) Open(name string) (File, error) {

fileName := filepath.Base(name)

file = &MemFile{Name: fileName, Buffer: new(bytes.Buffer), Mode: fs.ModePerm, ModTime: time.Now()}
file = &MemFile{Name: fileName, Mode: fs.ModePerm, ModTime: time.Now()}

mfs.files[name] = file

Expand All @@ -47,7 +47,7 @@ func (mfs *MemFS) OpenFile(name string, flag int, perm os.FileMode) (File, error
}

fileName := filepath.Base(name)
file = &MemFile{Name: fileName, Buffer: new(bytes.Buffer), Mode: perm, ModTime: time.Now()}
file = &MemFile{Name: fileName, Mode: perm, ModTime: time.Now()}

mfs.files[name] = file

Expand All @@ -59,7 +59,7 @@ func (mfs *MemFS) OpenFile(name string, flag int, perm os.FileMode) (File, error
func (mfs *MemFS) ReadFile(name string) ([]byte, error) {
file, ok := mfs.files[name]
if ok {
return file.Buffer.Bytes(), nil
return file.Buffer, nil
}

return nil, os.ErrNotExist
Expand All @@ -68,7 +68,7 @@ func (mfs *MemFS) ReadFile(name string) ([]byte, error) {
// WriteFile writes data to a file named by filename.
func (mfs *MemFS) WriteFile(name string, data []byte, perm os.FileMode) error {
fileName := filepath.Base(name)
file := &MemFile{Name: fileName, Buffer: new(bytes.Buffer), Mode: perm, ModTime: time.Now()}
file := &MemFile{Name: fileName, Mode: perm, ModTime: time.Now()}

mfs.files[name] = file

Expand Down Expand Up @@ -189,10 +189,10 @@ func (mfs *MemChanFS) Stat(name string) (fs.FileInfo, error) {

type MemFile struct {
Name string
Buffer *bytes.Buffer // file content
Mode fs.FileMode // FileInfo.Mode
ModTime time.Time // FileInfo.ModTime
Sys interface{} // FileInfo.Sys
Buffer []byte // file content
Mode fs.FileMode // FileInfo.Mode
ModTime time.Time // FileInfo.ModTime
Sys interface{} // FileInfo.Sys
reader io.Reader
}

Expand All @@ -201,14 +201,28 @@ func (f *MemFile) Stat() (fs.FileInfo, error) {
}
func (f *MemFile) Read(p []byte) (int, error) {
if f.reader == nil {
f.reader = bytes.NewReader(f.Buffer.Bytes())
f.reader = bytes.NewReader(f.Buffer)
}
return f.reader.Read(p)

}
func (f *MemFile) Write(p []byte) (n int, err error) {
return f.Buffer.Write(p)
f.Buffer = append(f.Buffer, p...)
return len(p), nil
}

func (f *MemFile) WriteAt(p []byte, offset int64) (n int, err error) {
if offset < 0 || offset > int64(len(f.Buffer)) {
return 0, io.ErrShortWrite
}

copy(f.Buffer[offset:], p)

return len(p), nil
}

func (f *MemFile) InitBuffer(size int) {
f.Buffer = make([]byte, size)
}

func (f *MemFile) Sync() error {
Expand All @@ -217,7 +231,7 @@ func (f *MemFile) Sync() error {
func (f *MemFile) Seek(offset int64, whence int) (ret int64, err error) {

// always reset it from beginning, it only work for wasm download
f.reader = bytes.NewReader(f.Buffer.Bytes())
f.reader = bytes.NewReader(f.Buffer)

return 0, nil
}
Expand All @@ -236,7 +250,7 @@ func (i *MemFileInfo) Name() string {
return i.name
}
func (i *MemFileInfo) Size() int64 {
return int64(i.f.Buffer.Len())
return int64(len(i.f.Buffer))
}

func (i *MemFileInfo) Mode() fs.FileMode {
Expand Down Expand Up @@ -291,7 +305,9 @@ func (f *MemChanFile) Read(p []byte) (int, error) {

func (f *MemChanFile) Write(p []byte) (n int, err error) {
if f.ChunkWriteSize == 0 {
f.Buffer <- p
data := make([]byte, len(p))
copy(data, p)
f.Buffer <- data
} else {
if cap(f.data) == 0 {
f.data = make([]byte, 0, f.ChunkWriteSize)
Expand Down
1 change: 1 addition & 0 deletions core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const (
STORAGESC_KILL_VALIDATOR = "kill_validator"
STORAGESC_SHUTDOWN_BLOBBER = "shutdown_blobber"
STORAGESC_SHUTDOWN_VALIDATOR = "shutdown_validator"
STORAGESC_RESET_BLOBBER_STATS = "reset_blobber_stats"

MINERSC_LOCK = "addToDelegatePool"
MINERSC_UNLOCK = "deleteFromDelegatePool"
Expand Down
2 changes: 1 addition & 1 deletion core/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
//====== THIS IS AUTOGENERATED FILE. DO NOT MODIFY ========

package version
const VERSIONSTR = "v1.11.5-4-ga759a908"
const VERSIONSTR = "v1.12.1-3-gbc68f654"

11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/hashicorp/golang-lru/v2 v2.0.1
github.com/herumi/bls-go-binary v1.31.0
github.com/hitenjain14/fasthttp v0.0.0-20240229173600-722723e15e17
github.com/influxdata/influxdb v1.8.3
github.com/klauspost/reedsolomon v1.11.8
github.com/lithammer/shortuuid/v3 v3.0.7
Expand All @@ -32,7 +33,7 @@ require (
github.com/uptrace/bunrouter v1.0.20
go.dedis.ch/kyber/v3 v3.1.0
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.16.0
golang.org/x/crypto v0.17.0
golang.org/x/image v0.14.0
golang.org/x/sync v0.5.0
google.golang.org/grpc v1.53.0
Expand All @@ -45,10 +46,12 @@ require (
require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/minio/sha256-simd v1.0.1
github.com/valyala/fasthttp v1.51.0
)

require (
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
Expand Down Expand Up @@ -112,14 +115,12 @@ require (
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.dedis.ch/fixbuf v1.0.3 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand All @@ -128,7 +129,7 @@ require (

require (
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/remeh/sizedwaitgroup v1.0.0
github.com/yusufpapurcu/wmi v1.2.2 // indirect
Expand Down
28 changes: 18 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
Expand Down Expand Up @@ -297,6 +299,14 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/herumi/bls-go-binary v1.31.0 h1:L1goQ2tMtGgpXCg5AwHAdJQpLs/pfnWWEc3Wog6OhmI=
github.com/herumi/bls-go-binary v1.31.0/go.mod h1:O4Vp1AfR4raRGwFeQpr9X/PQtncEicMoOe6BQt1oX0Y=
github.com/hitenjain14/fasthttp v0.0.0-20240201092245-8e4835c0e974 h1:oEjH9SSKBlzwDyYjzZaqRpxo7GlfUJCyRoOk7QHKSDs=
github.com/hitenjain14/fasthttp v0.0.0-20240201092245-8e4835c0e974/go.mod h1:RZMcXy7u4S+E97IXYTe7WHZ3+mCYOh4vys8PkIGZeXk=
github.com/hitenjain14/fasthttp v0.0.0-20240223160417-7458814cf3d0 h1:XCrNCir8+zDo+Ku7B+AXhzFnsJvSelx1YbQQTNpxtqI=
github.com/hitenjain14/fasthttp v0.0.0-20240223160417-7458814cf3d0/go.mod h1:RZMcXy7u4S+E97IXYTe7WHZ3+mCYOh4vys8PkIGZeXk=
github.com/hitenjain14/fasthttp v0.0.0-20240228200624-800f4e3a9663 h1:OS1ehSzPOz32fw+mgLL6f2dHXweh4sEB62jyLVwT7NI=
github.com/hitenjain14/fasthttp v0.0.0-20240228200624-800f4e3a9663/go.mod h1:RZMcXy7u4S+E97IXYTe7WHZ3+mCYOh4vys8PkIGZeXk=
github.com/hitenjain14/fasthttp v0.0.0-20240229173600-722723e15e17 h1:FbyIK0BfvXVZTOxKOe2dlxJqSPSF2ZXOv2Mc7dvS7sc=
github.com/hitenjain14/fasthttp v0.0.0-20240229173600-722723e15e17/go.mod h1:RZMcXy7u4S+E97IXYTe7WHZ3+mCYOh4vys8PkIGZeXk=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8=
Expand Down Expand Up @@ -336,8 +346,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4=
github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
Expand Down Expand Up @@ -527,6 +537,10 @@ github.com/uptrace/bunrouter v1.0.20 h1:jNvYNcJxF+lSYBQAaQjnE6I11Zs0m+3M5Ek7fq/T
github.com/uptrace/bunrouter v1.0.20/go.mod h1:TwT7Bc0ztF2Z2q/ZzMuSVkcb/Ig/d3MQeP2cxn3e1hI=
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa h1:5SqCsI/2Qya2bCzK15ozrqo2sZxkh0FHynJZOTVoV6Q=
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down Expand Up @@ -580,8 +594,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -613,8 +627,6 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPI
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a h1:sYbmY3FwUWCBTodZL1S3JUuOvaW6kM2o+clDzzDNBWg=
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a/go.mod h1:Ede7gF0KGoHlj822RtphAHK1jLdrcuRBZg0sF1Q+SPc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
Expand All @@ -623,8 +635,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -812,8 +822,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
3 changes: 0 additions & 3 deletions mobilesdk/sdk/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build mobile
// +build mobile

package sdk

import (
Expand Down
32 changes: 22 additions & 10 deletions wasmsdk/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ func listObjects(allocationID string, remotePath string, offset, pageLimit int)
if err != nil {
return nil, err
}

return alloc.ListDir(remotePath, sdk.WithListRequestOffset(offset), sdk.WithListRequestPageLimit(pageLimit))
}

func listObjectsFromAuthTicket(allocationID, authTicket, lookupHash string, offset, pageLimit int) (*sdk.ListResult, error) {
alloc, err := getAllocation(allocationID)
if err != nil {
return nil, err
}
return alloc.ListDirFromAuthTicket(authTicket, lookupHash, sdk.WithListRequestOffset(offset), sdk.WithListRequestPageLimit(pageLimit))
}

func cancelUpload(allocationID string, remotePath string) error {
allocationObj, err := getAllocation(allocationID)
if err != nil {
Expand Down Expand Up @@ -873,19 +881,23 @@ func downloadBlocks(allocId string, remotePath, authTicket, lookupHash string, s
defer sys.Files.Remove(localPath) //nolint

wg.Add(1)
err = alloc.DownloadByBlocksToFileHandler(
mf,
remotePath,
startBlock,
endBlock,
10,
false,
statusBar, true)
if authTicket != "" {
err = alloc.DownloadByBlocksToFileHandlerFromAuthTicket(mf, authTicket, lookupHash, startBlock, endBlock, 100, remotePath, false, statusBar, true)
} else {
err = alloc.DownloadByBlocksToFileHandler(
mf,
remotePath,
startBlock,
endBlock,
100,
false,
statusBar, true)
}
if err != nil {
return nil, err
}
wg.Wait()
return mf.Buffer.Bytes(), nil
return mf.Buffer, nil
}

// GetBlobbersList get list of active blobbers, and format them as array json string
Expand Down
26 changes: 25 additions & 1 deletion wasmsdk/chunked_upload_progress_storer.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package main

import "github.com/0chain/gosdk/zboxcore/sdk"
import (
"sync"

"github.com/0chain/gosdk/zboxcore/sdk"
)

// chunkedUploadProgressStorer load and save upload progress
type chunkedUploadProgressStorer struct {
list map[string]*sdk.UploadProgress
lock sync.Mutex
}

// Load load upload progress by id
func (mem *chunkedUploadProgressStorer) Load(id string) *sdk.UploadProgress {
mem.lock.Lock()
defer mem.lock.Unlock()
if mem.list == nil {
mem.list = make(map[string]*sdk.UploadProgress)
return nil
Expand All @@ -24,14 +31,31 @@ func (mem *chunkedUploadProgressStorer) Load(id string) *sdk.UploadProgress {

// Save save upload progress
func (mem *chunkedUploadProgressStorer) Save(up sdk.UploadProgress) {
mem.lock.Lock()
defer mem.lock.Unlock()
if mem.list == nil {
mem.list = make(map[string]*sdk.UploadProgress)
}
mem.list[up.ID] = &up
}

//nolint:golint,unused
func (mem *chunkedUploadProgressStorer) Update(id string, chunkIndex int) {
mem.lock.Lock()
defer mem.lock.Unlock()
if mem.list == nil {
return
}
up, ok := mem.list[id]
if ok {
up.ChunkIndex = chunkIndex
}
}

// Remove remove upload progress by id
func (mem *chunkedUploadProgressStorer) Remove(id string) error {
mem.lock.Lock()
defer mem.lock.Unlock()
delete(mem.list, id)
return nil
}
Loading

0 comments on commit cfe9bea

Please sign in to comment.