From 1ad0c90feaa5199b74279895a9f0a0eb0365f65e Mon Sep 17 00:00:00 2001 From: Yury Date: Thu, 6 Feb 2025 00:20:34 +0200 Subject: [PATCH 1/2] Revert "gosdk methods directing to 0box" --- core/client/http.go | 13 +++--- core/client/init_node.go | 5 --- core/client/set.go | 27 ----------- core/conf/vars.go | 5 --- core/screstapi/http.go | 86 ------------------------------------ core/transaction/get_data.go | 3 +- mobilesdk/sdk/sdk.go | 17 +++---- wasmsdk/sdk.go | 20 +-------- wasmsdk/zcn.go | 4 +- winsdk/wallet.go | 5 +-- zboxapi/sdk.go | 33 +------------- zboxcore/fileref/fileref.go | 1 - zboxcore/logger/logger.go | 4 +- zboxcore/sdk/listworker.go | 4 -- zboxcore/sdk/rollback.go | 84 ----------------------------------- zboxcore/sdk/sdk.go | 44 +++++++++--------- zcnbridge/rest.go | 7 ++- zcncore/get_data.go | 21 +++++---- zcncore/wallet_mobile.go | 3 +- 19 files changed, 56 insertions(+), 330 deletions(-) delete mode 100644 core/screstapi/http.go diff --git a/core/client/http.go b/core/client/http.go index 4572b366e..744ce0d4b 100644 --- a/core/client/http.go +++ b/core/client/http.go @@ -3,15 +3,14 @@ package client import ( "encoding/json" "fmt" - "log" - "net/http" - "net/url" - "sync" - "github.com/0chain/errors" "github.com/0chain/gosdk/core/conf" "github.com/0chain/gosdk/core/util" "github.com/shopspring/decimal" + "log" + "net/http" + "net/url" + "sync" ) // SCRestAPIHandler is a function type to handle the response from the SC Rest API @@ -21,7 +20,7 @@ import ( // `err` - the error if any type SCRestAPIHandler func(response map[string][]byte, numSharders int, err error) -func MakeSCRestAPICallToSharder(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error) { +func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error) { const ( consensusThresh = float32(25.0) ScRestApiUrl = "v1/screst/" @@ -160,7 +159,7 @@ func GetBalance(clientIDs ...string) (*GetBalanceResponse, error) { clientID = Id() } - if res, err = MakeSCRestAPICallToSharder("", GetBalance, map[string]string{ + if res, err = MakeSCRestAPICall("", GetBalance, map[string]string{ "client_id": clientID, }, "v1/"); err != nil { return nil, err diff --git a/core/client/init_node.go b/core/client/init_node.go index d356f2071..444b33834 100644 --- a/core/client/init_node.go +++ b/core/client/init_node.go @@ -20,7 +20,6 @@ import ( var ( logging = logger.GetLogger() nodeClient *Node - IsAppFlow = false ) // Node Maintains central states of SDK (client's context, network). @@ -35,10 +34,6 @@ type Node struct { networkGuard sync.RWMutex } -func SetIsAppFlow(val bool) { - IsAppFlow = true -} - // GetStableMiners Returns stable miner urls. // Length of stable miners is depedent on config's MinSubmit and number of miners in network. func (n *Node) GetStableMiners() []string { diff --git a/core/client/set.go b/core/client/set.go index 7aff4e528..1c72c0625 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -36,23 +36,6 @@ type Client struct { sign SignFunc } -type InitSdkOptions struct { - WalletJSON string - BlockWorker string - ChainID string - SignatureScheme string - Nonce int64 - IsSplitWallet bool - AddWallet bool - TxnFee *int - MinConfirmation *int - MinSubmit *int - ConfirmationChainLength *int - SharderConsensous *int - ZboxHost string - ZboxAppType string -} - func init() { sys.Sign = signHash sys.SignWithAuth = signHashWithAuth @@ -379,16 +362,6 @@ func InitSDK(walletJSON string, return nil } -func InitSDKWithWebApp(params InitSdkOptions) error { - err := InitSDK(params.WalletJSON, params.BlockWorker, params.ChainID, params.SignatureScheme, params.Nonce, params.AddWallet, *params.MinConfirmation, *params.MinSubmit, *params.ConfirmationChainLength, *params.SharderConsensous) - if err != nil { - return err - } - conf.SetZboxAppConfigs(params.ZboxHost, params.ZboxAppType) - SetIsAppFlow(true) - return nil -} - func IsSDKInitialized() bool { return sdkInitialized } diff --git a/core/conf/vars.go b/core/conf/vars.go index e31cbcd8f..8551c1cd9 100644 --- a/core/conf/vars.go +++ b/core/conf/vars.go @@ -39,11 +39,6 @@ func GetClientConfig() (*Config, error) { return cfg, nil } -func SetZboxAppConfigs(zboxHost, zboxAppType string) { - cfg.ZboxHost = zboxHost - cfg.ZboxAppType = zboxAppType -} - // InitClientConfig set global client config func InitClientConfig(c *Config) { onceCfg.Do(func() { diff --git a/core/screstapi/http.go b/core/screstapi/http.go deleted file mode 100644 index 53f5823b5..000000000 --- a/core/screstapi/http.go +++ /dev/null @@ -1,86 +0,0 @@ -package screstapi - -import ( - "context" - "encoding/json" - - "github.com/0chain/gosdk/core/client" - "github.com/0chain/gosdk/core/conf" - "github.com/0chain/gosdk/zboxapi" -) - -var urlPathSharderToZboxMap = map[string]string{ - "/getStakePoolStat": "/getStakePoolStat", - "/getUserStakePoolStat": "/getUserStakePoolStat", - "/getChallengePoolStat": "/getChallengePoolStat", - "/getBlobber": "/blobber", - "/getblobbers": "/blobbers", - "/blobber_ids": "/blobber_ids", - "/alloc_blobbers": "/blobbers/allocation", - "/get_validator": "/validator", - "/validators": "/validators", - "/allocation": "/getAllocation", - "/allocations": "/getAllocations", - "/v1/mint_nonce": "/mintNonce", - "client/get/balance": "/balance", - "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", -} - -func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { - _, ok := urlPathSharderToZboxMap[relativePath] - if client.IsAppFlow && ok { - resp, err = MakeSCRestAPICallToZbox(urlPathSharderToZboxMap[relativePath], params) - if err != nil { - resp, err = client.MakeSCRestAPICallToSharder(scAddress, relativePath, params, restApiUrls...) - } - } else { - resp, err = client.MakeSCRestAPICallToSharder(scAddress, relativePath, params, restApiUrls...) - } - - return resp, err -} - -func MakeSCRestAPICallToZbox(relativePath string, params map[string]string) ([]byte, error) { - // req, err := http.NewRequest(method, relativePath) - zboxApiClient := zboxapi.NewClient() - configObj, err := conf.GetClientConfig() - if err != nil { - return nil, err - } - zboxApiClient.SetRequest(configObj.ZboxHost, configObj.ZboxAppType) - - resp, err := zboxApiClient.MakeRestApiCallToZbox(context.TODO(), relativePath, params) - if err != nil { - return nil, err - } - - return resp, nil -} - -func GetBalance(clientIDs ...string) (*client.GetBalanceResponse, error) { - var clientID string - if len(clientIDs) > 0 { - clientID = clientIDs[0] - } else { - clientID = client.Id() - } - - const GetBalanceUrl = "client/get/balance" - var ( - balance client.GetBalanceResponse - err error - resp []byte - ) - - if resp, err = MakeSCRestAPICall("", GetBalanceUrl, map[string]string{ - "client_id": clientID, - }, "v1/"); err != nil { - return nil, err - } - - if err = json.Unmarshal(resp, &balance); err != nil { - return nil, err - } - - return &balance, err -} diff --git a/core/transaction/get_data.go b/core/transaction/get_data.go index 7ac58359a..cf7a60065 100644 --- a/core/transaction/get_data.go +++ b/core/transaction/get_data.go @@ -2,7 +2,6 @@ package transaction import ( "encoding/json" - "github.com/0chain/errors" coreHttp "github.com/0chain/gosdk/core/client" ) @@ -46,7 +45,7 @@ func GetConfig(configType string) (conf *InputMap, err error) { relativePath = GET_MINERSC_CONFIGS } - b, err = coreHttp.MakeSCRestAPICallToSharder(scAddress, relativePath, nil) + b, err = coreHttp.MakeSCRestAPICall(scAddress, relativePath, nil) if err != nil { return nil, errors.Wrap(err, "error requesting storage SC configs:") } diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index f5dd299c8..f319cf968 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -125,18 +125,11 @@ func InitStorageSDK(clientJson string, configJson string) (*StorageSDK, error) { l.Logger.Info(configObj.ChainID) l.Logger.Info(configObj.SignatureScheme) l.Logger.Info(configObj.PreferredBlobbers) - params := client.InitSdkOptions{ - WalletJSON: clientJson, - BlockWorker: configObj.BlockWorker, - ChainID: configObj.ChainID, - SignatureScheme: configObj.SignatureScheme, - Nonce: int64(0), - AddWallet: true, - ZboxHost: configObj.ZboxHost, - ZboxAppType: configObj.ZboxAppType, - } - - if err = client.InitSDKWithWebApp(params); err != nil { + if err = client.InitSDK(clientJson, + configObj.BlockWorker, + configObj.ChainID, + configObj.SignatureScheme, + 0, true); err != nil { l.Logger.Error(err) return nil, err } diff --git a/wasmsdk/sdk.go b/wasmsdk/sdk.go index 07f9974ad..c0b78a2b6 100644 --- a/wasmsdk/sdk.go +++ b/wasmsdk/sdk.go @@ -12,7 +12,6 @@ import ( "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" @@ -41,22 +40,7 @@ func initSDKs(chainID, blockWorker, signatureScheme string, zboxApiClient.SetRequest(zboxHost, zboxAppType) - params := client.InitSdkOptions{ - WalletJSON: "{}", - BlockWorker: blockWorker, - ChainID: chainID, - SignatureScheme: signatureScheme, - Nonce: int64(0), - AddWallet: false, - MinConfirmation: &minConfirmation, - MinSubmit: &minSubmit, - SharderConsensous: &sharderConsensous, - ConfirmationChainLength: &confirmationChainLength, - ZboxHost: zboxHost, - ZboxAppType: zboxAppType, - } - - err := client.InitSDKWithWebApp(params) + err := client.InitSDK("{}", blockWorker, chainID, signatureScheme, 0, false, minConfirmation, minSubmit, confirmationChainLength, sharderConsensous) if err != nil { fmt.Println("wasm: InitStorageSDK ", err) return err @@ -162,7 +146,7 @@ func makeSCRestAPICall(scAddress, relativePath, paramsJson string) (string, erro if err != nil { sdkLogger.Error(fmt.Sprintf("Error parsing JSON: %v", err)) } - b, err := screstapi.MakeSCRestAPICall(scAddress, relativePath, params) + b, err := client.MakeSCRestAPICall(scAddress, relativePath, params) return string(b), err } diff --git a/wasmsdk/zcn.go b/wasmsdk/zcn.go index f0272e4b5..bb3a53a3d 100644 --- a/wasmsdk/zcn.go +++ b/wasmsdk/zcn.go @@ -4,7 +4,7 @@ package main import ( - "github.com/0chain/gosdk/core/screstapi" + "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/zcncore" ) @@ -17,7 +17,7 @@ type Balance struct { // getWalletBalance retrieves the wallet balance of the client from the network. // - clientId is the client id func getWalletBalance(clientId string) (*Balance, error) { - bal, err := screstapi.GetBalance(clientId) + bal, err := client.GetBalance(clientId) if err != nil { return nil, err } diff --git a/winsdk/wallet.go b/winsdk/wallet.go index 51762ea61..0e72008f8 100644 --- a/winsdk/wallet.go +++ b/winsdk/wallet.go @@ -8,11 +8,10 @@ import ( ) import ( + "github.com/0chain/gosdk/core/client" "os" "path/filepath" - "github.com/0chain/gosdk/core/screstapi" - "github.com/0chain/gosdk/zcncore" ) @@ -88,7 +87,7 @@ func RecoverWallet(mnemonic *C.char) *C.char { // //export GetWalletBalance func GetWalletBalance(clientID *C.char) *C.char { - b, err := screstapi.GetBalance(C.GoString(clientID)) + b, err := client.GetBalance(C.GoString(clientID)) if err != nil { log.Error("win: ", err) return WithJSON(0, err) diff --git a/zboxapi/sdk.go b/zboxapi/sdk.go index 270e18c63..0ac6e7064 100644 --- a/zboxapi/sdk.go +++ b/zboxapi/sdk.go @@ -6,14 +6,11 @@ import ( "encoding/json" "errors" "fmt" - "io" + "github.com/0chain/gosdk/core/client" "net/http" - "net/url" "strconv" "time" - "github.com/0chain/gosdk/core/client" - thrown "github.com/0chain/errors" "github.com/0chain/gosdk/core/encryption" "github.com/0chain/gosdk/core/logger" @@ -374,31 +371,3 @@ func (c *Client) GetSharedToMe(ctx context.Context, phoneNumber, token string) ( return result.Data, nil } - -func (c *Client) MakeRestApiCallToZbox(ctx context.Context, relativePath string, params map[string]string) ([]byte, error) { - urlPath := c.baseUrl + "/v2" + relativePath - u, err := url.Parse(urlPath) - if err != nil { - return nil, fmt.Errorf("error parsing URL: %w", err) - } - - // Add query parameters - q := u.Query() - for key, value := range params { - q.Add(key, value) - } - u.RawQuery = q.Encode() - - resp, err := http.Get(u.String()) - if err != nil { - return nil, fmt.Errorf("error making GET request: %w", err) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - resp.Body.Close() - - return body, nil -} diff --git a/zboxcore/fileref/fileref.go b/zboxcore/fileref/fileref.go index 3f226777a..a1c082d5e 100644 --- a/zboxcore/fileref/fileref.go +++ b/zboxcore/fileref/fileref.go @@ -106,7 +106,6 @@ type Ref struct { AllocationRoot string `json:"allocation_root" mapstructure:"allocation_root"` CreatedAt common.Timestamp `json:"created_at" mapstructure:"created_at"` UpdatedAt common.Timestamp `json:"updated_at" mapstructure:"updated_at"` - NumFiles int `json:"num_files" mapstructure:"num_files"` } // GetReferenceLookup returns the lookup hash for a given allocationID and path diff --git a/zboxcore/logger/logger.go b/zboxcore/logger/logger.go index 0a78ddab7..64134eb35 100644 --- a/zboxcore/logger/logger.go +++ b/zboxcore/logger/logger.go @@ -1,9 +1,7 @@ // Proxy for the core logger package. package logger -import ( - "github.com/0chain/gosdk/core/logger" -) +import "github.com/0chain/gosdk/core/logger" // Logger global logger instance var Logger = logger.GetLogger() diff --git a/zboxcore/sdk/listworker.go b/zboxcore/sdk/listworker.go index a46e30f9b..d8944557d 100644 --- a/zboxcore/sdk/listworker.go +++ b/zboxcore/sdk/listworker.go @@ -69,7 +69,6 @@ type ListResult struct { ThumbnailSize int64 `json:"thumbnail_size"` ActualThumbnailHash string `json:"actual_thumbnail_hash"` ActualThumbnailSize int64 `json:"actual_thumbnail_size"` - NumFiles int `json:"num_files"` CreatedAt common.Timestamp `json:"created_at"` UpdatedAt common.Timestamp `json:"updated_at"` @@ -267,9 +266,6 @@ func (req *ListRequest) GetListFromBlobbers() (*ListResult, error) { result.ThumbnailSize = ti.ref.ThumbnailSize result.ActualThumbnailHash = ti.ref.ActualThumbnailHash result.ActualThumbnailSize = ti.ref.ActualThumbnailSize - if result.Path == "/" && req.storageVersion == StorageV2 { - result.NumFiles = ti.ref.NumFiles - } if ti.ref.ActualSize > 0 { result.ActualNumBlocks = (ti.ref.ActualSize + CHUNK_SIZE - 1) / CHUNK_SIZE diff --git a/zboxcore/sdk/rollback.go b/zboxcore/sdk/rollback.go index 6d1607c44..f623dbc63 100644 --- a/zboxcore/sdk/rollback.go +++ b/zboxcore/sdk/rollback.go @@ -316,10 +316,6 @@ func (a *Allocation) CheckAllocStatus() (AllocStatus, []BlobberStatus, error) { return Broken, blobberRes, common.NewError("check_alloc_status_failed", markerError.Error()) } - if a.StorageVersion == StorageV2 { - return a.checkStatusV2(markerChan, blobberRes) - } - versionMap := make(map[string][]*RollbackBlobber) var ( @@ -476,83 +472,3 @@ func (a *Allocation) RollbackWithMask(mask zboxutil.Uint128) { wg.Wait() } - -func (a *Allocation) checkStatusV2(markerChan chan *RollbackBlobber, blobStatus []BlobberStatus) (AllocStatus, []BlobberStatus, error) { - var ( - latestVersionMap = make(map[string][]*RollbackBlobber) - allVersionMap = make(map[string][]*RollbackBlobber) - consensusVersion string - allVersionConensus string - ) - - for rb := range markerChan { - if rb == nil || rb.lpm.LatestWM == nil { - continue - } - version := rb.lpm.LatestWM.AllocationRoot - latestVersionMap[version] = append(latestVersionMap[version], rb) - if len(latestVersionMap[version]) > a.DataShards { - consensusVersion = version - } - allVersionMap[version] = append(allVersionMap[version], rb) - if rb.lpm.PrevWM != nil && rb.lpm.PrevWM.AllocationRoot != version { - allVersionMap[rb.lpm.PrevWM.AllocationRoot] = append(allVersionMap[rb.lpm.PrevWM.AllocationRoot], rb) - if len(allVersionMap[rb.lpm.PrevWM.AllocationRoot]) >= a.DataShards { - allVersionConensus = rb.lpm.PrevWM.AllocationRoot - } - } - if len(allVersionMap[version]) >= a.DataShards { - allVersionConensus = version - } - } - - if consensusVersion != "" { - a.allocationRoot = consensusVersion - return Commit, blobStatus, nil - } - - if allVersionConensus == "" { - if len(latestVersionMap) == 0 { - return Commit, blobStatus, nil - } - return Broken, blobStatus, nil - } - - if len(latestVersionMap[allVersionConensus]) >= a.DataShards { - a.allocationRoot = allVersionConensus - return Repair, blobStatus, nil - } - l.Logger.Info("Rolling back to previous version") - fullConsensus := len(allVersionMap[allVersionConensus]) - len(latestVersionMap[allVersionConensus]) - consensusThresh := a.DataShards - len(latestVersionMap[allVersionConensus]) - var successCnt int32 - wg := &sync.WaitGroup{} - - for _, rb := range allVersionMap[allVersionConensus] { - if rb.lpm.LatestWM.AllocationRoot == allVersionConensus { - continue - } - wg.Add(1) - go func(rb *RollbackBlobber) { - defer wg.Done() - err := rb.processRollback(context.TODO(), a.Tx) - if err != nil { - rb.commitResult = ErrorCommitResult(err.Error()) - l.Logger.Error("error during rollback", zap.Error(err)) - } else { - atomic.AddInt32(&successCnt, 1) - rb.commitResult = SuccessCommitResult() - } - }(rb) - } - wg.Wait() - if successCnt < int32(consensusThresh) { - return Broken, blobStatus, common.NewError("rollback_failed", "Rollback failed") - } - a.allocationRoot = allVersionConensus - if successCnt == int32(fullConsensus) { - return Repair, blobStatus, nil - } - - return Commit, blobStatus, nil -} diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index a8e3934fb..40fdb954b 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -12,7 +12,6 @@ import ( "github.com/0chain/common/core/currency" "github.com/0chain/errors" "github.com/0chain/gosdk/core/logger" - "github.com/0chain/gosdk/core/screstapi" "gopkg.in/natefinch/lumberjack.v2" "github.com/0chain/gosdk/core/client" @@ -164,7 +163,7 @@ func GetStakePoolInfo(providerType ProviderType, providerID string) (info *Stake } var b []byte - b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getStakePoolStat", + b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getStakePoolStat", map[string]string{"provider_type": strconv.Itoa(int(providerType)), "provider_id": providerID}) if err != nil { return nil, errors.Wrap(err, "error requesting stake pool info:") @@ -205,7 +204,7 @@ func GetStakePoolUserInfo(clientID string, offset, limit int) (info *StakePoolUs "offset": strconv.FormatInt(int64(offset), 10), "limit": strconv.FormatInt(int64(limit), 10), } - b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getUserStakePoolStat", params) if err != nil { return nil, errors.Wrap(err, "error requesting stake pool user info:") @@ -258,7 +257,7 @@ func GetChallengePoolInfo(allocID string) (info *ChallengePoolInfo, err error) { } var b []byte - b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getChallengePoolStat", map[string]string{"allocation_id": allocID}) if err != nil { return nil, errors.Wrap(err, "error requesting challenge pool info:") @@ -282,7 +281,7 @@ func GetMptData(key string) ([]byte, error) { } var b []byte - b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/get_mpt_key", map[string]string{"key": key}, ) if err != nil { @@ -448,9 +447,13 @@ func getBlobbersInternal(active, stakable bool, limit, offset int) (bs []*Blobbe Nodes []*Blobber } - b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getblobbers", map[string]string{"active": strconv.FormatBool(active), "limit": strconv.FormatInt(int64(limit), 10), - "offset": strconv.FormatInt(int64(offset), 10), - "stakable": strconv.FormatBool(stakable)}) + url := fmt.Sprintf("/getblobbers?active=%s&limit=%d&offset=%d&stakable=%s", + strconv.FormatBool(active), + limit, + offset, + strconv.FormatBool(stakable), + ) + b, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, url, nil) var wrap nodes if err != nil { return nil, errors.Wrap(err, "error requesting blobbers:") @@ -508,7 +511,7 @@ func GetBlobber(blobberID string) (blob *Blobber, err error) { return nil, sdkNotInitialized } var b []byte - b, err = screstapi.MakeSCRestAPICall( + b, err = client.MakeSCRestAPICall( STORAGE_SCADDRESS, "/getBlobber", map[string]string{"blobber_id": blobberID}, @@ -533,7 +536,7 @@ func GetValidator(validatorID string) (validator *Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = screstapi.MakeSCRestAPICall( + b, err = client.MakeSCRestAPICall( STORAGE_SCADDRESS, "/get_validator", map[string]string{"validator_id": validatorID}, @@ -558,7 +561,7 @@ func GetValidators(stakable bool) (validators []*Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = screstapi.MakeSCRestAPICall( + b, err = client.MakeSCRestAPICall( STORAGE_SCADDRESS, "/validators", map[string]string{ @@ -622,11 +625,10 @@ func GetAllocation(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } - allocationObj := &Allocation{} err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { @@ -644,11 +646,10 @@ func GetAllocationForUpdate(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } - allocationObj := &Allocation{} err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { @@ -664,7 +665,7 @@ func GetAllocationUpdates(allocation *Allocation) error { params := make(map[string]string) params["allocation"] = allocation.ID - allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } @@ -717,11 +718,10 @@ func getAllocationsInternal(clientID string, limit, offset int) ([]*Allocation, params["client"] = clientID params["limit"] = fmt.Sprint(limit) params["offset"] = fmt.Sprint(offset) - allocationsBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocations", params) + allocationsBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocations", params) if err != nil { return nil, errors.New("allocations_fetch_error", "Error fetching the allocations."+err.Error()) } - allocations := make([]*Allocation, 0) err = json.Unmarshal(allocationsBytes, &allocations) if err != nil { @@ -848,7 +848,7 @@ func GetAllocationBlobbers( params["force"] = strconv.FormatBool(force[0]) } - allocBlobber, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", params) + allocBlobber, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", params) if err != nil { return nil, err } @@ -935,7 +935,7 @@ func GetBlobberIds(blobberUrls []string) ([]string, error) { params := make(map[string]string) params["blobber_urls"] = string(urlsStr) - idsStr, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", params) + idsStr, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", params) if err != nil { return nil, err } @@ -960,7 +960,7 @@ func GetFreeAllocationBlobbers(request map[string]interface{}) ([]string, error) params := make(map[string]string) params["free_allocation_data"] = string(data) - allocBlobber, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) + allocBlobber, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) if err != nil { return nil, err } @@ -1406,7 +1406,7 @@ func GetUpdateAllocationMinLock( params := make(map[string]string) params["data"] = string(data) - responseBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) + responseBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) if err != nil { return 0, errors.Wrap(err, "failed to request allocation update min lock") } diff --git a/zcnbridge/rest.go b/zcnbridge/rest.go index f5c12241f..ab860b16d 100644 --- a/zcnbridge/rest.go +++ b/zcnbridge/rest.go @@ -3,7 +3,6 @@ package zcnbridge import ( "encoding/json" "fmt" - coreHttp "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/common" @@ -89,7 +88,7 @@ func GetAuthorizer(id string) (res []byte, err error) { return nil, err } - return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ + return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ "id": id, }) } @@ -102,7 +101,7 @@ func GetAuthorizers(active bool) (res []byte, err error) { if err != nil { return nil, err } - return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) + return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) } // GetGlobalConfig Returns global config @@ -112,5 +111,5 @@ func GetGlobalConfig() (res []byte, err error) { if err != nil { return nil, err } - return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) + return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) } diff --git a/zcncore/get_data.go b/zcncore/get_data.go index d346a550b..b9cfd3a5d 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -10,7 +10,6 @@ import ( "github.com/0chain/gosdk/core/block" "github.com/0chain/gosdk/core/client" - "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/core/sys" "github.com/0chain/gosdk/core/tokenrate" "github.com/0chain/gosdk/core/util" @@ -214,7 +213,7 @@ func withParams(uri string, params Params) string { //nolint:unused // return // } // -// return coreHttp.MakeSCRestAPICallToSharder(StorageSmartContractAddress, STORAGE_GET_BLOBBER_SNAPSHOT, Params{ +// return coreHttp.MakeSCRestAPICall(StorageSmartContractAddress, STORAGE_GET_BLOBBER_SNAPSHOT, Params{ // "round": strconv.FormatInt(round, 10), // "limit": strconv.FormatInt(limit, 10), // "offset": strconv.FormatInt(offset, 10), @@ -229,7 +228,7 @@ func GetMinerSCNodeInfo(id string) ([]byte, error) { return nil, err } - return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ + return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ "id": id, }) } @@ -242,7 +241,7 @@ func GetMintNonce() ([]byte, error) { return nil, err } - return screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ + return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ "client_id": client.Id(), }) } @@ -252,7 +251,7 @@ func GetMiners(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ + return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -265,7 +264,7 @@ func GetSharders(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ + return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -277,7 +276,7 @@ func GetSharders(active, stakable bool, limit, offset int) ([]byte, error) { // - numSharders: number of sharders // - timeout: request timeout func GetLatestFinalizedMagicBlock() (m *block.MagicBlock, err error) { - res, err := screstapi.MakeSCRestAPICall("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") + res, err := client.MakeSCRestAPICall("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") if err != nil { return nil, err } @@ -306,7 +305,7 @@ func GetMinerSCUserInfo(clientID string) ([]byte, error) { clientID = client.Id() } - return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_USER, Params{ + return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_USER, Params{ "client_id": clientID, }) } @@ -318,7 +317,7 @@ func GetMinerSCNodePool(id string) ([]byte, error) { return nil, err } - return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ + return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ "id": id, "pool_id": client.Id(), }) @@ -336,7 +335,7 @@ func GetNotProcessedZCNBurnTickets(ethereumAddress, startNonce string) ([]byte, const GET_NOT_PROCESSED_BURN_TICKETS = `/v1/not_processed_burn_tickets` - return screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ + return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ "ethereum_address": ethereumAddress, "nonce": startNonce, }) @@ -355,7 +354,7 @@ func GetUserLockedTotal(clientID string) (int64, error) { const GET_USER_LOCKED_TOTAL = `/v1/getUserLockedTotal` - info, err := screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ + info, err := client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ "client_id": clientID, }) diff --git a/zcncore/wallet_mobile.go b/zcncore/wallet_mobile.go index b84955efd..7fd9b0564 100644 --- a/zcncore/wallet_mobile.go +++ b/zcncore/wallet_mobile.go @@ -5,7 +5,6 @@ package zcncore import ( "github.com/0chain/gosdk/core/client" - "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/core/zcncrypto" ) @@ -32,7 +31,7 @@ func (w *wallet) Sign(hash string) (string, error) { // GetWalletBalance retrieve wallet balance from sharders // - id: client id func GetWalletBalance(id string) (int64, error) { - response, err := screstapi.GetBalance(id) + response, err := client.GetBalance(id) if err != nil { return 0, err } From f845b3fd75d96f969dd73ce9306e20b7e9f00116 Mon Sep 17 00:00:00 2001 From: Yury Date: Thu, 6 Feb 2025 00:21:09 +0200 Subject: [PATCH 2/2] Revert "fix" --- zcncore/get_data.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index d346a550b..96ad74878 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -377,7 +377,7 @@ func GetUserLockedTotal(clientID string) (int64, error) { } func IsHardforkActivated(name string) (bool, error) { - res, err := screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_HARDFORK, Params{ + res, err := client.MakeSCRestAPICall(MinerSmartContractAddress, GET_HARDFORK, Params{ "name": name, }) if err != nil { @@ -409,7 +409,7 @@ func IsHardforkActivated(name string) (bool, error) { } func GetCurrentRound() (int64, error) { - res, err := screstapi.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil, "") + res, err := client.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil, "") if err != nil { return 0, err }