Skip to content

Commit

Permalink
refactor 3
Browse files Browse the repository at this point in the history
  • Loading branch information
smaulik13 committed Jan 16, 2025
1 parent b59dcf4 commit fcca97e
Show file tree
Hide file tree
Showing 37 changed files with 107 additions and 232 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
)

require (
github.com/0chain/gosdk_common v0.0.0-20250116114303-c44047234606
github.com/0chain/gosdk_common v0.0.0-20250116161245-a631a8c4c9fe
github.com/hack-pad/go-webworkers v0.1.0
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/minio/sha256-simd v1.0.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ github.com/0chain/gosdk_common v0.0.0-20250108074831-524b0ec9b7cd h1:zeLdGO7e5Ov
github.com/0chain/gosdk_common v0.0.0-20250108074831-524b0ec9b7cd/go.mod h1:A6zAa6S8jWML2razteUYtk9aINjHW4u8MjFKITgIdp4=
github.com/0chain/gosdk_common v0.0.0-20250116114303-c44047234606 h1:/pEJYnH04BoG5UJsQ+k74F/rJOtehXOgMVbB44h1gAY=
github.com/0chain/gosdk_common v0.0.0-20250116114303-c44047234606/go.mod h1:5MtnciUdibSOd2nDEWw346eWXmvpZZAywwrgFm/qmKM=
github.com/0chain/gosdk_common v0.0.0-20250116160841-eeec3c6a9fcd h1:LbZTG/mIwxmR1mcS5oNsDh0hsnrRLNt0u/6/mqg8V/A=
github.com/0chain/gosdk_common v0.0.0-20250116160841-eeec3c6a9fcd/go.mod h1:5MtnciUdibSOd2nDEWw346eWXmvpZZAywwrgFm/qmKM=
github.com/0chain/gosdk_common v0.0.0-20250116161245-a631a8c4c9fe h1:opO2O58fZh2Ca1rdHMNRCkSTys95AOnpCd3WUapgeFU=
github.com/0chain/gosdk_common v0.0.0-20250116161245-a631a8c4c9fe/go.mod h1:5MtnciUdibSOd2nDEWw346eWXmvpZZAywwrgFm/qmKM=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
Expand Down
2 changes: 1 addition & 1 deletion mobilesdk/zbox/models.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zbox

import (
"github.com/0chain/gosdk/core/transaction"
"github.com/0chain/gosdk_common/core/transaction"
)

type StatusCallbackMocked interface {
Expand Down
2 changes: 1 addition & 1 deletion mobilesdk/zbox/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"strings"
"time"

"github.com/0chain/gosdk/constants"
"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/0chain/gosdk/zboxcore/logger"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/0chain/gosdk_common/constants"
)

type fileResp struct {
Expand Down
2 changes: 1 addition & 1 deletion mobilesdk/zbox/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"time"

"github.com/0chain/gosdk/core/transaction"
"github.com/0chain/gosdk_common/core/transaction"

"github.com/0chain/gosdk/zboxcore/sdk"
)
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/auth_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"fmt"
"syscall/js"

"github.com/0chain/gosdk/zcncore"
"github.com/0chain/gosdk_common/core/sys"
"github.com/0chain/gosdk_common/wasmsdk/jsbridge"
"github.com/0chain/gosdk_common/zcncore"
)

type AuthCallbackFunc func(msg string) string
Expand Down
4 changes: 2 additions & 2 deletions wasmsdk/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"syscall/js"
"time"

"github.com/0chain/gosdk/constants"
"github.com/0chain/gosdk_common/constants"
"github.com/0chain/gosdk_common/core/client"
"github.com/0chain/gosdk_common/core/common"
"github.com/0chain/gosdk_common/core/encryption"
Expand All @@ -25,9 +25,9 @@ import (

"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/0chain/gosdk/zboxcore/zboxutil"
"github.com/0chain/gosdk_common/core/transaction"
"github.com/0chain/gosdk_common/wasmsdk/jsbridge"
"github.com/0chain/gosdk_common/zboxcore/zboxutil"

"github.com/hack-pad/go-webworkers/worker"
)
Expand Down
13 changes: 7 additions & 6 deletions wasmsdk/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"encoding/base64"
"encoding/json"
"github.com/0chain/gosdk/core/client"
"github.com/0chain/gosdk/zcnbridge"
"github.com/0chain/gosdk/zcnbridge/errors"
"github.com/0chain/gosdk/zcnbridge/log"
"github.com/0chain/gosdk/zcncore"
"github.com/ethereum/go-ethereum/ethclient"
"path"
"strconv"

"github.com/0chain/gosdk_common/core/client"
"github.com/0chain/gosdk_common/zcnbridge"
"github.com/0chain/gosdk_common/zcnbridge/errors"
"github.com/0chain/gosdk_common/zcnbridge/log"
"github.com/0chain/gosdk_common/zcncore"
"github.com/ethereum/go-ethereum/ethclient"
)

var bridge *zcnbridge.BridgeClient //nolint:unused
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/chunked_upload_progress_storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

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

// chunkedUploadProgressStorer load and save upload progress
Expand Down
4 changes: 2 additions & 2 deletions wasmsdk/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"
"sync"

"github.com/0chain/gosdk/core/common"
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/gosdk_common/core/common"
"github.com/0chain/gosdk_common/zcncore"
"github.com/uptrace/bunrouter"
)

Expand Down
3 changes: 2 additions & 1 deletion wasmsdk/ethwallet.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build js && wasm
// +build js,wasm

package main
Expand All @@ -8,7 +9,7 @@ import (
"sync"
"syscall/js"

"github.com/0chain/gosdk/zcncore"
"github.com/0chain/gosdk_common/zcncore"
)

// JS does not have int64 so we must take a string instead of int64.
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/player_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"context"
"fmt"

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

type FilePlayer struct {
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/player_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"sync"
"time"

"github.com/0chain/gosdk/zboxcore/marker"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/0chain/gosdk_common/core/sys"
"github.com/0chain/gosdk_common/wasmsdk/jsbridge"
"github.com/0chain/gosdk_common/zboxcore/marker"
)

type StreamPlayer struct {
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"time"

"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/gosdk_common/core/client"
"github.com/0chain/gosdk_common/core/sys"
"github.com/0chain/gosdk_common/core/version"
"github.com/0chain/gosdk_common/core/zcncrypto"
"github.com/0chain/gosdk_common/wasmsdk/jsbridge"
"github.com/0chain/gosdk_common/zcncore"

"github.com/hack-pad/safejs"

Expand Down
12 changes: 6 additions & 6 deletions wasmsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"encoding/json"
"fmt"

"github.com/0chain/gosdk/core/client"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/gosdk/core/imageutil"
"github.com/0chain/gosdk/core/logger"
"github.com/0chain/gosdk/core/screstapi"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/gosdk_common/core/client"
"github.com/0chain/gosdk_common/core/encryption"
"github.com/0chain/gosdk_common/core/imageutil"
"github.com/0chain/gosdk_common/core/logger"
"github.com/0chain/gosdk_common/core/screstapi"
"github.com/0chain/gosdk_common/zcncore"

"io"
"os"
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/statusbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path"
"sync"

"github.com/0chain/gosdk/core/sys"
"github.com/0chain/gosdk_common/core/sys"
"github.com/0chain/gosdk/zboxcore/sdk"
"gopkg.in/cheggaaa/pb.v1"
)
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/tokenrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"

"github.com/0chain/gosdk/core/tokenrate"
"github.com/0chain/gosdk_common/core/tokenrate"
)

// getUSDRate gets the USD rate for the given crypto symbol
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/wallet_base.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/gosdk_common/zcncore"
)

// Split keys from the primary master key
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/zbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"errors"

"github.com/0chain/gosdk/zboxapi"
"github.com/0chain/gosdk_common/zboxapi"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions wasmsdk/zcn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package main

import (
"github.com/0chain/gosdk/core/screstapi"
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/gosdk_common/core/screstapi"
"github.com/0chain/gosdk_common/zcncore"
)

type Balance struct {
Expand Down
27 changes: 19 additions & 8 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
thrown "github.com/0chain/errors"
"github.com/0chain/gosdk_common/constants"
"github.com/0chain/gosdk_common/core/common"
"github.com/0chain/gosdk_common/core/encryption"
"github.com/0chain/gosdk_common/core/pathutil"
"github.com/0chain/gosdk_common/core/sys"
"github.com/0chain/gosdk_common/zboxcore/blockchain"
Expand Down Expand Up @@ -2421,6 +2422,16 @@ func (a *Allocation) CancelDownload(remotepath string) error {
return errors.New("remote_path_not_found", "Invalid path. No download in progress for the path "+remotepath)
}

func (a *Allocation) CancelDownloadBlocks(remotepath string, start, end int64) error {
hash := encryption.Hash(fmt.Sprintf("%s:%d:%d", remotepath, start, end))
if downloadReq, ok := a.downloadProgressMap[hash]; ok {
downloadReq.isDownloadCanceled = true
downloadReq.ctxCncl()
return nil
}
return errors.New("remote_path_not_found", "Invalid path. No download in progress for the path "+remotepath)
}

// DownloadFromReader downloads a file from the allocation to the specified local path using the provided reader.
// [DEPRECATED] Use DownloadFile or DownloadFromAuthTicket instead.
func (a *Allocation) DownloadFromReader(
Expand Down Expand Up @@ -3102,14 +3113,14 @@ func (a *Allocation) SetConsensusThreshold() {
// - fileOptionsParams: The file options parameters which control permissions of the files of the allocations.
// - statusCB: A callback function to receive status updates during the update operation.
func (a *Allocation) UpdateWithRepair(
size int64,
size, authRoundExpiry int64,
extend bool,
lock uint64,
addBlobberId, addBlobberAuthTicket, removeBlobberId string,
setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters,
addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string,
setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, updateAllocTicket string,
statusCB StatusCallback,
) (string, error) {
updatedAlloc, hash, isRepairRequired, err := a.UpdateWithStatus(size, extend, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, setThirdPartyExtendable, fileOptionsParams, statusCB)
updatedAlloc, hash, isRepairRequired, err := a.UpdateWithStatus(size, authRoundExpiry, extend, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket)
if err != nil {
return hash, err
}
Expand Down Expand Up @@ -3137,12 +3148,12 @@ func (a *Allocation) UpdateWithRepair(
//
// Returns the updated allocation, hash, and a boolean indicating whether repair is required.
func (a *Allocation) UpdateWithStatus(
size int64,
size, authRoundExpiry int64,
extend bool,
lock uint64,
addBlobberId, addBlobberAuthTicket, removeBlobberId string,
addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string,
setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters,
statusCB StatusCallback,
updateAllocTicket string,
) (*Allocation, string, bool, error) {
var (
alloc *Allocation
Expand All @@ -3153,7 +3164,7 @@ func (a *Allocation) UpdateWithStatus(
}

l.Logger.Info("Updating allocation")
hash, _, err := UpdateAllocation(size, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, setThirdPartyExtendable, fileOptionsParams)
hash, _, err := UpdateAllocation(size, authRoundExpiry, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket)
if err != nil {
return alloc, "", isRepairRequired, err
}
Expand Down
33 changes: 8 additions & 25 deletions zboxcore/sdk/blobber_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"math"
"strings"

"github.com/0chain/errors"
"github.com/0chain/gosdk_common/core/transaction"
Expand Down Expand Up @@ -45,7 +44,7 @@ func CreateAllocationForOwner(
return "", 0, nil, errors.New("allocation_validation_failed", "atleast 1 data and 1 parity shards are required")
}

allocationRequest, err := getNewAllocationBlobbers(
allocationRequest, err := getNewAllocationBlobbers(StorageV2,
datashards, parityshards, size, readPrice, writePrice, preferredBlobberIds, blobberAuthTickets, force)
if err != nil {
return "", 0, nil, errors.New("failed_get_allocation_blobbers", "failed to get blobbers for allocation: "+err.Error())
Expand Down Expand Up @@ -115,12 +114,12 @@ func CreateFreeAllocation(marker string, value uint64) (string, int64, error) {
//
// returns the hash of the transaction, the nonce of the transaction and an error if any.
func UpdateAllocation(
size int64,
size, authRoundExpiry int64,
extend bool,
allocationID string,
lock uint64,
addBlobberId, addBlobberAuthTicket, removeBlobberId string,
setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters,
addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerID, ownerSigninPublicKey string,
setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, ticket string,
) (hash string, nonce int64, err error) {

if lock > math.MaxInt64 {
Expand Down Expand Up @@ -225,7 +224,7 @@ func StakePoolLock(providerType ProviderType, providerID string, value, fee uint
// - providerType: provider type
// - providerID: provider ID
// - fee: transaction fee
func StakePoolUnlock(providerType ProviderType, providerID string, fee uint64) (unstake int64, nonce int64, err error) {
func StakePoolUnlock(providerType ProviderType, providerID, clientID string, fee uint64) (unstake int64, nonce int64, err error) {
if !sdkInitialized {
return 0, 0, sdkNotInitialized
}
Expand All @@ -241,6 +240,7 @@ func StakePoolUnlock(providerType ProviderType, providerID string, fee uint64) (
spr := stakePoolRequest{
ProviderType: providerType,
ProviderID: providerID,
ClientID: clientID,
}

var sn = transaction.SmartContractTxnData{
Expand Down Expand Up @@ -390,24 +390,7 @@ func storageSmartContractTxnValue(sn transaction.SmartContractTxnData, value uin

func smartContractTxnValueFeeWithRetry(scAddress string, sn transaction.SmartContractTxnData,
value, fee uint64) (hash, out string, nonce int64, t *transaction.Transaction, err error) {
hash, out, nonce, t, err = smartContractTxnValueFee(scAddress, sn, value, fee)

if err != nil && strings.Contains(err.Error(), "invalid transaction nonce") {
return smartContractTxnValueFee(scAddress, sn, value, fee)
}
return
}

func smartContractTxnValueFee(scAddress string, sn transaction.SmartContractTxnData,
value, fee uint64) (hash, out string, nonce int64, t *transaction.Transaction, err error) {
t, err = ExecuteSmartContract(scAddress, sn, value, fee)
if err != nil {
if t != nil {
return "", "", t.TransactionNonce, nil, err
}

return "", "", 0, nil, err
}

return t.Hash, t.TransactionOutput, t.TransactionNonce, t, nil
// Fee is set during sdk initialization.
return transaction.SmartContractTxnValueFeeWithRetry(STORAGE_SCADDRESS, sn, value, client.TxnFee(), true)
}
2 changes: 1 addition & 1 deletion zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"errors"

thrown "github.com/0chain/errors"
"github.com/0chain/gosdk/zboxcore/allocationchange"
"github.com/0chain/gosdk_common/constants"
"github.com/0chain/gosdk_common/core/common"
coreEncryption "github.com/0chain/gosdk_common/core/encryption"
"github.com/0chain/gosdk_common/core/sys"
"github.com/0chain/gosdk_common/core/util"
"github.com/0chain/gosdk_common/zboxcore/allocationchange"
"github.com/0chain/gosdk_common/zboxcore/blockchain"
"github.com/0chain/gosdk_common/zboxcore/client"
"github.com/0chain/gosdk_common/zboxcore/encryption"
Expand Down
Loading

0 comments on commit fcca97e

Please sign in to comment.