Skip to content

Commit 8e4827a

Browse files
Merge branch 'sprint-1.19' into feat/upload-timings
2 parents fee1409 + e3474c2 commit 8e4827a

File tree

31 files changed

+617
-107
lines changed

31 files changed

+617
-107
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build & Push Normal Wasm
2+
3+
concurrency:
4+
group: "build-release-wasm-${{ github.ref }}"
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
# branches: [ master, staging, qa ]
10+
tags:
11+
- 'v*.*.*'
12+
# pull_request:
13+
workflow_dispatch:
14+
15+
jobs:
16+
build-wasm:
17+
name: Build-wasm
18+
runs-on: [self-hosted, arc-runner]
19+
outputs:
20+
build_version: ${{ steps.wasm_build.outputs.BUILD_TAG }}
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Build wasm binary using go version 1.22.5
28+
id: wasm_build
29+
run: |
30+
docker run --rm -v $PWD:/gosdk -w /gosdk golang:1.22.5 sh -c "git config --global --add safe.directory /gosdk; make wasm-build"
31+
BUILD_TAG=zcn-$(git describe --tags --exact-match)-normal.wasm
32+
BUILD_TAG="${BUILD_TAG:0:4}${BUILD_TAG:5}"
33+
mv zcn.wasm $BUILD_TAG
34+
echo "BUILD_TAG=$BUILD_TAG" >>$GITHUB_OUTPUT
35+
36+
- name: 'Upload Artifact'
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: ${{ steps.wasm_build.outputs.BUILD_TAG }}
40+
path: ${{ steps.wasm_build.outputs.BUILD_TAG }}
41+
42+
- name: Install AWS cli
43+
run: |
44+
sudo apt update -y
45+
sudo apt install awscli -y
46+
47+
- name: Copy the wasm binary to aws s3.
48+
run: |
49+
export AWS_ACCESS_KEY_ID=${{ secrets.WEBAPP_STATIC_ACCESS_KEY }}
50+
export AWS_SECRET_ACCESS_KEY=${{ secrets.WEBAPP_STATIC_SECRET_ACCESS_KEY }}
51+
export AWS_DEFAULT_REGION=${{ secrets.WEBAPP_STATIC_REGION }}
52+
gzip -9 ${{ steps.wasm_build.outputs.BUILD_TAG }} && mv ${{ steps.wasm_build.outputs.BUILD_TAG }}.gz ${{ steps.wasm_build.outputs.BUILD_TAG }}
53+
aws s3 cp ${{ steps.wasm_build.outputs.BUILD_TAG }} s3://${{ secrets.WEBAPP_STATIC_BUCKET }}/wasm/${{ steps.wasm_build.outputs.BUILD_TAG }} --content-encoding gzip
54+
55+
- name: Invalidate wasm binary
56+
run: |
57+
export AWS_ACCESS_KEY_ID=${{ secrets.WEBAPP_STATIC_ACCESS_KEY }}
58+
export AWS_SECRET_ACCESS_KEY=${{ secrets.WEBAPP_STATIC_SECRET_ACCESS_KEY }}
59+
export AWS_DEFAULT_REGION=${{ secrets.WEBAPP_STATIC_REGION }}
60+
aws cloudfront create-invalidation --distribution-id ${{ secrets.WEBAPP_STATIC_DISTRIBUTION_ID }} --paths '/wasm/*'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build-and-release-wasm
2+
3+
concurrency:
4+
group: "build-release-wasm-${{ github.ref }}"
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
# branches: [ master, staging, qa ]
10+
tags:
11+
- 'v*.*.*'
12+
# pull_request:
13+
workflow_dispatch:
14+
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GOSDK }}
17+
18+
jobs:
19+
build-wasm:
20+
name: Build-wasm
21+
runs-on: [self-hosted, arc-runner]
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
# - name: Set up Go 1.23
27+
# uses: actions/setup-go@v3
28+
# with:
29+
# go-version: 1.23
30+
31+
- name: Install dependencies
32+
run: |
33+
sudo apt-get update
34+
sudo apt-get -y install build-essential nghttp2 libnghttp2-dev libssl-dev wget
35+
36+
- name: Build
37+
run: |
38+
docker run --rm -v $PWD:/gosdk -w /gosdk golang:1.23 make wasm-build
39+
ls -lha
40+
CURRENT_TAG=$(git describe --tags --exact-match)
41+
mv zcn.wasm zcn-${CURRENT_TAG}-normal.wasm
42+
ls -lha
43+
44+
# - name: 'Upload Artifact'
45+
# uses: actions/upload-artifact@v4
46+
# with:
47+
# name: zcn.wasm
48+
# path: zcn.wasm

.github/workflows/build-sdks.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
jobs:
1919
build-ios:
2020
name: Build-ios
21-
runs-on: macos-runner
21+
runs-on: macos-latest
2222

2323
steps:
2424
- name: Checkout code
@@ -82,7 +82,7 @@ jobs:
8282
file_glob: true
8383

8484
- name: Upload Artifact
85-
uses: actions/upload-artifact@v3
85+
uses: actions/upload-artifact@v4
8686
with:
8787
name: zcncore-ios
8888
path: |
@@ -186,14 +186,14 @@ jobs:
186186
file_glob: true
187187

188188
- name: Upload Artifact
189-
uses: actions/upload-artifact@v3
189+
uses: actions/upload-artifact@v4
190190
with:
191191
name: zcncore-android
192192
path: zcncore-android.tar.gz
193193

194194
build-macos:
195195
name: Build-macos
196-
runs-on: macos-runner
196+
runs-on: macos-latest
197197

198198
steps:
199199
- name: Checkout code
@@ -257,7 +257,7 @@ jobs:
257257
file_glob: true
258258

259259
- name: Upload Artifact
260-
uses: actions/upload-artifact@v3
260+
uses: actions/upload-artifact@v4
261261
with:
262262
name: zcncore-macos
263263
path: |
@@ -325,7 +325,7 @@ jobs:
325325
file_glob: true
326326

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

354354
- name: 'Upload Artifact'
355-
uses: actions/upload-artifact@v3
355+
uses: actions/upload-artifact@v4
356356
with:
357357
name: zcn.wasm
358-
path: zcn.wasm
358+
path: zcn.wasm

core/client/http.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package client
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/0chain/errors"
7-
"github.com/0chain/gosdk/core/conf"
8-
"github.com/0chain/gosdk/core/util"
9-
"github.com/shopspring/decimal"
106
"log"
117
"net/http"
128
"net/url"
139
"sync"
10+
11+
"github.com/0chain/errors"
12+
"github.com/0chain/gosdk/core/conf"
13+
"github.com/0chain/gosdk/core/util"
14+
"github.com/shopspring/decimal"
1415
)
1516

1617
// SCRestAPIHandler is a function type to handle the response from the SC Rest API
@@ -20,7 +21,7 @@ import (
2021
// `err` - the error if any
2122
type SCRestAPIHandler func(response map[string][]byte, numSharders int, err error)
2223

23-
func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error) {
24+
func MakeSCRestAPICallToSharder(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error) {
2425
const (
2526
consensusThresh = float32(25.0)
2627
ScRestApiUrl = "v1/screst/"
@@ -159,7 +160,7 @@ func GetBalance(clientIDs ...string) (*GetBalanceResponse, error) {
159160
clientID = Id()
160161
}
161162

162-
if res, err = MakeSCRestAPICall("", GetBalance, map[string]string{
163+
if res, err = MakeSCRestAPICallToSharder("", GetBalance, map[string]string{
163164
"client_id": clientID,
164165
}, "v1/"); err != nil {
165166
return nil, err

core/client/init_node.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ import (
1818
)
1919

2020
var (
21-
logging logger.Logger
21+
logging = logger.GetLogger()
2222
nodeClient *Node
23+
IsAppFlow = false
2324
)
2425

25-
func init() {
26-
logging.Init(logger.DEBUG, "0chain-core")
27-
}
28-
2926
// Node Maintains central states of SDK (client's context, network).
3027
// Initialized through [Init] function.
3128
// Use client.GetNode() to get its instance after Init is called.
@@ -38,6 +35,10 @@ type Node struct {
3835
networkGuard sync.RWMutex
3936
}
4037

38+
func SetIsAppFlow(val bool) {
39+
IsAppFlow = true
40+
}
41+
4142
// GetStableMiners Returns stable miner urls.
4243
// Length of stable miners is depedent on config's MinSubmit and number of miners in network.
4344
func (n *Node) GetStableMiners() []string {

core/client/set.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ type Client struct {
3636
sign SignFunc
3737
}
3838

39+
type InitSdkOptions struct {
40+
WalletJSON string
41+
BlockWorker string
42+
ChainID string
43+
SignatureScheme string
44+
Nonce int64
45+
IsSplitWallet bool
46+
AddWallet bool
47+
TxnFee *int
48+
MinConfirmation *int
49+
MinSubmit *int
50+
ConfirmationChainLength *int
51+
SharderConsensous *int
52+
ZboxHost string
53+
ZboxAppType string
54+
}
55+
3956
func init() {
4057
sys.Sign = signHash
4158
sys.SignWithAuth = signHash
@@ -326,6 +343,16 @@ func InitSDK(walletJSON string,
326343
return nil
327344
}
328345

346+
func InitSDKWithWebApp(params InitSdkOptions) error {
347+
err := InitSDK(params.WalletJSON, params.BlockWorker, params.ChainID, params.SignatureScheme, params.Nonce, params.AddWallet, *params.MinConfirmation, *params.MinSubmit, *params.ConfirmationChainLength, *params.SharderConsensous)
348+
if err != nil {
349+
return err
350+
}
351+
conf.SetZboxAppConfigs(params.ZboxHost, params.ZboxAppType)
352+
SetIsAppFlow(true)
353+
return nil
354+
}
355+
329356
func IsSDKInitialized() bool {
330357
return sdkInitialized
331358
}

core/conf/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func LoadConfig(v Reader) (Config, error) {
177177
cfg.SignatureScheme = v.GetString("signature_scheme")
178178
cfg.ChainID = v.GetString("chain_id")
179179
cfg.ZauthServer = v.GetString("zauth_server")
180+
cfg.EthereumNode = v.GetString("ethereum_node_url")
180181

181182
return cfg, nil
182183
}

core/conf/vars.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func GetClientConfig() (*Config, error) {
3939
return cfg, nil
4040
}
4141

42+
func SetZboxAppConfigs(zboxHost, zboxAppType string) {
43+
cfg.ZboxHost = zboxHost
44+
cfg.ZboxAppType = zboxAppType
45+
}
46+
4247
// InitClientConfig set global client config
4348
func InitClientConfig(c *Config) {
4449
onceCfg.Do(func() {

core/logger/logger.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package logger
33

44
import (
55
"fmt"
6+
"github.com/0chain/gosdk/core/version"
7+
"gopkg.in/natefinch/lumberjack.v2"
68
"io"
79
"log"
810
"os"
@@ -142,3 +144,39 @@ func (l *Logger) Close() {
142144
}
143145
}
144146
}
147+
148+
// Initialize common logger
149+
var logging Logger
150+
151+
func GetLogger() *Logger {
152+
return &logging
153+
}
154+
155+
func CloseLog() {
156+
logging.Close()
157+
}
158+
159+
func init() {
160+
logging.Init(DEBUG, "0chain-core-sdk")
161+
}
162+
163+
// SetLogLevel set the log level.
164+
// lvl - 0 disabled; higher number (upto 4) more verbosity
165+
func SetLogLevel(lvl int) {
166+
logging.SetLevel(lvl)
167+
}
168+
169+
// SetLogFile - sets file path to write log
170+
// verbose - true - console output; false - no console output
171+
func SetLogFile(logFile string, verbose bool) {
172+
ioWriter := &lumberjack.Logger{
173+
Filename: logFile,
174+
MaxSize: 100, // MB
175+
MaxBackups: 5, // number of backups
176+
MaxAge: 28, //days
177+
LocalTime: false,
178+
Compress: false, // disabled by default
179+
}
180+
logging.SetLogFile(ioWriter, verbose)
181+
logging.Info("******* Wallet SDK Version:", version.VERSIONSTR, " ******* (SetLogFile)")
182+
}

0 commit comments

Comments
 (0)