Skip to content

Commit

Permalink
Merge branch 'sprint-1.19' into kms/peter-staging-4
Browse files Browse the repository at this point in the history
* sprint-1.19: (22 commits)
  update upload artifact action in workflows. (#1738)
  Update build-sdks.yml to macos-latest runner
  Feature view change (#1736)
  fix
  test 5
  test 5
  test 4
  test 3
  test 2
  test 2
  lint fix
  new folder
  test 1
  Fix
  Fix
  Fix
  Fix is hardfork activated
  Add hardfork round request
  Fix restricted blobber round
  Empty commit
  ...
  • Loading branch information
peterlimg committed Jan 31, 2025
2 parents 10013b5 + e3474c2 commit adbe86e
Show file tree
Hide file tree
Showing 24 changed files with 361 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-release-wasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
ls -lha
# - name: 'Upload Artifact'
# uses: actions/upload-artifact@v3
# uses: actions/upload-artifact@v4
# with:
# name: zcn.wasm
# path: zcn.wasm
16 changes: 8 additions & 8 deletions .github/workflows/build-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
jobs:
build-ios:
name: Build-ios
runs-on: macos-runner
runs-on: macos-latest

steps:
- name: Checkout code
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
file_glob: true

- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: zcncore-ios
path: |
Expand Down Expand Up @@ -186,14 +186,14 @@ jobs:
file_glob: true

- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: zcncore-android
path: zcncore-android.tar.gz

build-macos:
name: Build-macos
runs-on: macos-runner
runs-on: macos-latest

steps:
- name: Checkout code
Expand Down Expand Up @@ -257,7 +257,7 @@ jobs:
file_glob: true

- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: zcncore-macos
path: |
Expand Down Expand Up @@ -325,7 +325,7 @@ jobs:
file_glob: true

- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: zcn-windows
path: |
Expand All @@ -352,7 +352,7 @@ jobs:
run: docker run --rm -v $PWD:/gosdk -w /gosdk golang:1.23 make wasm-build

- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: zcn.wasm
path: zcn.wasm
path: zcn.wasm
4 changes: 2 additions & 2 deletions core/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// `err` - the error if any
type SCRestAPIHandler func(response map[string][]byte, numSharders int, err error)

func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error) {
func MakeSCRestAPICallToSharder(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 +160,7 @@ func GetBalance(clientIDs ...string) (*GetBalanceResponse, error) {
clientID = Id()
}

if res, err = MakeSCRestAPICall("", GetBalance, map[string]string{
if res, err = MakeSCRestAPICallToSharder("", GetBalance, map[string]string{
"client_id": clientID,
}, "v1/"); err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions core/client/init_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
var (
logging = logger.GetLogger()
nodeClient *Node
IsAppFlow = false
)

// Node Maintains central states of SDK (client's context, network).
Expand All @@ -34,6 +35,10 @@ 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: 27 additions & 0 deletions core/client/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ type Client struct {
sign SignFunc //nolint: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 @@ -326,6 +343,16 @@ 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
1 change: 1 addition & 0 deletions core/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func LoadConfig(v Reader) (Config, error) {
cfg.SignatureScheme = v.GetString("signature_scheme")
cfg.ChainID = v.GetString("chain_id")
cfg.ZauthServer = v.GetString("zauth_server")
cfg.EthereumNode = v.GetString("ethereum_node_url")

return cfg, nil
}
Expand Down
5 changes: 5 additions & 0 deletions core/conf/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ 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: 86 additions & 0 deletions core/screstapi/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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
}
3 changes: 2 additions & 1 deletion core/transaction/get_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transaction

import (
"encoding/json"

"github.com/0chain/errors"
coreHttp "github.com/0chain/gosdk/core/client"
)
Expand Down Expand Up @@ -45,7 +46,7 @@ func GetConfig(configType string) (conf *InputMap, err error) {
relativePath = GET_MINERSC_CONFIGS
}

b, err = coreHttp.MakeSCRestAPICall(scAddress, relativePath, nil)
b, err = coreHttp.MakeSCRestAPICallToSharder(scAddress, relativePath, nil)
if err != nil {
return nil, errors.Wrap(err, "error requesting storage SC configs:")
}
Expand Down
27 changes: 18 additions & 9 deletions mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,18 @@ func InitStorageSDK(clientJson string, configJson string) (*StorageSDK, error) {
l.Logger.Info(configObj.ChainID)
l.Logger.Info(configObj.SignatureScheme)
l.Logger.Info(configObj.PreferredBlobbers)
if err = client.InitSDK(clientJson,
configObj.BlockWorker,
configObj.ChainID,
configObj.SignatureScheme,
0, true); err != nil {
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 {
l.Logger.Error(err)
return nil, err
}
Expand All @@ -199,7 +206,7 @@ func InitStorageSDK(clientJson string, configJson string) (*StorageSDK, error) {
// - expiration: duration to allocation expiration
// - lock: lock write pool with given number of tokens
// - blobberAuthTickets: list of blobber auth tickets needed for the restricted blobbers
func (s *StorageSDK) CreateAllocation(datashards, parityshards int, size, expiration int64, lock string, blobberAuthTickets []string) (*zbox.Allocation, error) {
func (s *StorageSDK) CreateAllocation(datashards, parityshards int, size, expiration, authRoundExpiry int64, lock string, blobberAuthTickets []string) (*zbox.Allocation, error) {
readPrice := sdk.PriceRange{Min: 0, Max: math.MaxInt64}
writePrice := sdk.PriceRange{Min: 0, Max: math.MaxInt64}

Expand All @@ -218,6 +225,7 @@ func (s *StorageSDK) CreateAllocation(datashards, parityshards int, size, expira
BlobberIds: []string{},
FileOptionsParams: &sdk.FileOptionsParameters{},
BlobberAuthTickets: blobberAuthTickets,
AuthRoundExpiry: authRoundExpiry,
}

sdkAllocationID, _, _, err := sdk.CreateAllocationWith(options)
Expand All @@ -240,7 +248,7 @@ func (s *StorageSDK) CreateAllocation(datashards, parityshards int, size, expira
// - lock: lock write pool with given number of tokens
// - blobberUrls: concat blobber urls with comma. leave it as empty if you don't have any preferred blobbers
// - blobberIds: concat blobber ids with comma. leave it as empty if you don't have any preferred blobbers
func (s *StorageSDK) CreateAllocationWithBlobbers(name string, datashards, parityshards int, size int64, lock string, blobberUrls, blobberIds string, blobberAuthTickets []string) (*zbox.Allocation, error) {
func (s *StorageSDK) CreateAllocationWithBlobbers(name string, datashards, parityshards int, size, authRoundExpiry int64, lock string, blobberUrls, blobberIds string, blobberAuthTickets []string) (*zbox.Allocation, error) {
readPrice := sdk.PriceRange{Min: 0, Max: math.MaxInt64}
writePrice := sdk.PriceRange{Min: 0, Max: math.MaxInt64}

Expand All @@ -257,6 +265,7 @@ func (s *StorageSDK) CreateAllocationWithBlobbers(name string, datashards, parit
WritePrice: writePrice,
ReadPrice: readPrice,
BlobberAuthTickets: blobberAuthTickets,
AuthRoundExpiry: authRoundExpiry,
}

if blobberUrls != "" {
Expand Down Expand Up @@ -413,12 +422,12 @@ func GetVersion() string {
// - extend: extend allocation
// - allocationID: allocation ID
// - lock: Number of tokens to lock to the allocation after the update
func (s *StorageSDK) UpdateAllocation(size int64, extend bool, allocationID string, lock uint64) (hash string, err error) {
func (s *StorageSDK) UpdateAllocation(size, authRoundExpiry int64, extend bool, allocationID string, lock uint64) (hash string, err error) {
if lock > math.MaxInt64 {
return "", errors.Errorf("int64 overflow in lock")
}

hash, _, err = sdk.UpdateAllocation(size, extend, allocationID, lock, "", "", "", "", "", false, &sdk.FileOptionsParameters{}, "")
hash, _, err = sdk.UpdateAllocation(size, authRoundExpiry, extend, allocationID, lock, "", "", "", "", "", false, &sdk.FileOptionsParameters{}, "")
return hash, err
}

Expand Down
Loading

0 comments on commit adbe86e

Please sign in to comment.