Skip to content

Commit

Permalink
Hotfix: added supported type for transaction creation method for mobi…
Browse files Browse the repository at this point in the history
…le (#1616)

* fix: added supported type for transaction creation method

* fix: fixed bugs

* Updated go version for andriod build in build-sdks.yml

* fix: fixed bugs

* fix: fixed bugs

* fix: provided separation for blobber operation

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* fix: fixed bugs

* update go in build-sdks.yml

---------

Co-authored-by: shahnawaz-creator <[email protected]>
  • Loading branch information
YarikRevich and shahnawaz-creator authored Sep 21, 2024
1 parent 21ce33a commit 293cd4a
Show file tree
Hide file tree
Showing 12 changed files with 992 additions and 446 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go 1.x
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22

- name: Clean build
run: make clean-mobilesdk
Expand Down Expand Up @@ -96,10 +96,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go 1.x
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22

- name: Install deps
run: |
Expand Down Expand Up @@ -199,10 +199,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go 1.x
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22

- name: Clean build
run: make clean-mobilesdk
Expand Down Expand Up @@ -271,10 +271,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go 1.x
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22

- name: Install deps
run: |
Expand Down
6 changes: 3 additions & 3 deletions mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ func (s *StorageSDK) GetReadPoolInfo(clientID string) (string, error) {
func (s *StorageSDK) WritePoolLock(durInSeconds int64, tokens, fee float64, allocID string) error {
_, _, err := sdk.WritePoolLock(
allocID,
zcncore.ConvertTokenToSAS(tokens),
zcncore.ConvertTokenToSAS(fee))
strconv.FormatUint(zcncore.ConvertTokenToSAS(tokens), 10),
strconv.FormatUint(zcncore.ConvertTokenToSAS(fee), 10))
return err
}

Expand Down Expand Up @@ -406,7 +406,7 @@ func (s *StorageSDK) RedeemFreeStorage(ticket string) (string, error) {
return "", fmt.Errorf("invalid_free_marker: free marker is not assigned to your wallet")
}

hash, _, err := sdk.CreateFreeAllocation(marker, lock)
hash, _, err := sdk.CreateFreeAllocation(marker, strconv.FormatUint(lock, 10))
return hash, err
}

Expand Down
18 changes: 2 additions & 16 deletions mobilesdk/zcn/readpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package zcn

import (
"github.com/0chain/gosdk/core/util"
"github.com/0chain/gosdk/zboxcore/sdk"
)

Expand All @@ -13,29 +12,16 @@ import (
// - tokens: sas tokens
// - fee: sas tokens
func ReadPoolLock(tokens, fee string) (string, error) {
t, err := util.ParseCoinStr(tokens)
if err != nil {
return "", err
}
hash, _, err := sdk.ReadPoolLock(tokens, fee)

f, err := util.ParseCoinStr(fee)
if err != nil {
return "", err
}

hash, _, err := sdk.ReadPoolLock(t, f)
return hash, err
}

// ReadPoolUnLock unlocks all the tokens in the readpool associated with the current wallet.
// ## Inputs
// - fee: sas tokens
func ReadPoolUnLock(fee string) (string, error) {
f, err := util.ParseCoinStr(fee)
if err != nil {
return "", err
}
hash, _, err := sdk.ReadPoolUnlock(fee)

hash, _, err := sdk.ReadPoolUnlock(f)
return hash, err
}
12 changes: 3 additions & 9 deletions mobilesdk/zcn/smartcontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package zcn
import (
"encoding/json"
"fmt"
"strconv"
"sync"

"github.com/0chain/gosdk/zcncore"
Expand All @@ -17,22 +16,17 @@ func Faucet(methodName, jsonInput string, zcnToken float64) (string, error) {
return ExecuteSmartContract(zcncore.FaucetSmartContractAddress, methodName, jsonInput, zcncore.ConvertToValue(zcnToken))
}

func ExecuteSmartContract(address, methodName, input string, sasToken string) (string, error) {
func ExecuteSmartContract(address, methodName, input, sasToken string) (string, error) {
wg := &sync.WaitGroup{}
cb := &transactionCallback{wg: wg}
txn, err := zcncore.NewTransaction(cb, 0, 0)
txn, err := zcncore.NewTransaction(cb, "0", 0)
if err != nil {
return "", err
}

wg.Add(1)

v, err := strconv.ParseUint(sasToken, 10, 64)
if err != nil {
return "", fmt.Errorf("invalid token value: %v, err: %v", sasToken, err)
}

_, err = txn.ExecuteSmartContract(address, methodName, input, v)
_, err = txn.ExecuteSmartContract(address, methodName, input, sasToken)
if err != nil {
return "", err

Expand Down
9 changes: 1 addition & 8 deletions mobilesdk/zcn/writepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package zcn

import (
"github.com/0chain/gosdk/core/util"
"github.com/0chain/gosdk/zboxcore/sdk"
)

Expand All @@ -14,13 +13,7 @@ import (
// - tokens: sas tokens
// - fee: sas tokens
func WritePoolLock(allocID string, tokens, fee string) (string, error) {
t, err := util.ParseCoinStr(tokens)
if err != nil {
return "", err
}

f, err := util.ParseCoinStr(fee)
hash, _, err := sdk.WritePoolLock(allocID, t, f)
hash, _, err := sdk.WritePoolLock(allocID, tokens, fee)

return hash, err
}
Loading

0 comments on commit 293cd4a

Please sign in to comment.