Skip to content

Commit

Permalink
Merge branch 'sprint-1.11' into winsdk-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
boddumanohar committed Nov 29, 2023
2 parents 29bd86a + 9857209 commit 3a14dc5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 125 deletions.
47 changes: 36 additions & 11 deletions .github/workflows/build-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ jobs:
echo "::set-output name=RELEASE::false"
echo "::set-output name=TAG::none"
elif [[ ${tag} = v*\.*\.* ]] ; then
echo "> 0Chain: trigger from git event"
# upload output on release
echo "::set-output name=RELEASE::true"
echo "::set-output name=TAG::${tag}"
Expand Down Expand Up @@ -159,17 +159,17 @@ jobs:
run: |
tag=$(echo ${GITHUB_REF#refs/tags/})
echo ${tag}
if [[ "${{github.event_name}}" = "workflow_dispatch" ]]; then
echo "> 0Chain: trigger from workflow_dispatch"
echo "::set-output name=RELEASE::false"
echo "::set-output name=TAG::none"
elif [[ ${tag} = v*\.*\.* ]] ; then
echo "> 0Chain: trigger from git event"
# upload output on release
echo "::set-output name=RELEASE::true"
echo "::set-output name=TAG::${tag}"
Expand Down Expand Up @@ -237,10 +237,10 @@ jobs:
echo "::set-output name=RELEASE::false"
echo "::set-output name=TAG::none"
elif [[ ${tag} = v*\.*\.* ]] ; then
echo "> 0Chain: trigger from git event"
# upload output on release
echo "::set-output name=RELEASE::true"
echo "::set-output name=TAG::${tag}"
Expand All @@ -263,7 +263,6 @@ jobs:
path: |
zcncore-macos.tar.gz
build-windows:
name: Build-windows
runs-on: [self-hosted, arc-runner]
Expand Down Expand Up @@ -306,10 +305,10 @@ jobs:
echo "::set-output name=RELEASE::false"
echo "::set-output name=TAG::none"
elif [[ ${tag} = v*\.*\.* ]] ; then
echo "> 0Chain: trigger from git event"
# upload output on release
echo "::set-output name=RELEASE::true"
echo "::set-output name=TAG::${tag}"
Expand All @@ -331,3 +330,29 @@ jobs:
name: zcn-windows
path: |
zcn-windows.zip
build-wasm:
name: Build-wasm
runs-on: [self-hosted, arc-runner]
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v2
with:
go-version: ^1.20

- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y install build-essential nghttp2 libnghttp2-dev libssl-dev wget
- name: Build
run: docker run --rm -v $PWD:/gosdk -w /gosdk golang:1.20 make wasm-build

- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: zcn.wasm
path: zcn.wasm
85 changes: 5 additions & 80 deletions .github/workflows/sdk-release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
name: GoSDK & WasmSDK
name: GoSDK Release

concurrency:
group: "sdk-${{ github.ref }}"
cancel-in-progress: true

on:
push:
branches: [ master, staging, qa ]
branches: [ master, staging, qa, sprint-* ]
tags:
- 'v*.*.*'
pull_request:
workflow_dispatch:
inputs:
version:
Expand All @@ -20,105 +19,31 @@ env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

jobs:
build:
name: sdk-build
runs-on: [self-hosted, arc-runner]
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v2
with:
go-version: ^1.20

- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y install build-essential nghttp2 libnghttp2-dev libssl-dev wget
- name: Setup Build
id: setup_build
run: |
tag=$(echo ${GITHUB_REF#refs/tags/})
echo ${tag}
if [[ -n "${{github.event.inputs.version}}" ]]; then
echo "> 0Chain: trigger from workflow_dispatch"
echo "::set-output name=PR::true"
gosdk="{\"gosdk\":\"${{github.event.inputs.version}}\"}"
echo "::set-output name=SDK::${gosdk}"
elif [[ ${tag} = v*\.*\.* ]] ; then
echo "> 0Chain: trigger from git event"
echo "::set-output name=PR::true"
gosdk="{\"gosdk\":\"${tag}\"}"
echo "::set-output name=SDK::${gosdk}"
# upload zcn.wasm on release
echo "::set-output name=RELEASE::true"
echo "::set-output name=TAG::${tag}"
elif [[ ${tag} = "refs/heads/staging" ]] ; then
echo "> 0Chain: trigger from git event"
echo "::set-output name=PR::true"
gosdk="{\"gosdk\":\"staging\"}"
echo "::set-output name=SDK::${gosdk}"
# upload zcn.wasm on release
echo "::set-output name=RELEASE::true"
echo "::set-output name=TAG::${tag}"
fi
- name: Build
run: docker run --rm -v $PWD:/gosdk -w /gosdk golang:1.20 make wasm-build

- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
if: steps.setup_build.outputs.RELEASE == 'true'
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: zcn.wasm
tag: ${{ steps.setup_build.outputs.TAG }}
overwrite: true
file_glob: true

- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: zcn.wasm
path: zcn.wasm
outputs:
PR: ${{ steps.setup_build.outputs.PR }}
SDK: ${{ steps.setup_build.outputs.SDK }}
TAG: ${{ steps.setup_build.outputs.TAG }}

release:
name: sdk-release
needs: build
if: needs.build.outputs.PR == 'true'
runs-on: [self-hosted, build]
steps:
- name: start to create pr
run: |
echo "GoSDK & WebAssembly SDK should be upgraded"
create-pr:
name: create-pr
strategy:
fail-fast: false
max-parallel: 1
matrix:
repo: [0nft, 0box, 0dns, zwalletcli, zboxcli, blobber, zs3server, s3-migration, token_bridge_authserver ]
needs: [ build, release ]
needs: [ release ]
runs-on: [self-hosted, build]
steps:
- name: Create PR on ${{ matrix.repo }}
uses: convictional/trigger-workflow-and-wait@v1.3.0
if: needs.build.outputs.PR == 'true'
with:
owner: 0chain
repo: ${{ matrix.repo }}
ref: staging
ref: ${{ github.head_ref || github.ref_name }}
github_token: ${{ secrets.GOSDK }}
workflow_file_name: gosdk.yml
inputs: ${{ needs.build.outputs.SDK }}
Expand Down
5 changes: 2 additions & 3 deletions wasmsdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,11 @@ func updateAllocation(allocationID string,

func getAllocationMinLock(datashards, parityshards int,
size int64,
maxreadPrice, maxwritePrice uint64,
maxwritePrice uint64,
) (int64, error) {
readPrice := sdk.PriceRange{Min: 0, Max: maxreadPrice}
writePrice := sdk.PriceRange{Min: 0, Max: maxwritePrice}

value, err := sdk.GetAllocationMinLock(datashards, parityshards, size, readPrice, writePrice)
value, err := sdk.GetAllocationMinLock(datashards, parityshards, size, writePrice)
if err != nil {
sdkLogger.Error(err)
return 0, err
Expand Down
6 changes: 6 additions & 0 deletions wasmsdk/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,9 @@ func multiUpload(jsonBulkUploadOptions string) (MultiUploadResult, error) {
if numBlocks < 1 {
numBlocks = 100
}
if allocationObj.DataShards > 7 {
numBlocks = 60
}
options := []sdk.ChunkedUploadOption{
sdk.WithThumbnail(option.ThumbnailBytes.Buffer),
sdk.WithEncrypt(encrypt),
Expand Down Expand Up @@ -711,6 +714,9 @@ func uploadWithJsFuncs(allocationID, remotePath string, readChunkFuncName string
if numBlocks < 1 {
numBlocks = 100
}
if allocationObj.DataShards > 7 {
numBlocks = 60
}

ChunkedUpload, err := sdk.CreateChunkedUpload("/", allocationObj, fileMeta, fileReader, isUpdate, isRepair, webStreaming, zboxutil.NewConnectionId(),
sdk.WithThumbnail(thumbnailBytes),
Expand Down
1 change: 1 addition & 0 deletions zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func CreateChunkedUpload(
for _, opt := range opts {
opt(su)
}

if su.progressStorer == nil {
su.progressStorer = createFsChunkedUploadProgress(context.Background())
}
Expand Down
24 changes: 3 additions & 21 deletions zboxcore/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,32 +1567,14 @@ func CommitToFabric(metaTxnData, fabricConfigJSON string) (string, error) {
func GetAllocationMinLock(
datashards, parityshards int,
size int64,
readPrice, writePrice PriceRange,
writePrice PriceRange,
) (int64, error) {
baSize := int64(math.Ceil(float64(size) / float64(datashards)))
totalSize := baSize * int64(datashards+parityshards)
config, err := GetStorageSCConfig()
if err != nil {
return 0, err
}
t := config.Fields["time_unit"]
timeunitStr, ok := t.(string)
if !ok {
return 0, fmt.Errorf("bad time_unit type")
}
timeunit, err := time.ParseDuration(timeunitStr)
if err != nil {
return 0, fmt.Errorf("bad time_unit format")
}

expiry := common.Timestamp(time.Now().Add(timeunit).Unix())
duration := expiry / common.Timestamp(timeunit.Milliseconds())
if expiry%common.Timestamp(timeunit.Milliseconds()) != 0 {
duration++
}

sizeInGB := float64(totalSize) / GB
cost := float64(duration) * (sizeInGB*float64(writePrice.Max) + sizeInGB*float64(readPrice.Max))

cost := sizeInGB * float64(writePrice.Max)
coin, err := currency.Float64ToCoin(cost)
if err != nil {
return 0, err
Expand Down
9 changes: 8 additions & 1 deletion zcnbridge/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func CreateKeyStorage(homedir, password string) error {
type AccountAddressIndex struct {
AccountIndex int
AddressIndex int
Bip32 bool
}

// ImportAccount imports account using mnemonic
Expand All @@ -149,7 +150,13 @@ func ImportAccount(homedir, mnemonic, password string, accountAddrIndex ...Accou
aai = accountAddrIndex[0]
}

pathD := hdw.MustParseDerivationPath(fmt.Sprintf("m/44'/60'/0'/%d/%d", aai.AccountIndex, aai.AddressIndex))
var pathD accounts.DerivationPath
if aai.Bip32 {
pathD = hdw.MustParseDerivationPath(fmt.Sprintf("m/44'/60'/0'/%d", aai.AddressIndex))
} else {
pathD = hdw.MustParseDerivationPath(fmt.Sprintf("m/44'/60'/%d'/0/%d", aai.AccountIndex, aai.AddressIndex))
}

account, err := wallet.Derive(pathD, true)
if err != nil {
return "", errors.Wrap(err, "failed parse derivation path")
Expand Down
11 changes: 2 additions & 9 deletions zcncore/wallet_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,24 +1282,17 @@ func Decrypt(key, text string) (string, error) {
func CryptoJsEncrypt(passphrase, message string) (string, error) {
o := openssl.New()

enc, err := o.EncryptBytes(pad(passphrase, 32, ","), []byte(message), openssl.DigestMD5Sum)
enc, err := o.EncryptBytes(passphrase, []byte(message), openssl.DigestMD5Sum)
if err != nil {
return "", err
}

return string(enc), nil
}

func pad(passphrase string, i int, symbol string) string {
if len(passphrase) < i {
return passphrase + strings.Repeat(symbol, i-len(passphrase))
}
return passphrase
}

func CryptoJsDecrypt(passphrase, encryptedMessage string) (string, error) {
o := openssl.New()
dec, err := o.DecryptBytes(pad(passphrase, 32, ","), []byte(encryptedMessage), openssl.DigestMD5Sum)
dec, err := o.DecryptBytes(passphrase, []byte(encryptedMessage), openssl.DigestMD5Sum)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 3a14dc5

Please sign in to comment.