From dc41b72f25faad338fe36a53bff32f4d14582076 Mon Sep 17 00:00:00 2001 From: Yury Date: Fri, 20 Dec 2024 19:01:45 +0200 Subject: [PATCH] Revert "Methods to 0box apis direction" --- core/client/cache.go | 3 +- core/client/http.go | 28 +++++------ core/client/init_node.go | 5 -- core/client/set.go | 27 ---------- core/conf/vars.go | 5 -- core/screstapi/http.go | 85 ------------------------------- core/transaction/get_data.go | 5 +- core/transaction/utils.go | 2 +- mobilesdk/sdk/sdk.go | 19 ++----- wasmsdk/sdk.go | 21 +------- wasmsdk/zcn.go | 4 +- winsdk/wallet.go | 5 +- zboxapi/sdk.go | 33 +------------ zboxcore/sdk/sdk.go | 96 +++++++++++++++--------------------- zcnbridge/rest.go | 10 ++-- zcncore/get_data.go | 28 ++++------- zcncore/wallet_mobile.go | 3 +- 17 files changed, 83 insertions(+), 296 deletions(-) delete mode 100644 core/screstapi/http.go diff --git a/core/client/cache.go b/core/client/cache.go index 84fe6efe6..cfeb3566d 100644 --- a/core/client/cache.go +++ b/core/client/cache.go @@ -1,9 +1,8 @@ package client import ( - "sync" - "github.com/0chain/gosdk/core/logger" + "sync" ) var Cache *NonceCache diff --git a/core/client/http.go b/core/client/http.go index e230784e4..744ce0d4b 100644 --- a/core/client/http.go +++ b/core/client/http.go @@ -3,19 +3,16 @@ 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" ) -const GetBalanceUrl = "client/get/balance" - // SCRestAPIHandler is a function type to handle the response from the SC Rest API // // `response` - the response from the SC Rest API @@ -23,7 +20,7 @@ const GetBalanceUrl = "client/get/balance" // `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/" @@ -148,6 +145,13 @@ func isCurrentDominantStatus(respStatus int, currentTotalPerStatus map[int]int, } func GetBalance(clientIDs ...string) (*GetBalanceResponse, error) { + const GetBalance = "client/get/balance" + var ( + balance GetBalanceResponse + err error + res []byte + ) + var clientID string if len(clientIDs) > 0 { clientID = clientIDs[0] @@ -155,13 +159,7 @@ func GetBalance(clientIDs ...string) (*GetBalanceResponse, error) { clientID = Id() } - var ( - balance GetBalanceResponse - err error - res []byte - ) - - if res, err = MakeSCRestAPICallToSharder("", GetBalanceUrl, 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 2856b4215..f7a2ad901 100644 --- a/core/client/init_node.go +++ b/core/client/init_node.go @@ -20,17 +20,12 @@ import ( var ( logging logger.Logger nodeClient *Node - IsAppFlow = false ) func init() { logging.Init(logger.DEBUG, "0chain-core") } -func SetIsAppFlow(val bool) { - IsAppFlow = true -} - // Node Maintains central states of SDK (client's context, network). // Initialized through [Init] function. // Use client.GetNode() to get its instance after Init is called. diff --git a/core/client/set.go b/core/client/set.go index f0ba52ad4..3eb4d486e 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 = signHash @@ -343,16 +326,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 f34b2e9c5..000000000 --- a/core/screstapi/http.go +++ /dev/null @@ -1,85 +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() - } - - var ( - balance client.GetBalanceResponse - err error - resp []byte - ) - - if resp, err = MakeSCRestAPICall("", client.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 0ea9c3068..cf7a60065 100644 --- a/core/transaction/get_data.go +++ b/core/transaction/get_data.go @@ -2,9 +2,8 @@ package transaction import ( "encoding/json" - "github.com/0chain/errors" - "github.com/0chain/gosdk/core/screstapi" + coreHttp "github.com/0chain/gosdk/core/client" ) const ( @@ -46,7 +45,7 @@ func GetConfig(configType string) (conf *InputMap, err error) { relativePath = GET_MINERSC_CONFIGS } - b, err = screstapi.MakeSCRestAPICall(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/core/transaction/utils.go b/core/transaction/utils.go index c832701b5..db4287171 100644 --- a/core/transaction/utils.go +++ b/core/transaction/utils.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/0chain/gosdk/core/client" "math" "net/http" "strconv" @@ -12,7 +13,6 @@ import ( "github.com/0chain/common/core/encryption" "github.com/0chain/errors" - "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/conf" "github.com/0chain/gosdk/core/resty" "github.com/0chain/gosdk/core/util" diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index e68003db7..467ab0b49 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -125,20 +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 fdb263aff..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,8 +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/sdk/sdk.go b/zboxcore/sdk/sdk.go index c4ac4297b..65948326a 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -16,7 +16,6 @@ import ( "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/common" - "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/core/version" "github.com/0chain/gosdk/zboxcore/blockchain" @@ -164,10 +163,8 @@ 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:") } @@ -207,9 +204,8 @@ 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, "/getUserStakePoolStat", - params) + b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, + "/getUserStakePoolStat", params) if err != nil { return nil, errors.Wrap(err, "error requesting stake pool user info:") } @@ -260,10 +256,8 @@ func GetChallengePoolInfo(allocID string) (info *ChallengePoolInfo, err error) { } var b []byte - - b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getChallengePoolStat", - map[string]string{"allocation_id": allocID}) - + 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:") } @@ -286,8 +280,9 @@ func GetMptData(key string) ([]byte, error) { } var b []byte - b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, - "/get_mpt_key", map[string]string{"key": key}) + b, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, + "/get_mpt_key", map[string]string{"key": key}, + ) if err != nil { return nil, errors.Wrap(err, "error requesting mpt key data:") } @@ -451,12 +446,13 @@ func getBlobbersInternal(active, stakable bool, limit, offset int) (bs []*Blobbe Nodes []*Blobber } - var b []byte - - 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:") @@ -466,7 +462,7 @@ func getBlobbersInternal(active, stakable bool, limit, offset int) (bs []*Blobbe } if err = json.Unmarshal(b, &wrap); err != nil { - return nil, errors.Wrap(err, "error decoding response:") + return nil, errors.Wrap(err, "6 error decoding response:") } return wrap.Nodes, nil @@ -514,9 +510,11 @@ func GetBlobber(blobberID string) (blob *Blobber, err error) { return nil, sdkNotInitialized } var b []byte - - b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getBlobber", - map[string]string{"blobber_id": blobberID}) + b, err = client.MakeSCRestAPICall( + STORAGE_SCADDRESS, + "/getBlobber", + map[string]string{"blobber_id": blobberID}, + ) if err != nil { return nil, errors.Wrap(err, "requesting blobber:") } @@ -537,9 +535,11 @@ func GetValidator(validatorID string) (validator *Validator, err error) { return nil, sdkNotInitialized } var b []byte - - b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/get_validator", - map[string]string{"validator_id": validatorID}) + b, err = client.MakeSCRestAPICall( + STORAGE_SCADDRESS, + "/get_validator", + map[string]string{"validator_id": validatorID}, + ) if err != nil { return nil, errors.Wrap(err, "requesting validator:") } @@ -560,11 +560,13 @@ func GetValidators(stakable bool) (validators []*Validator, err error) { return nil, sdkNotInitialized } var b []byte - - b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/validators", + b, err = client.MakeSCRestAPICall( + STORAGE_SCADDRESS, + "/validators", map[string]string{ "stakable": strconv.FormatBool(stakable), - }) + }, + ) if err != nil { return nil, errors.Wrap(err, "requesting validator list") } @@ -622,11 +624,7 @@ func GetAllocation(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - var allocationBytes []byte - var err error - - 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()) } @@ -647,8 +645,7 @@ 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()) } @@ -667,12 +664,7 @@ func GetAllocationUpdates(allocation *Allocation) error { params := make(map[string]string) params["allocation"] = allocation.ID - var allocationBytes []byte - var err error - - 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()) } @@ -725,11 +717,7 @@ func getAllocationsInternal(clientID string, limit, offset int) ([]*Allocation, params["client"] = clientID params["limit"] = fmt.Sprint(limit) params["offset"] = fmt.Sprint(offset) - var allocationsBytes []byte - var err error - - 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()) } @@ -857,11 +845,8 @@ func GetAllocationBlobbers( if len(force) > 0 && force[0] { params["force"] = strconv.FormatBool(force[0]) } - var allocBlobber []byte - var err error - allocBlobber, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", - params) + allocBlobber, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", params) if err != nil { return nil, err } @@ -948,10 +933,7 @@ func GetBlobberIds(blobberUrls []string) ([]string, error) { params := make(map[string]string) params["blobber_urls"] = string(urlsStr) - var idsStr []byte - - idsStr, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", - params) + idsStr, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", params) if err != nil { return nil, err } @@ -976,7 +958,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 } @@ -1422,7 +1404,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 4a8913d5f..ab860b16d 100644 --- a/zcnbridge/rest.go +++ b/zcnbridge/rest.go @@ -3,9 +3,7 @@ package zcnbridge import ( "encoding/json" "fmt" - - "github.com/0chain/gosdk/core/screstapi" - + coreHttp "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/common" "github.com/0chain/gosdk/zcncore" @@ -90,7 +88,7 @@ func GetAuthorizer(id string) (res []byte, err error) { return nil, err } - return screstapi.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ + return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ "id": id, }) } @@ -103,7 +101,7 @@ func GetAuthorizers(active bool) (res []byte, err error) { if err != nil { return nil, err } - return screstapi.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) + return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) } // GetGlobalConfig Returns global config @@ -113,5 +111,5 @@ func GetGlobalConfig() (res []byte, err error) { if err != nil { return nil, err } - return screstapi.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) + return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) } diff --git a/zcncore/get_data.go b/zcncore/get_data.go index 999fb472d..6a17f7aff 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -10,8 +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" @@ -215,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), @@ -230,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,13 +240,10 @@ func GetMintNonce() ([]byte, error) { if err != nil { return nil, err } - var res []byte - res, err = screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ + return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ "client_id": client.Id(), }) - - return res, err } func GetMiners(active, stakable bool, limit, offset int) ([]byte, error) { @@ -256,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), @@ -269,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), @@ -281,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 } @@ -310,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, }) } @@ -322,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(), }) @@ -340,13 +335,10 @@ func GetNotProcessedZCNBurnTickets(ethereumAddress, startNonce string) ([]byte, const GET_NOT_PROCESSED_BURN_TICKETS = `/v1/not_processed_burn_tickets` - var res []byte - - res, err = screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ + return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ "ethereum_address": ethereumAddress, "nonce": startNonce, }) - return res, err } // GetUserLockedTotal get total token user locked @@ -362,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 }