Skip to content

Commit

Permalink
Merge pull request #1712 from 0chain/revert-1704-methods_0box_mig
Browse files Browse the repository at this point in the history
Revert "Methods to 0box apis direction"
  • Loading branch information
dabasov authored Dec 20, 2024
2 parents 3c22a72 + dc41b72 commit 9ddde94
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 296 deletions.
3 changes: 1 addition & 2 deletions core/client/cache.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package client

import (
"sync"

"github.com/0chain/gosdk/core/logger"
"sync"
)

var Cache *NonceCache
Expand Down
28 changes: 13 additions & 15 deletions core/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ 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
// `numSharders` - the number of sharders that responded
// `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 @@ -148,20 +145,21 @@ 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]
} else {
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
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,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.
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 = signHash
Expand Down Expand Up @@ -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
}
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
85 changes: 0 additions & 85 deletions core/screstapi/http.go

This file was deleted.

5 changes: 2 additions & 3 deletions core/transaction/get_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:")
}
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/0chain/gosdk/core/client"
"math"
"net/http"
"strconv"
Expand All @@ -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"
Expand Down
19 changes: 5 additions & 14 deletions mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 2 additions & 19 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,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
}

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
Loading

0 comments on commit 9ddde94

Please sign in to comment.