github.com/0chain/gosdk@v1.17.11/wasmsdk/zcn.go (about) 1 //go:build js && wasm 2 // +build js,wasm 3 4 package main 5 6 import ( 7 "github.com/0chain/gosdk/zboxcore/sdk" 8 "github.com/0chain/gosdk/zcncore" 9 ) 10 11 type Balance struct { 12 ZCN float64 `json:"zcn"` 13 USD float64 `json:"usd"` 14 Nonce int64 `json:"nonce"` 15 } 16 17 // getWalletBalance retrieves the wallet balance of the client from the network. 18 // - clientId is the client id 19 func getWalletBalance(clientId string) (*Balance, error) { 20 21 zcn, nonce, err := zcncore.GetWalletBalance(clientId) 22 if err != nil { 23 return nil, err 24 } 25 26 zcnToken, err := zcn.ToToken() 27 if err != nil { 28 return nil, err 29 } 30 31 usd, err := zcncore.ConvertTokenToUSD(zcnToken) 32 if err != nil { 33 return nil, err 34 } 35 36 return &Balance{ 37 ZCN: zcnToken, 38 USD: usd, 39 Nonce: nonce, 40 }, nil 41 } 42 43 // createReadPool creates a read pool for the client where they should lock tokens to be able to read data. 44 func createReadPool() (string, error) { 45 hash, _, err := sdk.CreateReadPool() 46 return hash, err 47 }