Skip to content

Commit

Permalink
Fix/fail shardedr on bad code (#1264)
Browse files Browse the repository at this point in the history
* Fix/remove path (#1221)

* feature: added more test cases

* fix: fixed existing test cases

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* feature: added more test cases

* feature: added more test cases

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* feature: added mocks

* fix: fixed bugs

* fix: fixed mocks

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* fix: made components internal

* Add webstreaming to multiupload (#1190)

* add webstreaming

* fix typos

* add webstreaming to wasm multiupload

* fix typo

* fix dup upload consensus (#1195)

* Fix multiupload completed callback (#1172)

* remove unnecessary print

* fix delete and createdir

* return major error

* add webstreaming

* fix typos

* add webstreaming to wasm multiupload

* fix typo

* cleanup

* fix completed callback

* Feat/update methods in WinSDK (#1198)

* delete dir in repair (#1196)

* delete dir in repair

* replace ioutil

* fix unit test

* fix list worker test

* fix rename dir error

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* Add NFT Config contract (#1212)

* Silent the zcnbridge http request when --silent (#1207)

* Change the return type of downloadBlocks to []byte in wasm (#1218)

* change the order of exchanges to get the ZCN prices (#1216)

* Deprecate non multi-operation functions (#1214)

* remove CreateDir, Rename, Copy, Move

* use docker build wasm

* use @v4 version of git action

* Revert "use @v4 version of git action"

This reverts commit fbb93f2.

* Updated self hosted macos runner (#1219)

* Updated self hosted macos runner

* fixed runner name build-sdks.yml

* remove path header, fix ws tag

---------

Co-authored-by: YarikRevich <yariksvitlitskiy2@gmail.com>
Co-authored-by: Yaroslav Svitlytskyi <53532703+YarikRevich@users.noreply.github.com>
Co-authored-by: Dinmukhammed Kambarov <52813950+din-mukhammed@users.noreply.github.com>
Co-authored-by: Hitenjain14 <57557631+Hitenjain14@users.noreply.github.com>
Co-authored-by: Lz <imlangzi@qq.com>
Co-authored-by: Yaroslav Svitlytskyi <yariksvitlitskiy81@gmail.com>
Co-authored-by: peterlimg <54137706+peterlimg@users.noreply.github.com>
Co-authored-by: Kishan Dhakan <42718091+Kishan-Dhakan@users.noreply.github.com>
Co-authored-by: Manohar Reddy <b.manu199@gmail.com>
Co-authored-by: shahnawaz-creator <117025384+shahnawaz-creator@users.noreply.github.com>
Co-authored-by: din-mukhammed <dimash.r53@gmail.com>

* Revert "Fix/remove path (#1221)" (#1222)

This reverts commit 464260a.

* remove path header, fix ws tag (#1223)

* remove path header, fix ws tag

* fixed broken build

---------

Co-authored-by: din-mukhammed <dimash.r53@gmail.com>

* Updated self hosted macos runner (#1219)

* Updated self hosted macos runner

* fixed runner name build-sdks.yml

(cherry picked from commit 1c9f143)

* updated wasm binary build fix.

* README grammar and formatting tweaks.

* Merge remote-tracking branch 'origin/feature/sharder-keep-list' into feature/sharder-keep-list

---------

Co-authored-by: YarikRevich <yariksvitlitskiy2@gmail.com>
Co-authored-by: Yaroslav Svitlytskyi <53532703+YarikRevich@users.noreply.github.com>
Co-authored-by: Dinmukhammed Kambarov <52813950+din-mukhammed@users.noreply.github.com>
Co-authored-by: Hitenjain14 <57557631+Hitenjain14@users.noreply.github.com>
Co-authored-by: Lz <imlangzi@qq.com>
Co-authored-by: Yaroslav Svitlytskyi <yariksvitlitskiy81@gmail.com>
Co-authored-by: peterlimg <54137706+peterlimg@users.noreply.github.com>
Co-authored-by: Kishan Dhakan <42718091+Kishan-Dhakan@users.noreply.github.com>
Co-authored-by: Manohar Reddy <b.manu199@gmail.com>
Co-authored-by: shahnawaz-creator <117025384+shahnawaz-creator@users.noreply.github.com>
Co-authored-by: din-mukhammed <dimash.r53@gmail.com>
Co-authored-by: shahnawaz-creator <msac8225@gmail.com>
Co-authored-by: UncertainBadg3r <139782199+UncertainBadg3r@users.noreply.github.com>
  • Loading branch information
14 people committed Oct 29, 2023
1 parent e992911 commit 39776e7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 22 deletions.
44 changes: 22 additions & 22 deletions README.md
Expand Up @@ -37,7 +37,7 @@ This repository currently supports the following platforms:
### Instructions
- Go is required to build gosdk code. Instructions can be found [here](https://go.dev/doc/install)

1. Save below code as sdkversion.go
1. Save below code as `sdkversion.go`

package main

Expand All @@ -64,18 +64,18 @@ This repository currently supports the following platforms:


## Mobile Builds
- gosdk can be build to use on Mobile platforms iOS and Android using gomobile.
- Xcode Command Line Tools is required to build SDK for iOS.
- Android studio with NDK is required to build SDK for Android.
- gosdk can be built for iOS and Android using gomobile.
- Xcode Command Line Tools is required to build the SDK for iOS.
- Android studio with NDK is required to build the SDK for Android.
- See [FAQ](#faq) for installing Go, gomobile Xcode or Android Studio.

Steps:
1. Run below command for the first time to setup gomobile environment
1. Run the command below for the first time to setup the gomobile environment:

make setup-gomobile
2. In case Go package not found in golang.org/x/mobile/bind, run the command
2. In case the Go package is not found in `golang.org/x/mobile/bind`, run:
`go get golang.org/x/mobile/bind`
3. Use below commands in the root folder of the repo to build Mobile SDK
3. Run below commands in the root folder of the repo to build the Mobile SDK:

For iOS only:
make build-ios
Expand All @@ -84,14 +84,14 @@ Steps:

## Expose a gosdk function to mobilesdk
Examples:
* `mobilesdk/sdk/common.go` which exports the functions in `core/encryption/hash.go`.
* `mobilesdk/sdk/common.go`, which exports the functions in `core/encryption/hash.go`.

Steps:

1. If you are exposing:

- a new function from an existing file like `zboxcore/sdk/allocation.go`, you should add a function to `mobilesdksdk/zbox/allocation.go` which should call the gosdk function you intend to expose.
- a function from a new file, you should create a new `<filename>.go` file for it, in the same style as `mobilesdksdk/zbox/allocation.go` & in the file created, you should call the gosdk function you intend to expose.
- a new function from an existing file, such as `zboxcore/sdk/allocation.go`, you should add a function to `mobilesdksdk/zbox/allocation.go`. This new function should call the gosdk function you intend to expose.
- a function from a new file, you should create a new `<filename>.go` file for it. This should follow the same style as `mobilesdksdk/zbox/allocation.go`. In the new file, call the gosdk function you intend to expose.

2. Build the Mobile SDK as mentioned in the 'Mobile Builds' section of this file to build the aar file used in the mobile application you are developing.

Expand Down Expand Up @@ -123,7 +123,7 @@ Steps:

### An important note regarding export of an async function

If your golang function requires to be run asynchronously, you need to add more wrapper code where you are returning a Promise object.
If your golang function needs to suport asynchronous execution, you need to add more wrapper code where you are returning a Promise object.

See "InitZCNSDK" example:

Expand Down Expand Up @@ -157,18 +157,18 @@ func InitZCNSDK(this js.Value, p []js.Value) interface{} {

### BLS unit test

It's advisable to put GOPATH as $TOP/../go, to avoid conflicts with this command: `go build ./...`
It's advisable to put GOPATH as `$TOP/../go`, to avoid conflicts with this command: `go build ./...`

To run all the unit tests in `gosdk`: go test github.com/0chain/gosdk/zboxcore/sdk -v`
To run all the unit tests in `gosdk`: `go test github.com/0chain/gosdk/zboxcore/sdk -v`
```bash
$ go test ./...
```

To run all the unit tests in `bls0chain_test.go`, run this command from $TOP: `go test github.com/0chain/gosdk/core/zcncrypto -v`

To run a specific unit test in `bls0chain_test.go` such as `TestSignatureScheme`, run this: `go test github.com/0chain/gosdk/core/zcncrypto -v -run TestSignatureScheme`
To run a specific unit test in `bls0chain_test.go`, such as `TestSignatureScheme`, run: `go test github.com/0chain/gosdk/core/zcncrypto -v -run TestSignatureScheme`

To run the coverage test in `gosdk:
To run the coverage test in `gosdk`:
```bash
$ go test <path_to_folder> -coverprofile=coverage.out
$ go tool cover -html=coverage.out
Expand All @@ -180,32 +180,32 @@ $ go tool cover -html=coverage.out

1. You need to install nodejs first, see [this page](https://nodejs.org/en/download/) for further instructions

2. Add `/path/to/go/misc/wasm` to your `$PATH` environment variable (so that "go test" can find "go_js_wasm_exec"). For example in ubuntu, run `$export PATH=$PATH:/usr/local/go/misc/wasm/`.
2. Add `/path/to/go/misc/wasm` to your `$PATH` environment variable (so that `go test` can find `go_js_wasm_exec`). For example in Ubuntu, run `$export PATH=$PATH:/usr/local/go/misc/wasm/`.

3. You can then run the test by following the [BLS unit test](#bls-unit-test) above by adding the prefix environment `GOOS=js CGO_ENABLED=0 GOARCH=wasm`:
```
```bash
go test -tags test -v github.com/0chain/gosdk/wasmsdk
```

#### Test in the client

1. After you successfully [export the wasm package to proxy.wasm](#how-to-export-a-gosdk-function-to-webassembly), now you can test that `proxy.wasm`.
1. After you successfully [export the wasm package to proxy.wasm](#how-to-export-a-gosdk-function-to-webassembly), you can test the exported `proxy.wasm`.

2. We currently have a test page going at the js-client-sdk repo: `https://github.com/0chain/js-client-sdk/blob/gosdk/test/index.html`

3. You can replace the proxy.wasm at `https://github.com/0chain/js-client-sdk/blob/gosdk/test/proxy.wasm`

4. You need to startup a special test server in order to stream WASM files. Use this command from js-client-sdk $TOP: `sudo php -S localhost:82 test/server.php`
4. You need to start a special test server in order to stream WASM files. Use the following command from js-client-sdk $TOP: `sudo php -S localhost:82 test/server.php`

5. See "testethwallet" function in index.html for how the testing for ethwallet.go is done
5. See "testethwallet" function in index.html for how the testing for ethwallet.go is done.

6. To test the function you exported, it's probably as simple as calling "HelloWorld()". It should be a 1-liner.

### How to install `ffmpeg`

### On linux ubuntu
#### On Ubuntu Linux

```
```bash
sudo apt-get install ffmpeg
sudo apt-get install v4l-utils
```
Expand Down
46 changes: 46 additions & 0 deletions wasmsdk/blobber.go
Expand Up @@ -510,6 +510,52 @@ func MultiOperation(allocationID string, jsonMultiUploadOptions string) error {
return allocationObj.DoMultiOperation(operations)
}

func bulkUpload(jsonBulkUploadOptions string) ([]BulkUploadResult, error) {
var options []BulkUploadOption
err := json.Unmarshal([]byte(jsonBulkUploadOptions), &options)
if err != nil {
return nil, err
}

n := len(options)
wait := make(chan BulkUploadResult, 1)

for _, option := range options {
go func(o BulkUploadOption) {
result := BulkUploadResult{
RemotePath: o.RemotePath,
}
defer func() { wait <- result }()

ok, err := uploadWithJsFuncs(o.AllocationID, o.RemotePath,
o.ReadChunkFuncName,
o.FileSize,
o.ThumbnailBytes.Buffer,
o.IsWebstreaming,
o.Encrypt,
o.IsUpdate,
o.IsRepair,
o.NumBlocks,
o.CallbackFuncName)
result.Success = ok
if err != nil {
result.Error = err.Error()
result.Success = false
}

}(option)

}

results := make([]BulkUploadResult, 0, n)
for i := 0; i < n; i++ {
result := <-wait
results = append(results, result)
}

return results, nil
}

func multiUpload(jsonBulkUploadOptions string) (MultiUploadResult, error) {
var options []BulkUploadOption
result := MultiUploadResult{}
Expand Down
5 changes: 5 additions & 0 deletions zboxcore/zboxutil/http.go
Expand Up @@ -838,6 +838,11 @@ func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]
defer response.Body.Close()
entityBytes, _ := ioutil.ReadAll(response.Body)
mu.Lock()
if response.StatusCode > http.StatusBadRequest {
blockchain.Sharders.Fail(sharder)
} else {
blockchain.Sharders.Success(sharder)
}
responses[response.StatusCode]++
if responses[response.StatusCode] > maxCount {
maxCount = responses[response.StatusCode]
Expand Down

0 comments on commit 39776e7

Please sign in to comment.