From 320244046666e249fae269e683f596d6ad7d356e Mon Sep 17 00:00:00 2001 From: storybehind Date: Wed, 4 Dec 2024 10:15:17 +0530 Subject: [PATCH 01/22] add eth node url to config --- core/conf/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/conf/config.go b/core/conf/config.go index 4444892e3..e174d3ed9 100644 --- a/core/conf/config.go +++ b/core/conf/config.go @@ -179,6 +179,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 } From 62fc7ab4010d90f238ed62700674d7569c17b0bd Mon Sep 17 00:00:00 2001 From: storybehind Date: Wed, 11 Dec 2024 19:15:07 +0530 Subject: [PATCH 02/22] revert --- core/conf/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/conf/config.go b/core/conf/config.go index 026332917..b1db3d098 100644 --- a/core/conf/config.go +++ b/core/conf/config.go @@ -176,7 +176,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.ZauthServer = v.GetString("zauth_server") cfg.EthereumNode = v.GetString("ethereum_node_url") return cfg, nil From a4e82053d01995b341abf6cc338b121bb70d996f Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Thu, 2 Jan 2025 21:51:49 +0530 Subject: [PATCH 03/22] Empty commit From e1d9de00a484d438238f43e94f5c0d3f6f81856e Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 01:12:44 +0530 Subject: [PATCH 04/22] Fix restricted blobber round --- mobilesdk/sdk/sdk.go | 10 ++++++---- wasmsdk/allocation.go | 17 ++++++++++------- zboxcore/sdk/allocation.go | 10 +++++----- zboxcore/sdk/blobber_operations.go | 6 ++++-- zboxcore/sdk/sdk.go | 3 ++- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index eaab794ad..f319cf968 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -155,7 +155,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} @@ -174,6 +174,7 @@ func (s *StorageSDK) CreateAllocation(datashards, parityshards int, size, expira BlobberIds: []string{}, FileOptionsParams: &sdk.FileOptionsParameters{}, BlobberAuthTickets: blobberAuthTickets, + AuthRoundExpiry: authRoundExpiry, } sdkAllocationID, _, _, err := sdk.CreateAllocationWith(options) @@ -196,7 +197,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} @@ -213,6 +214,7 @@ func (s *StorageSDK) CreateAllocationWithBlobbers(name string, datashards, parit WritePrice: writePrice, ReadPrice: readPrice, BlobberAuthTickets: blobberAuthTickets, + AuthRoundExpiry: authRoundExpiry, } if blobberUrls != "" { @@ -364,12 +366,12 @@ func (s *StorageSDK) 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 } diff --git a/wasmsdk/allocation.go b/wasmsdk/allocation.go index d310b10f6..25aae7861 100644 --- a/wasmsdk/allocation.go +++ b/wasmsdk/allocation.go @@ -88,7 +88,7 @@ func getAllocationBlobbers(preferredBlobberURLs []string, // - lock is the lock value to add to the allocation. // - blobberIds is the list of blobber ids. // - blobberAuthTickets is the list of blobber auth tickets in case of using restricted blobbers. -func createAllocation(datashards, parityshards int, size int64, +func createAllocation(datashards, parityshards int, size, authRoundExpiry int64, minReadPrice, maxReadPrice, minWritePrice, maxWritePrice int64, lock int64, blobberIds, blobberAuthTickets []string, setThirdPartyExtendable, IsEnterprise, force bool) ( *transaction.Transaction, error) { @@ -111,6 +111,7 @@ func createAllocation(datashards, parityshards int, size int64, StorageVersion: sdk.StorageV2, BlobberAuthTickets: blobberAuthTickets, Force: force, + AuthRoundExpiry: authRoundExpiry, } sdkLogger.Info(options) @@ -161,7 +162,8 @@ func transferAllocation(allocationID, newOwnerId, newOwnerPublicKey string) erro func UpdateForbidAllocation(allocationID string, forbidupload, forbiddelete, forbidupdate, forbidmove, forbidcopy, forbidrename bool) (string, error) { hash, _, err := sdk.UpdateAllocation( - 0, //size, + 0, //size, + 0, false, //extend, allocationID, // allocID, 0, //lock, @@ -192,7 +194,8 @@ func UpdateForbidAllocation(allocationID string, forbidupload, forbiddelete, for func freezeAllocation(allocationID string) (string, error) { hash, _, err := sdk.UpdateAllocation( - 0, //size, + 0, //size, + 0, false, //extend, allocationID, // allocID, 0, //lock, @@ -245,7 +248,7 @@ func cancelAllocation(allocationID string) (string, error) { // - addBlobberAuthTicket: blobber auth ticket to add to the allocation, in case of restricted blobbers // - removeBlobberId: blobber ID to remove from the allocation func updateAllocationWithRepair(allocationID string, - size int64, + size, authRoundExpiry int64, extend bool, lock int64, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, updateAllocTicket, callbackFuncName string) (string, error) { @@ -265,7 +268,7 @@ func updateAllocationWithRepair(allocationID string, } } - alloc, hash, isRepairRequired, err := allocationObj.UpdateWithStatus(size, extend, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, false, &sdk.FileOptionsParameters{}, updateAllocTicket) + alloc, hash, isRepairRequired, err := allocationObj.UpdateWithStatus(size, authRoundExpiry, extend, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, false, &sdk.FileOptionsParameters{}, updateAllocTicket) if err != nil { return hash, err } @@ -299,10 +302,10 @@ func updateAllocationWithRepair(allocationID string, // - removeBlobberId: blobber ID to remove from the allocation // - setThirdPartyExtendable: third party extendable flag, if true, the allocation can be extended (in terms of size) by a non-owner client func updateAllocation(allocationID string, - size int64, extend bool, + size, authRoundExpiry int64, extend bool, lock int64, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, setThirdPartyExtendable bool) (string, error) { - hash, _, err := sdk.UpdateAllocation(size, extend, allocationID, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, &sdk.FileOptionsParameters{}, "") + hash, _, err := sdk.UpdateAllocation(size, authRoundExpiry, extend, allocationID, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, &sdk.FileOptionsParameters{}, "") if err == nil { clearAllocation(allocationID) diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 03209f484..1162f2342 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -465,7 +465,7 @@ func (a *Allocation) generateAndSetOwnerSigningPublicKey() { if a.OwnerSigningPublicKey == "" && !a.Finalized && !a.Canceled && client.Wallet().IsSplit { pubKey := privateSigningKey.Public().(ed25519.PublicKey) a.OwnerSigningPublicKey = hex.EncodeToString(pubKey) - hash, _, err := UpdateAllocation(0, false, a.ID, 0, "", "", "", "", a.OwnerSigningPublicKey, false, nil, "") + hash, _, err := UpdateAllocation(0, 0, false, a.ID, 0, "", "", "", "", a.OwnerSigningPublicKey, false, nil, "") if err != nil { l.Logger.Error("Failed to update owner signing public key ", err, " allocationID: ", a.ID, " hash: ", hash) return @@ -3185,14 +3185,14 @@ func (a *Allocation) SetConsensusThreshold() { // - fileOptionsParams: The file options parameters which control permissions of the files of the allocations. // - statusCB: A callback function to receive status updates during the update operation. func (a *Allocation) UpdateWithRepair( - size int64, + size, authRoundExpiry int64, extend bool, lock uint64, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, updateAllocTicket string, statusCB StatusCallback, ) (string, error) { - updatedAlloc, hash, isRepairRequired, err := a.UpdateWithStatus(size, extend, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket) + updatedAlloc, hash, isRepairRequired, err := a.UpdateWithStatus(size, authRoundExpiry, extend, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket) if err != nil { return hash, err } @@ -3220,7 +3220,7 @@ func (a *Allocation) UpdateWithRepair( // // Returns the updated allocation, hash, and a boolean indicating whether repair is required. func (a *Allocation) UpdateWithStatus( - size int64, + size, authRoundExpiry int64, extend bool, lock uint64, addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, @@ -3236,7 +3236,7 @@ func (a *Allocation) UpdateWithStatus( } l.Logger.Info("Updating allocation") - hash, _, err := UpdateAllocation(size, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket) + hash, _, err := UpdateAllocation(size, authRoundExpiry, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket) if err != nil { return alloc, "", isRepairRequired, err } diff --git a/zboxcore/sdk/blobber_operations.go b/zboxcore/sdk/blobber_operations.go index 9caa83686..fa15777d9 100644 --- a/zboxcore/sdk/blobber_operations.go +++ b/zboxcore/sdk/blobber_operations.go @@ -34,7 +34,7 @@ func CreateAllocationForOwner( owner, ownerpublickey string, datashards, parityshards int, size int64, readPrice, writePrice PriceRange, - lock uint64, preferredBlobberIds, blobberAuthTickets []string, thirdPartyExtendable, IsEnterprise, force bool, fileOptionsParams *FileOptionsParameters, + lock uint64, preferredBlobberIds, blobberAuthTickets []string, thirdPartyExtendable, IsEnterprise, force bool, fileOptionsParams *FileOptionsParameters, authRoundExpiry int64, ) (hash string, nonce int64, txn *transaction.Transaction, err error) { if lock > math.MaxInt64 { @@ -71,6 +71,7 @@ func CreateAllocationForOwner( allocationRequest["file_options_changed"], allocationRequest["file_options"] = calculateAllocationFileOptions(63 /*0011 1111*/, fileOptionsParams) allocationRequest["is_enterprise"] = IsEnterprise allocationRequest["storage_version"] = StorageV2 + allocationRequest["auth_round_expiry"] = authRoundExpiry var sn = transaction.SmartContractTxnData{ Name: transaction.NEW_ALLOCATION_REQUEST, @@ -126,7 +127,7 @@ func CreateFreeAllocation(marker string, value uint64) (string, int64, error) { // // returns the hash of the transaction, the nonce of the transaction and an error if any. func UpdateAllocation( - size int64, + size, authRoundExpiry int64, extend bool, allocationID string, lock uint64, @@ -162,6 +163,7 @@ func UpdateAllocation( updateAllocationRequest["set_third_party_extendable"] = setThirdPartyExtendable updateAllocationRequest["owner_signing_public_key"] = ownerSigninPublicKey updateAllocationRequest["file_options_changed"], updateAllocationRequest["file_options"] = calculateAllocationFileOptions(alloc.FileOptions, fileOptionsParams) + updateAllocationRequest["auth_round_expiry"] = authRoundExpiry if ticket != "" { diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 260cd57cc..86bfcee5d 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -796,6 +796,7 @@ type CreateAllocationOptions struct { FileOptionsParams *FileOptionsParameters Force bool StorageVersion int + AuthRoundExpiry int64 } // CreateAllocationWith creates a new allocation with the given options for the current client using the SDK. @@ -809,7 +810,7 @@ func CreateAllocationWith(options CreateAllocationOptions) ( return CreateAllocationForOwner(client.Id(), client.PublicKey(), options.DataShards, options.ParityShards, options.Size, options.ReadPrice, options.WritePrice, options.Lock, - options.BlobberIds, options.BlobberAuthTickets, options.ThirdPartyExtendable, options.IsEnterprise, options.Force, options.FileOptionsParams) + options.BlobberIds, options.BlobberAuthTickets, options.ThirdPartyExtendable, options.IsEnterprise, options.Force, options.FileOptionsParams, options.AuthRoundExpiry) } // GetAllocationBlobbers returns a list of blobber ids that can be used for a new allocation. From 6205f97c3c94a57ee0856f4b9730ed933470e85b Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 19:44:43 +0530 Subject: [PATCH 05/22] Add hardfork round request --- zcncore/get_data.go | 22 ++++++++++++++++++++++ zcncore/wallet_base.go | 2 ++ 2 files changed, 24 insertions(+) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index 6a17f7aff..affea0a2b 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -374,3 +374,25 @@ func GetUserLockedTotal(clientID string) (int64, error) { return 0, err } } + +func GetHardforkRound(name string) (int64, error) { + res, err := client.MakeSCRestAPICall(MinerSmartContractAddress, GET_HARDFORK, Params{ + "name": name, + }) + if err != nil { + return 0, err + } + + var result map[string]int64 + err = json.Unmarshal(res, &result) + if err != nil { + return 0, err + } + + round, ok := result[name] + if !ok { + return 0, errors.New("hardfork not found") + } + + return round, nil +} diff --git a/zcncore/wallet_base.go b/zcncore/wallet_base.go index f4ead5968..f47b4b5f9 100644 --- a/zcncore/wallet_base.go +++ b/zcncore/wallet_base.go @@ -45,6 +45,8 @@ const ( GET_MINERSC_USER = "/getUserPools" GET_MINERSC_MINERS = "/getMinerList" GET_MINERSC_SHARDERS = "/getSharderList" + + GET_HARDFORK = "/hardfork" ) const ( From 0d88122d4ba897dc2c01c6e75a721f7bb8302b5a Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 20:06:46 +0530 Subject: [PATCH 06/22] Fix is hardfork activated --- zcncore/get_data.go | 29 ++++++++++++++++++++++++----- zcncore/wallet_base.go | 3 ++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index affea0a2b..c23576c23 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -375,24 +375,43 @@ func GetUserLockedTotal(clientID string) (int64, error) { } } -func GetHardforkRound(name string) (int64, error) { +func IsHardforkActivated(name string) (bool, error) { res, err := client.MakeSCRestAPICall(MinerSmartContractAddress, GET_HARDFORK, Params{ "name": name, }) if err != nil { - return 0, err + return false, err } var result map[string]int64 err = json.Unmarshal(res, &result) if err != nil { - return 0, err + return false, err } round, ok := result[name] if !ok { - return 0, errors.New("hardfork not found") + return false, errors.New("hardfork not found") + } + + currentRound, err := GetCurrentRound() + if err != nil { + return false, err } - return round, nil + return currentRound >= round, nil +} + +func GetCurrentRound() (int64, error) { + res, err := client.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil) + if err != nil { + return 0, err + } + + var result int64 + err = json.Unmarshal(res, &result) + if err != nil { + return 0, err + } + return result, nil } diff --git a/zcncore/wallet_base.go b/zcncore/wallet_base.go index f47b4b5f9..97a6ec052 100644 --- a/zcncore/wallet_base.go +++ b/zcncore/wallet_base.go @@ -46,7 +46,8 @@ const ( GET_MINERSC_MINERS = "/getMinerList" GET_MINERSC_SHARDERS = "/getSharderList" - GET_HARDFORK = "/hardfork" + GET_HARDFORK = "/hardfork" + GET_CURRENT_ROUND = "/v1/current-round" ) const ( From cefe782f114603a7bd9b6c92e411dcc28cfbb2ed Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 20:16:33 +0530 Subject: [PATCH 07/22] Fix --- zcncore/get_data.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index c23576c23..55f8d99ae 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -380,13 +380,13 @@ func IsHardforkActivated(name string) (bool, error) { "name": name, }) if err != nil { - return false, err + return false, fmt.Errorf("error getting hardfork status: %v", err) } var result map[string]int64 err = json.Unmarshal(res, &result) if err != nil { - return false, err + return false, fmt.Errorf("error unmarshalling hardfork status: %v", err) } round, ok := result[name] @@ -396,7 +396,7 @@ func IsHardforkActivated(name string) (bool, error) { currentRound, err := GetCurrentRound() if err != nil { - return false, err + return false, fmt.Errorf("error getting current round: %v", err) } return currentRound >= round, nil @@ -408,10 +408,16 @@ func GetCurrentRound() (int64, error) { return 0, err } - var result int64 + var result string err = json.Unmarshal(res, &result) if err != nil { - return 0, err + return 0, fmt.Errorf("error getting current round : %v", err) } - return result, nil + + round, err := strconv.ParseInt(result, 10, 64) + if err != nil { + return 0, fmt.Errorf("error parsing current round : %v", err) + } + + return round, nil } From 1d110f70662bab42d95ccb46b8652e6eac982ae8 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 20:18:48 +0530 Subject: [PATCH 08/22] Fix --- zcncore/get_data.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index 55f8d99ae..3e3c85111 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -383,17 +383,22 @@ func IsHardforkActivated(name string) (bool, error) { return false, fmt.Errorf("error getting hardfork status: %v", err) } - var result map[string]int64 + var result map[string]string err = json.Unmarshal(res, &result) if err != nil { return false, fmt.Errorf("error unmarshalling hardfork status: %v", err) } - round, ok := result[name] + roundString, ok := result[name] if !ok { return false, errors.New("hardfork not found") } + round, err := strconv.ParseInt(roundString, 10, 64) + if err != nil { + return false, fmt.Errorf("error parsing round: %v", err) + } + currentRound, err := GetCurrentRound() if err != nil { return false, fmt.Errorf("error getting current round: %v", err) From 0f4cb303af5c580c0265ce030fdcda34392a99cf Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 20:29:17 +0530 Subject: [PATCH 09/22] Fix --- zcncore/get_data.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index 3e3c85111..0ad2611d0 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -389,7 +389,7 @@ func IsHardforkActivated(name string) (bool, error) { return false, fmt.Errorf("error unmarshalling hardfork status: %v", err) } - roundString, ok := result[name] + roundString, ok := result["round"] if !ok { return false, errors.New("hardfork not found") } @@ -408,21 +408,16 @@ func IsHardforkActivated(name string) (bool, error) { } func GetCurrentRound() (int64, error) { - res, err := client.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil) + res, err := client.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil, "") if err != nil { return 0, err } - var result string - err = json.Unmarshal(res, &result) + var round int64 + err = json.Unmarshal(res, &round) if err != nil { return 0, fmt.Errorf("error getting current round : %v", err) } - round, err := strconv.ParseInt(result, 10, 64) - if err != nil { - return 0, fmt.Errorf("error parsing current round : %v", err) - } - return round, nil } From 1a0614400aedc42642d31dba71458848d0de3b98 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 20:03:37 +0530 Subject: [PATCH 10/22] test 1 --- core/client/http.go | 13 +++++---- core/client/init_node.go | 5 ++++ core/client/set.go | 27 ++++++++++++++++++ core/conf/vars.go | 5 ++++ core/transaction/get_data.go | 3 +- mobilesdk/sdk/sdk.go | 17 ++++++++---- wasmsdk/sdk.go | 19 +++++++++++-- zboxapi/sdk.go | 33 +++++++++++++++++++++- zboxcore/logger/logger.go | 4 ++- zboxcore/sdk/sdk.go | 53 ++++++++++++++++++++++++++++++------ zcnbridge/rest.go | 7 +++-- zcncore/get_data.go | 20 +++++++------- 12 files changed, 169 insertions(+), 37 deletions(-) diff --git a/core/client/http.go b/core/client/http.go index 744ce0d4b..4572b366e 100644 --- a/core/client/http.go +++ b/core/client/http.go @@ -3,14 +3,15 @@ package client import ( "encoding/json" "fmt" - "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" + + "github.com/0chain/errors" + "github.com/0chain/gosdk/core/conf" + "github.com/0chain/gosdk/core/util" + "github.com/shopspring/decimal" ) // SCRestAPIHandler is a function type to handle the response from the SC Rest API @@ -20,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/" @@ -159,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 diff --git a/core/client/init_node.go b/core/client/init_node.go index 444b33834..d356f2071 100644 --- a/core/client/init_node.go +++ b/core/client/init_node.go @@ -20,6 +20,7 @@ import ( var ( logging = logger.GetLogger() nodeClient *Node + IsAppFlow = false ) // Node Maintains central states of SDK (client's context, network). @@ -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 { diff --git a/core/client/set.go b/core/client/set.go index 3eb4d486e..f0ba52ad4 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -36,6 +36,23 @@ 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 @@ -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 } diff --git a/core/conf/vars.go b/core/conf/vars.go index 8551c1cd9..e31cbcd8f 100644 --- a/core/conf/vars.go +++ b/core/conf/vars.go @@ -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() { diff --git a/core/transaction/get_data.go b/core/transaction/get_data.go index cf7a60065..7ac58359a 100644 --- a/core/transaction/get_data.go +++ b/core/transaction/get_data.go @@ -2,6 +2,7 @@ package transaction import ( "encoding/json" + "github.com/0chain/errors" coreHttp "github.com/0chain/gosdk/core/client" ) @@ -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:") } diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index eaab794ad..1b22d06b7 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -125,11 +125,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 } diff --git a/wasmsdk/sdk.go b/wasmsdk/sdk.go index c0b78a2b6..89045bee6 100644 --- a/wasmsdk/sdk.go +++ b/wasmsdk/sdk.go @@ -40,7 +40,22 @@ func initSDKs(chainID, blockWorker, signatureScheme string, zboxApiClient.SetRequest(zboxHost, zboxAppType) - err := client.InitSDK("{}", blockWorker, chainID, signatureScheme, 0, false, minConfirmation, minSubmit, confirmationChainLength, sharderConsensous) + 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) if err != nil { fmt.Println("wasm: InitStorageSDK ", err) return err @@ -146,7 +161,7 @@ func makeSCRestAPICall(scAddress, relativePath, paramsJson string) (string, erro if err != nil { sdkLogger.Error(fmt.Sprintf("Error parsing JSON: %v", err)) } - b, err := client.MakeSCRestAPICall(scAddress, relativePath, params) + b, err := client.MakeSCRestAPICallToSharder(scAddress, relativePath, params) return string(b), err } diff --git a/zboxapi/sdk.go b/zboxapi/sdk.go index 0ac6e7064..270e18c63 100644 --- a/zboxapi/sdk.go +++ b/zboxapi/sdk.go @@ -6,11 +6,14 @@ import ( "encoding/json" "errors" "fmt" - "github.com/0chain/gosdk/core/client" + "io" "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" @@ -371,3 +374,31 @@ 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/logger/logger.go b/zboxcore/logger/logger.go index 64134eb35..0a78ddab7 100644 --- a/zboxcore/logger/logger.go +++ b/zboxcore/logger/logger.go @@ -1,7 +1,9 @@ // 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/sdk.go b/zboxcore/sdk/sdk.go index adb6eddbe..f2eba124f 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -12,6 +12,8 @@ import ( "github.com/0chain/common/core/currency" "github.com/0chain/errors" "github.com/0chain/gosdk/core/logger" + "github.com/0chain/gosdk/core/screstapi" + "go.uber.org/zap" "gopkg.in/natefinch/lumberjack.v2" "github.com/0chain/gosdk/core/client" @@ -163,7 +165,7 @@ func GetStakePoolInfo(providerType ProviderType, providerID string) (info *Stake } var b []byte - b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getStakePoolStat", + b, err = screstapi.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:") @@ -204,7 +206,7 @@ func GetStakePoolUserInfo(clientID string, offset, limit int) (info *StakePoolUs "offset": strconv.FormatInt(int64(offset), 10), "limit": strconv.FormatInt(int64(limit), 10), } - b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getUserStakePoolStat", params) if err != nil { return nil, errors.Wrap(err, "error requesting stake pool user info:") @@ -257,7 +259,7 @@ func GetChallengePoolInfo(allocID string) (info *ChallengePoolInfo, err error) { } var b []byte - b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getChallengePoolStat", map[string]string{"allocation_id": allocID}) if err != nil { return nil, errors.Wrap(err, "error requesting challenge pool info:") @@ -281,7 +283,7 @@ func GetMptData(key string) ([]byte, error) { } var b []byte - b, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/get_mpt_key", map[string]string{"key": key}, ) if err != nil { @@ -625,10 +627,19 @@ func GetAllocation(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } + + allocationBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) + if err != nil { + return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) + } + + l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationBytes))) + l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) + allocationObj := &Allocation{} err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { @@ -646,10 +657,19 @@ func GetAllocationForUpdate(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } + + allocationBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) + if err != nil { + return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) + } + + l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationBytes))) + l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) + allocationObj := &Allocation{} err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { @@ -665,11 +685,19 @@ func GetAllocationUpdates(allocation *Allocation) error { params := make(map[string]string) params["allocation"] = allocation.ID - allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } + allocationBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) + if err != nil { + return errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) + } + + l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationBytes))) + l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) + updatedAllocationObj := new(Allocation) if err := json.Unmarshal(allocationBytes, updatedAllocationObj); err != nil { return errors.New("allocation_decode_error", "Error decoding the allocation."+err.Error()) @@ -718,10 +746,19 @@ func getAllocationsInternal(clientID string, limit, offset int) ([]*Allocation, params["client"] = clientID params["limit"] = fmt.Sprint(limit) params["offset"] = fmt.Sprint(offset) - allocationsBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocations", params) + allocationsBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocations", params) if err != nil { return nil, errors.New("allocations_fetch_error", "Error fetching the allocations."+err.Error()) } + + allocationsBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocations", params) + if err != nil { + return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) + } + + l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationsBytes))) + l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationsBytes2))) + allocations := make([]*Allocation, 0) err = json.Unmarshal(allocationsBytes, &allocations) if err != nil { diff --git a/zcnbridge/rest.go b/zcnbridge/rest.go index ab860b16d..f5c12241f 100644 --- a/zcnbridge/rest.go +++ b/zcnbridge/rest.go @@ -3,6 +3,7 @@ package zcnbridge import ( "encoding/json" "fmt" + coreHttp "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/common" @@ -88,7 +89,7 @@ func GetAuthorizer(id string) (res []byte, err error) { return nil, err } - return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ + return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ "id": id, }) } @@ -101,7 +102,7 @@ func GetAuthorizers(active bool) (res []byte, err error) { if err != nil { return nil, err } - return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) + return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) } // GetGlobalConfig Returns global config @@ -111,5 +112,5 @@ func GetGlobalConfig() (res []byte, err error) { if err != nil { return nil, err } - return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) + return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) } diff --git a/zcncore/get_data.go b/zcncore/get_data.go index 6a17f7aff..fdb1f0b05 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -213,7 +213,7 @@ func withParams(uri string, params Params) string { //nolint:unused // return // } // -// return coreHttp.MakeSCRestAPICall(StorageSmartContractAddress, STORAGE_GET_BLOBBER_SNAPSHOT, Params{ +// return coreHttp.MakeSCRestAPICallToSharder(StorageSmartContractAddress, STORAGE_GET_BLOBBER_SNAPSHOT, Params{ // "round": strconv.FormatInt(round, 10), // "limit": strconv.FormatInt(limit, 10), // "offset": strconv.FormatInt(offset, 10), @@ -228,7 +228,7 @@ func GetMinerSCNodeInfo(id string) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ + return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ "id": id, }) } @@ -241,7 +241,7 @@ func GetMintNonce() ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ + return client.MakeSCRestAPICallToSharder(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ "client_id": client.Id(), }) } @@ -251,7 +251,7 @@ func GetMiners(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ + return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -264,7 +264,7 @@ func GetSharders(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ + return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -276,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 := client.MakeSCRestAPICall("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") + res, err := client.MakeSCRestAPICallToSharder("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") if err != nil { return nil, err } @@ -305,7 +305,7 @@ func GetMinerSCUserInfo(clientID string) ([]byte, error) { clientID = client.Id() } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_USER, Params{ + return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_USER, Params{ "client_id": clientID, }) } @@ -317,7 +317,7 @@ func GetMinerSCNodePool(id string) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ + return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ "id": id, "pool_id": client.Id(), }) @@ -335,7 +335,7 @@ func GetNotProcessedZCNBurnTickets(ethereumAddress, startNonce string) ([]byte, const GET_NOT_PROCESSED_BURN_TICKETS = `/v1/not_processed_burn_tickets` - return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ + return client.MakeSCRestAPICallToSharder(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ "ethereum_address": ethereumAddress, "nonce": startNonce, }) @@ -354,7 +354,7 @@ func GetUserLockedTotal(clientID string) (int64, error) { const GET_USER_LOCKED_TOTAL = `/v1/getUserLockedTotal` - info, err := client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ + info, err := client.MakeSCRestAPICallToSharder(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ "client_id": clientID, }) From 67345859df67962be9743d6a83bba569ed2ad6dd Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 20:04:27 +0530 Subject: [PATCH 11/22] new folder --- core/screstapi/http.go | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 core/screstapi/http.go diff --git a/core/screstapi/http.go b/core/screstapi/http.go new file mode 100644 index 000000000..45c9aee56 --- /dev/null +++ b/core/screstapi/http.go @@ -0,0 +1,84 @@ +package screstapi + +import ( + "context" + + "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 = client.MakeSCRestAPICallToSharder("", 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 +// } From c86e869ace51fc5fccaa2b89ce52804dc86ea4fa Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 20:06:51 +0530 Subject: [PATCH 12/22] lint fix --- zboxcore/sdk/sdk.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index f2eba124f..400015213 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -455,7 +455,7 @@ func getBlobbersInternal(active, stakable bool, limit, offset int) (bs []*Blobbe offset, strconv.FormatBool(stakable), ) - b, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, url, nil) + b, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, url, nil) var wrap nodes if err != nil { return nil, errors.Wrap(err, "error requesting blobbers:") @@ -513,7 +513,7 @@ func GetBlobber(blobberID string) (blob *Blobber, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICall( + b, err = client.MakeSCRestAPICallToSharder( STORAGE_SCADDRESS, "/getBlobber", map[string]string{"blobber_id": blobberID}, @@ -538,7 +538,7 @@ func GetValidator(validatorID string) (validator *Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICall( + b, err = client.MakeSCRestAPICallToSharder( STORAGE_SCADDRESS, "/get_validator", map[string]string{"validator_id": validatorID}, @@ -563,7 +563,7 @@ func GetValidators(stakable bool) (validators []*Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICall( + b, err = client.MakeSCRestAPICallToSharder( STORAGE_SCADDRESS, "/validators", map[string]string{ @@ -884,7 +884,7 @@ func GetAllocationBlobbers( params["force"] = strconv.FormatBool(force[0]) } - allocBlobber, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", params) + allocBlobber, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/alloc_blobbers", params) if err != nil { return nil, err } @@ -971,7 +971,7 @@ func GetBlobberIds(blobberUrls []string) ([]string, error) { params := make(map[string]string) params["blobber_urls"] = string(urlsStr) - idsStr, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", params) + idsStr, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/blobber_ids", params) if err != nil { return nil, err } @@ -996,7 +996,7 @@ func GetFreeAllocationBlobbers(request map[string]interface{}) ([]string, error) params := make(map[string]string) params["free_allocation_data"] = string(data) - allocBlobber, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) + allocBlobber, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) if err != nil { return nil, err } @@ -1442,7 +1442,7 @@ func GetUpdateAllocationMinLock( params := make(map[string]string) params["data"] = string(data) - responseBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) + responseBytes, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) if err != nil { return 0, errors.Wrap(err, "failed to request allocation update min lock") } From f3dee3cfc7a515d7f82f8528a65a7bb3470b5549 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 20:42:08 +0530 Subject: [PATCH 13/22] test 2 --- zboxcore/sdk/sdk.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 400015213..a83a67b30 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -283,7 +283,7 @@ func GetMptData(key string) ([]byte, error) { } var b []byte - b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/get_mpt_key", map[string]string{"key": key}, ) if err != nil { @@ -641,7 +641,7 @@ func GetAllocation(allocationID string) (*Allocation, error) { l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) allocationObj := &Allocation{} - err = json.Unmarshal(allocationBytes, allocationObj) + err = json.Unmarshal(allocationBytes2, allocationObj) if err != nil { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } @@ -671,7 +671,7 @@ func GetAllocationForUpdate(allocationID string) (*Allocation, error) { l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) allocationObj := &Allocation{} - err = json.Unmarshal(allocationBytes, allocationObj) + err = json.Unmarshal(allocationBytes2, allocationObj) if err != nil { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } @@ -699,7 +699,7 @@ func GetAllocationUpdates(allocation *Allocation) error { l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) updatedAllocationObj := new(Allocation) - if err := json.Unmarshal(allocationBytes, updatedAllocationObj); err != nil { + if err := json.Unmarshal(allocationBytes2, updatedAllocationObj); err != nil { return errors.New("allocation_decode_error", "Error decoding the allocation."+err.Error()) } @@ -760,7 +760,7 @@ func getAllocationsInternal(clientID string, limit, offset int) ([]*Allocation, l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationsBytes2))) allocations := make([]*Allocation, 0) - err = json.Unmarshal(allocationsBytes, &allocations) + err = json.Unmarshal(allocationsBytes2, &allocations) if err != nil { return nil, errors.New("allocations_decode_error", "Error decoding the allocations."+err.Error()) } From 5c7ed0871dfcb6c6ae18437a1240c9a2dd3ca789 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 21:38:44 +0530 Subject: [PATCH 14/22] test 2 --- zboxcore/sdk/sdk.go | 49 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index a83a67b30..d9ac51cab 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -13,7 +13,6 @@ import ( "github.com/0chain/errors" "github.com/0chain/gosdk/core/logger" "github.com/0chain/gosdk/core/screstapi" - "go.uber.org/zap" "gopkg.in/natefinch/lumberjack.v2" "github.com/0chain/gosdk/core/client" @@ -627,21 +626,13 @@ 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.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } - allocationBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) - if err != nil { - return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) - } - - l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationBytes))) - l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) - allocationObj := &Allocation{} - err = json.Unmarshal(allocationBytes2, allocationObj) + err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } @@ -657,21 +648,13 @@ 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.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } - allocationBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) - if err != nil { - return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) - } - - l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationBytes))) - l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) - allocationObj := &Allocation{} - err = json.Unmarshal(allocationBytes2, allocationObj) + err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } @@ -685,21 +668,13 @@ 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.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } - allocationBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) - if err != nil { - return errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) - } - - l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationBytes))) - l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationBytes2))) - updatedAllocationObj := new(Allocation) - if err := json.Unmarshal(allocationBytes2, updatedAllocationObj); err != nil { + if err := json.Unmarshal(allocationBytes, updatedAllocationObj); err != nil { return errors.New("allocation_decode_error", "Error decoding the allocation."+err.Error()) } @@ -746,21 +721,13 @@ 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.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocations", params) if err != nil { return nil, errors.New("allocations_fetch_error", "Error fetching the allocations."+err.Error()) } - allocationsBytes2, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocations", params) - if err != nil { - return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) - } - - l.Logger.Debug("0box res allocation", zap.Any("response", string(allocationsBytes))) - l.Logger.Debug("sharder res allocation", zap.Any("response", string(allocationsBytes2))) - allocations := make([]*Allocation, 0) - err = json.Unmarshal(allocationsBytes2, &allocations) + err = json.Unmarshal(allocationsBytes, &allocations) if err != nil { return nil, errors.New("allocations_decode_error", "Error decoding the allocations."+err.Error()) } From 04299ea0b5282aa1084f742bb51edc115865c6d9 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 22:15:51 +0530 Subject: [PATCH 15/22] test 3 --- zboxcore/sdk/sdk.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index d9ac51cab..6608ad7a2 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -668,7 +668,7 @@ func GetAllocationUpdates(allocation *Allocation) error { params := make(map[string]string) params["allocation"] = allocation.ID - allocationBytes, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } @@ -721,7 +721,7 @@ func getAllocationsInternal(clientID string, limit, offset int) ([]*Allocation, params["client"] = clientID params["limit"] = fmt.Sprint(limit) params["offset"] = fmt.Sprint(offset) - allocationsBytes, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocations", params) + allocationsBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocations", params) if err != nil { return nil, errors.New("allocations_fetch_error", "Error fetching the allocations."+err.Error()) } From 8898b7d41005bc9b5f0c01ecb720e2638e5225ed Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 22:33:48 +0530 Subject: [PATCH 16/22] test 4 --- zboxcore/sdk/sdk.go | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 6608ad7a2..edcf8d747 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -282,7 +282,7 @@ func GetMptData(key string) ([]byte, error) { } var b []byte - b, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, + b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/get_mpt_key", map[string]string{"key": key}, ) if err != nil { @@ -448,13 +448,9 @@ func getBlobbersInternal(active, stakable bool, limit, offset int) (bs []*Blobbe Nodes []*Blobber } - url := fmt.Sprintf("/getblobbers?active=%s&limit=%d&offset=%d&stakable=%s", - strconv.FormatBool(active), - limit, - offset, - strconv.FormatBool(stakable), - ) - b, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, url, nil) + 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)}) var wrap nodes if err != nil { return nil, errors.Wrap(err, "error requesting blobbers:") @@ -512,7 +508,7 @@ func GetBlobber(blobberID string) (blob *Blobber, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICallToSharder( + b, err = screstapi.MakeSCRestAPICall( STORAGE_SCADDRESS, "/getBlobber", map[string]string{"blobber_id": blobberID}, @@ -537,7 +533,7 @@ func GetValidator(validatorID string) (validator *Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICallToSharder( + b, err = screstapi.MakeSCRestAPICall( STORAGE_SCADDRESS, "/get_validator", map[string]string{"validator_id": validatorID}, @@ -562,7 +558,7 @@ func GetValidators(stakable bool) (validators []*Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICallToSharder( + b, err = screstapi.MakeSCRestAPICall( STORAGE_SCADDRESS, "/validators", map[string]string{ @@ -626,7 +622,7 @@ func GetAllocation(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } @@ -648,7 +644,7 @@ func GetAllocationForUpdate(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } @@ -851,7 +847,7 @@ func GetAllocationBlobbers( params["force"] = strconv.FormatBool(force[0]) } - allocBlobber, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/alloc_blobbers", params) + allocBlobber, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", params) if err != nil { return nil, err } @@ -938,7 +934,7 @@ func GetBlobberIds(blobberUrls []string) ([]string, error) { params := make(map[string]string) params["blobber_urls"] = string(urlsStr) - idsStr, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/blobber_ids", params) + idsStr, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", params) if err != nil { return nil, err } @@ -963,7 +959,7 @@ func GetFreeAllocationBlobbers(request map[string]interface{}) ([]string, error) params := make(map[string]string) params["free_allocation_data"] = string(data) - allocBlobber, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) + allocBlobber, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) if err != nil { return nil, err } @@ -1409,7 +1405,7 @@ func GetUpdateAllocationMinLock( params := make(map[string]string) params["data"] = string(data) - responseBytes, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) + responseBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) if err != nil { return 0, errors.Wrap(err, "failed to request allocation update min lock") } From 4a24461246f14f4829493bfe74abcccf2f22c080 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 22:55:40 +0530 Subject: [PATCH 17/22] test 5 --- core/screstapi/http.go | 46 +++++++++++++++++++++------------------- wasmsdk/sdk.go | 3 ++- wasmsdk/zcn.go | 4 ++-- winsdk/wallet.go | 5 +++-- zcncore/get_data.go | 19 +++++++++-------- zcncore/wallet_mobile.go | 3 ++- 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index 45c9aee56..095305230 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -2,6 +2,7 @@ package screstapi import ( "context" + "encoding/json" "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/conf" @@ -56,29 +57,30 @@ func MakeSCRestAPICallToZbox(relativePath string, params map[string]string) ([]b return resp, nil } -// func GetBalance(clientIDs ...string) (*client.GetBalanceResponse, error) { -// var clientID string -// if len(clientIDs) > 0 { -// clientID = clientIDs[0] -// } else { -// clientID = client.Id() -// } +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 -// ) + const GetBalanceUrl = "client/get/balance" + var ( + balance client.GetBalanceResponse + err error + resp []byte + ) -// if resp, err = client.MakeSCRestAPICallToSharder("", GetBalanceUrl, map[string]string{ -// "client_id": clientID, -// }, "v1/"); err != nil { -// return nil, err -// } + if resp, err = client.MakeSCRestAPICallToSharder("", GetBalanceUrl, map[string]string{ + "client_id": clientID, + }, "v1/"); err != nil { + return nil, err + } -// if err = json.Unmarshal(resp, &balance); err != nil { -// return nil, err -// } + if err = json.Unmarshal(resp, &balance); err != nil { + return nil, err + } -// return &balance, err -// } + return &balance, err +} diff --git a/wasmsdk/sdk.go b/wasmsdk/sdk.go index 89045bee6..07f9974ad 100644 --- a/wasmsdk/sdk.go +++ b/wasmsdk/sdk.go @@ -12,6 +12,7 @@ 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" @@ -161,7 +162,7 @@ func makeSCRestAPICall(scAddress, relativePath, paramsJson string) (string, erro if err != nil { sdkLogger.Error(fmt.Sprintf("Error parsing JSON: %v", err)) } - b, err := client.MakeSCRestAPICallToSharder(scAddress, relativePath, params) + b, err := screstapi.MakeSCRestAPICall(scAddress, relativePath, params) return string(b), err } diff --git a/wasmsdk/zcn.go b/wasmsdk/zcn.go index bb3a53a3d..f0272e4b5 100644 --- a/wasmsdk/zcn.go +++ b/wasmsdk/zcn.go @@ -4,7 +4,7 @@ package main import ( - "github.com/0chain/gosdk/core/client" + "github.com/0chain/gosdk/core/screstapi" "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 := client.GetBalance(clientId) + bal, err := screstapi.GetBalance(clientId) if err != nil { return nil, err } diff --git a/winsdk/wallet.go b/winsdk/wallet.go index 0e72008f8..51762ea61 100644 --- a/winsdk/wallet.go +++ b/winsdk/wallet.go @@ -8,10 +8,11 @@ import ( ) import ( - "github.com/0chain/gosdk/core/client" "os" "path/filepath" + "github.com/0chain/gosdk/core/screstapi" + "github.com/0chain/gosdk/zcncore" ) @@ -87,7 +88,7 @@ func RecoverWallet(mnemonic *C.char) *C.char { // //export GetWalletBalance func GetWalletBalance(clientID *C.char) *C.char { - b, err := client.GetBalance(C.GoString(clientID)) + b, err := screstapi.GetBalance(C.GoString(clientID)) if err != nil { log.Error("win: ", err) return WithJSON(0, err) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index fdb1f0b05..dcc343b1d 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -10,6 +10,7 @@ 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" @@ -228,7 +229,7 @@ func GetMinerSCNodeInfo(id string) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ "id": id, }) } @@ -241,7 +242,7 @@ func GetMintNonce() ([]byte, error) { return nil, err } - return client.MakeSCRestAPICallToSharder(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ + return screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ "client_id": client.Id(), }) } @@ -251,7 +252,7 @@ func GetMiners(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -264,7 +265,7 @@ func GetSharders(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -276,7 +277,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 := client.MakeSCRestAPICallToSharder("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") + res, err := screstapi.MakeSCRestAPICall("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") if err != nil { return nil, err } @@ -305,7 +306,7 @@ func GetMinerSCUserInfo(clientID string) ([]byte, error) { clientID = client.Id() } - return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_USER, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_USER, Params{ "client_id": clientID, }) } @@ -317,7 +318,7 @@ func GetMinerSCNodePool(id string) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICallToSharder(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ "id": id, "pool_id": client.Id(), }) @@ -335,7 +336,7 @@ func GetNotProcessedZCNBurnTickets(ethereumAddress, startNonce string) ([]byte, const GET_NOT_PROCESSED_BURN_TICKETS = `/v1/not_processed_burn_tickets` - return client.MakeSCRestAPICallToSharder(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ + return screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ "ethereum_address": ethereumAddress, "nonce": startNonce, }) @@ -354,7 +355,7 @@ func GetUserLockedTotal(clientID string) (int64, error) { const GET_USER_LOCKED_TOTAL = `/v1/getUserLockedTotal` - info, err := client.MakeSCRestAPICallToSharder(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ + info, err := screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ "client_id": clientID, }) diff --git a/zcncore/wallet_mobile.go b/zcncore/wallet_mobile.go index 7fd9b0564..b84955efd 100644 --- a/zcncore/wallet_mobile.go +++ b/zcncore/wallet_mobile.go @@ -5,6 +5,7 @@ package zcncore import ( "github.com/0chain/gosdk/core/client" + "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/core/zcncrypto" ) @@ -31,7 +32,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 := client.GetBalance(id) + response, err := screstapi.GetBalance(id) if err != nil { return 0, err } From 3f9b9adc68ca6070ab5d1d3d3fa5936b837857ee Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 13 Jan 2025 22:58:14 +0530 Subject: [PATCH 18/22] test 5 --- core/screstapi/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index 095305230..53f5823b5 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -72,7 +72,7 @@ func GetBalance(clientIDs ...string) (*client.GetBalanceResponse, error) { resp []byte ) - if resp, err = client.MakeSCRestAPICallToSharder("", GetBalanceUrl, map[string]string{ + if resp, err = MakeSCRestAPICall("", GetBalanceUrl, map[string]string{ "client_id": clientID, }, "v1/"); err != nil { return nil, err From 6272db39ae066b53db914485c8afe8511ce991a2 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Wed, 15 Jan 2025 15:04:00 +0530 Subject: [PATCH 19/22] 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 29a659a9e..f6f752e76 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 := client.MakeSCRestAPICall(MinerSmartContractAddress, GET_HARDFORK, Params{ + res, err := screstapi.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 := client.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil, "") + res, err := screstapi.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil, "") if err != nil { return 0, err } From 4933fa5602a5740dfdbffd720a7fbf0c5e49d991 Mon Sep 17 00:00:00 2001 From: Jayash Satolia <73050737+Jayashsatolia403@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:15:14 +0530 Subject: [PATCH 20/22] Feature view change (#1736) --- zcncore/execute_transactions.go | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/zcncore/execute_transactions.go b/zcncore/execute_transactions.go index 45c49a5ad..5a75ddde8 100644 --- a/zcncore/execute_transactions.go +++ b/zcncore/execute_transactions.go @@ -3,6 +3,7 @@ package zcncore import ( "fmt" "github.com/0chain/gosdk/core/transaction" + "github.com/0chain/gosdk/zboxcore/sdk" ) // AuthorizerNode represents an authorizer node in the network @@ -220,3 +221,39 @@ func Faucet(tokens uint64, input string, client ...string) (hash, out string, no InputArgs: input, }, tokens, true, client...) } + +func DeleteMiner(id string) (hash, out string, nonce int64, txn *transaction.Transaction, err error) { + return transaction.SmartContractTxn(MinerSmartContractAddress, transaction.SmartContractTxnData{ + Name: "delete_miner", + InputArgs: &MinerSCMinerInfo{ + SimpleMiner: SimpleMiner{ + ID: id, + }, + }, + }, true) +} + +func DeleteSharder(id string) (hash, out string, nonce int64, txn *transaction.Transaction, err error) { + return transaction.SmartContractTxn(MinerSmartContractAddress, transaction.SmartContractTxnData{ + Name: "delete_sharder", + InputArgs: &MinerSCMinerInfo{ + SimpleMiner: SimpleMiner{ + ID: id, + }, + }, + }, true) +} + +func VcRegisterNode(id string, nodeType sdk.ProviderType) (hash, out string, nonce int64, txn *transaction.Transaction, err error) { + type VCAddSCData struct { + ID string + Type int + } + return transaction.SmartContractTxnValueFee(MinerSmartContractAddress, transaction.SmartContractTxnData{ + Name: "vc_add", + InputArgs: VCAddSCData{ + ID: id, + Type: int(nodeType), + }, + }, 0, 10000000000, true) +} From 88a3acacf247628f9ff5de6faf48c28e032cd338 Mon Sep 17 00:00:00 2001 From: shahnawaz-creator <117025384+shahnawaz-creator@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:58:31 +0530 Subject: [PATCH 21/22] Update build-sdks.yml to macos-latest runner --- .github/workflows/build-sdks.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-sdks.yml b/.github/workflows/build-sdks.yml index c8ae4e35a..34ac83854 100644 --- a/.github/workflows/build-sdks.yml +++ b/.github/workflows/build-sdks.yml @@ -18,7 +18,7 @@ env: jobs: build-ios: name: Build-ios - runs-on: macos-runner + runs-on: macos-latest steps: - name: Checkout code @@ -193,7 +193,7 @@ jobs: build-macos: name: Build-macos - runs-on: macos-runner + runs-on: macos-latest steps: - name: Checkout code @@ -355,4 +355,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: zcn.wasm - path: zcn.wasm \ No newline at end of file + path: zcn.wasm From e3474c292394727da6012d3632c4279537a7fe99 Mon Sep 17 00:00:00 2001 From: Yash Verma Date: Fri, 24 Jan 2025 11:08:14 +0530 Subject: [PATCH 22/22] update upload artifact action in workflows. (#1738) Co-authored-by: Jayash Satolia <73050737+Jayashsatolia403@users.noreply.github.com> --- .github/workflows/build-release-wasm.yaml | 2 +- .github/workflows/build-sdks.yml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-release-wasm.yaml b/.github/workflows/build-release-wasm.yaml index 125022d24..477bd3d15 100644 --- a/.github/workflows/build-release-wasm.yaml +++ b/.github/workflows/build-release-wasm.yaml @@ -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 \ No newline at end of file diff --git a/.github/workflows/build-sdks.yml b/.github/workflows/build-sdks.yml index 34ac83854..1034fd8ba 100644 --- a/.github/workflows/build-sdks.yml +++ b/.github/workflows/build-sdks.yml @@ -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: | @@ -186,7 +186,7 @@ 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 @@ -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: | @@ -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: | @@ -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