Skip to content

Commit

Permalink
Merge pull request #1742 from 0chain/sprint-1.19
Browse files Browse the repository at this point in the history
Sprint 1.19
  • Loading branch information
dabasov authored Feb 5, 2025
2 parents 233e527 + 2ba2cd2 commit d56430e
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 332 deletions.
13 changes: 6 additions & 7 deletions core/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions core/client/init_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
var (
logging = logger.GetLogger()
nodeClient *Node
IsAppFlow = false
)

// Node Maintains central states of SDK (client's context, network).
Expand All @@ -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 {
Expand Down
27 changes: 0 additions & 27 deletions core/client/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,6 @@ type Client struct {
sign SignFunc

Check failure on line 36 in core/client/set.go

View workflow job for this annotation

GitHub Actions / lint

field `sign` is unused (unused)
}

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
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 0 additions & 5 deletions core/conf/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
86 changes: 0 additions & 86 deletions core/screstapi/http.go

This file was deleted.

3 changes: 1 addition & 2 deletions core/transaction/get_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package transaction

import (
"encoding/json"

"github.com/0chain/errors"
coreHttp "github.com/0chain/gosdk/core/client"
)
Expand Down Expand Up @@ -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:")
}
Expand Down
17 changes: 5 additions & 12 deletions mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 2 additions & 18 deletions wasmsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

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

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

Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions winsdk/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
33 changes: 1 addition & 32 deletions zboxapi/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion zboxcore/fileref/fileref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions zboxcore/logger/logger.go
Original file line number Diff line number Diff line change
@@ -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()
Loading

0 comments on commit d56430e

Please sign in to comment.