-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sprint-1.19' into kms/peter-staging-4
* 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
Showing
24 changed files
with
361 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.