Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi wallet #1675

Draft
wants to merge 22 commits into
base: sprint-1.19
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7db2dff
Fix multi wallet
Jayashsatolia403 Nov 16, 2024
a8a5927
Merge branch 'refs/heads/staging' into fix/multi-wallet
Jayashsatolia403 Nov 20, 2024
d7bb9a5
Merge branch 'staging' into fix/multi-wallet
yash10019coder Dec 6, 2024
51d0f30
Merge remote-tracking branch 'origin/staging' into fix/multi-wallet
smaulik13 Dec 14, 2024
84a682a
Merge branch 'sprint-1.19' into fix/multi-wallet
Jayashsatolia403 Jan 2, 2025
7f125fc
Empty commit
Jayashsatolia403 Jan 3, 2025
46e0ced
Merge branch 'sprint-1.19' of github.com:0chain/gosdk into fix/multi-…
yash10019coder Jan 16, 2025
479aebc
* SendWithCustom fee method.
yash10019coder Jan 23, 2025
ad98ef0
Merge branch 'sprint-1.19' of github.com:0chain/gosdk into fix/multi-…
yash10019coder Jan 23, 2025
b58111f
* add blobber sc
yash10019coder Jan 26, 2025
e0ecce1
Merge branch 'sprint-1.19' of github.com:0chain/gosdk into fix/multi-…
yash10019coder Jan 26, 2025
ac5667c
nit fix update allocation.
yash10019coder Jan 26, 2025
3a58428
Merge branch 'sprint-1.19' of github.com:0chain/gosdk into fix/multi-…
yash10019coder Feb 2, 2025
63540e6
debug: memory leak/
yash10019coder Feb 7, 2025
5521ac8
Merge branch 'sprint-1.19' of github.com:0chain/gosdk into fix/multi-…
yash10019coder Feb 7, 2025
b16b85b
fix: syntax issue.
yash10019coder Feb 7, 2025
d8022a6
fix
yash10019coder Feb 7, 2025
b42d0cb
fix mobilesdk.
yash10019coder Feb 8, 2025
deea587
fix unit tests.
yash10019coder Feb 8, 2025
8632996
revert memory leak code.
yash10019coder Feb 9, 2025
03145da
fix: public key for multi wallet.
yash10019coder Feb 9, 2025
79c07f0
revert public key in set.go
yash10019coder Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/conf/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TestLoadConfig(t *testing.T) {

var mockDefaultReader = func() Reader {
reader := &mocks.Reader{}
reader.On("GetString", "ethereum_node_url").Return("https://127.0.0.1:8545")
reader.On("GetString", "block_worker").Return("http://127.0.0.1:9091/dns")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestLoadConfig(t *testing.T) {
setup: func(t *testing.T) Reader {

reader := &mocks.Reader{}
reader.On("GetString", "ethereum_node_url").Return("https://127.0.0.1:8545")
reader.On("GetString", "block_worker").Return("")
reader.On("GetString", "zauth_server").Return("")
reader.On("GetInt", "min_submit").Return(0)
Expand Down Expand Up @@ -86,6 +88,7 @@ func TestLoadConfig(t *testing.T) {
setup: func(t *testing.T) Reader {

reader := &mocks.Reader{}
reader.On("GetString", "ethereum_node_url").Return("https://127.0.0.1:8545")
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(101)
Expand Down Expand Up @@ -121,6 +124,7 @@ func TestLoadConfig(t *testing.T) {
setup: func(t *testing.T) Reader {

reader := &mocks.Reader{}
reader.On("GetString", "ethereum_node_url").Return("https://127.0.0.1:8545")
reader.On("GetString", "block_worker").Return("https://127.0.0.1:9091/dns")
reader.On("GetString", "zauth_server").Return("http://127.0.0.1:8090/")
reader.On("GetInt", "min_submit").Return(0)
Expand Down
1 change: 1 addition & 0 deletions core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const (
STORAGESC_RESET_ALLOCATION_STATS = "reset_allocation_stats"
STORAGESC_RESET_BLOBBER_VERSION = "update_blobber_version"
STORAGESC_INSERT_KILLED_PROVIDER_ID = "insert_killed_provider_id"
STORAGESC_ADD_BLOBBER = "add_blobber"

MINERSC_LOCK = "addToDelegatePool"
MINERSC_UNLOCK = "deleteFromDelegatePool"
Expand Down
4 changes: 2 additions & 2 deletions mobilesdk/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ func (s *StorageSDK) GetVersion() string {
// - extend: extend allocation
// - allocationID: allocation ID
// - lock: Number of tokens to lock to the allocation after the update
func (s *StorageSDK) UpdateAllocation(size, authRoundExpiry int64, extend bool, allocationID string, lock uint64) (hash string, err error) {
func (s *StorageSDK) UpdateAllocation(size int64, extend bool, allocationID string, lock uint64) (hash string, err error) {
if lock > math.MaxInt64 {
return "", errors.Errorf("int64 overflow in lock")
}

hash, _, err = sdk.UpdateAllocation(size, authRoundExpiry, extend, allocationID, lock, "", "", "", "", "", false, &sdk.FileOptionsParameters{}, "")
hash, _, err = sdk.UpdateAllocation(size, extend, allocationID, lock, "", "", "", "", "", false, &sdk.FileOptionsParameters{}, "")
return hash, err
}

Expand Down
36 changes: 34 additions & 2 deletions play.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
package main

import (
"fmt"
"github.com/0chain/gosdk/core/client"
"sync"
"time"
)

func main() {
fmt.Printf("Now = %v\n", Now())
clientId := "90cbab94239ef9c74ec83f8e616fb921a5dd8b36214b1b514e5010b449e5f162"

err := client.InitSDK("", "https://dev.zus.network/dns", "0afc093ffb509f059c55478bc1a60351cef7b4e9c008a53a6cc8241ca8617dfe", "bls0chain", 0, false)
if err != nil {
println(err.Error())
return
}

size := 1000
resChan := make(chan *client.GetBalanceResponse, size)

var wg sync.WaitGroup
for i := 0; i < size; i++ {
wg.Add(1)
go func() {
defer wg.Done()
res, err := client.GetBalance(clientId)
if err != nil {
println(i, err.Error())
return
}
resChan <- res
}()
}

wg.Wait()

for i := 0; i < size; i++ {
res := <-resChan
println(i, res.Balance)
}

}

// Timestamp represents Unix time (e.g. in seconds)
Expand Down
8 changes: 3 additions & 5 deletions wasmsdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ func transferAllocation(allocationID, newOwnerId, newOwnerPublicKey string) erro
func UpdateForbidAllocation(allocationID string, forbidupload, forbiddelete, forbidupdate, forbidmove, forbidcopy, forbidrename bool) (string, error) {

hash, _, err := sdk.UpdateAllocation(
0, //size,
0,
0, //size,
false, //extend,
allocationID, // allocID,
0, //lock,
Expand Down Expand Up @@ -194,8 +193,7 @@ func UpdateForbidAllocation(allocationID string, forbidupload, forbiddelete, for
func freezeAllocation(allocationID string) (string, error) {

hash, _, err := sdk.UpdateAllocation(
0, //size,
0,
0, //size,
false, //extend,
allocationID, // allocID,
0, //lock,
Expand Down Expand Up @@ -305,7 +303,7 @@ func updateAllocation(allocationID string,
size, authRoundExpiry int64, extend bool,
lock int64,
addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerSigninPublicKey string, setThirdPartyExtendable bool) (string, error) {
hash, _, err := sdk.UpdateAllocation(size, authRoundExpiry, extend, allocationID, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, &sdk.FileOptionsParameters{}, "")
hash, _, err := sdk.UpdateAllocation(size, extend, allocationID, uint64(lock), addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, &sdk.FileOptionsParameters{}, "")

if err == nil {
clearAllocation(allocationID)
Expand Down
4 changes: 2 additions & 2 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (a *Allocation) generateAndSetOwnerSigningPublicKey() {
if a.OwnerSigningPublicKey == "" && !a.Finalized && !a.Canceled && client.Wallet().IsSplit {
pubKey := privateSigningKey.Public().(ed25519.PublicKey)
a.OwnerSigningPublicKey = hex.EncodeToString(pubKey)
hash, _, err := UpdateAllocation(0, 0, false, a.ID, 0, "", "", "", "", a.OwnerSigningPublicKey, false, nil, "")
hash, _, err := UpdateAllocation(0, false, a.ID, 0, "", "", "", "", a.OwnerSigningPublicKey, false, nil, "")
if err != nil {
l.Logger.Error("Failed to update owner signing public key ", err, " allocationID: ", a.ID, " hash: ", hash)
return
Expand Down Expand Up @@ -3236,7 +3236,7 @@ func (a *Allocation) UpdateWithStatus(
}

l.Logger.Info("Updating allocation")
hash, _, err := UpdateAllocation(size, authRoundExpiry, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket)
hash, _, err := UpdateAllocation(size, extend, a.ID, lock, addBlobberId, addBlobberAuthTicket, removeBlobberId, "", ownerSigninPublicKey, setThirdPartyExtendable, fileOptionsParams, updateAllocTicket)
if err != nil {
return alloc, "", isRepairRequired, err
}
Expand Down
17 changes: 8 additions & 9 deletions zboxcore/sdk/blobber_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func CreateAllocationForOwner(
owner, ownerpublickey string,
datashards, parityshards int, size int64,
readPrice, writePrice PriceRange,
lock uint64, preferredBlobberIds, blobberAuthTickets []string, thirdPartyExtendable, IsEnterprise, force bool, fileOptionsParams *FileOptionsParameters, authRoundExpiry int64,
lock uint64, preferredBlobberIds, blobberAuthTickets []string, thirdPartyExtendable, IsEnterprise, force bool, fileOptionsParams *FileOptionsParameters, authRoundExpiry int64, clients ...string,
) (hash string, nonce int64, txn *transaction.Transaction, err error) {

if lock > math.MaxInt64 {
Expand Down Expand Up @@ -71,13 +71,12 @@ func CreateAllocationForOwner(
allocationRequest["file_options_changed"], allocationRequest["file_options"] = calculateAllocationFileOptions(63 /*0011 1111*/, fileOptionsParams)
allocationRequest["is_enterprise"] = IsEnterprise
allocationRequest["storage_version"] = StorageV2
allocationRequest["auth_round_expiry"] = authRoundExpiry

var sn = transaction.SmartContractTxnData{
Name: transaction.NEW_ALLOCATION_REQUEST,
InputArgs: allocationRequest,
}
hash, _, nonce, txn, err = storageSmartContractTxnValue(sn, lock)
hash, _, nonce, txn, err = StorageSmartContractTxnValue(sn, lock)
return
}

Expand Down Expand Up @@ -109,7 +108,7 @@ func CreateFreeAllocation(marker string, value uint64) (string, int64, error) {
Name: transaction.NEW_FREE_ALLOCATION,
InputArgs: input,
}
hash, _, n, _, err := storageSmartContractTxnValue(sn, value)
hash, _, n, _, err := StorageSmartContractTxnValue(sn, value)
return hash, n, err
}

Expand All @@ -127,12 +126,13 @@ func CreateFreeAllocation(marker string, value uint64) (string, int64, error) {
//
// returns the hash of the transaction, the nonce of the transaction and an error if any.
func UpdateAllocation(
size, authRoundExpiry int64,
size int64,
extend bool,
allocationID string,
lock uint64,
addBlobberId, addBlobberAuthTicket, removeBlobberId, ownerID, ownerSigninPublicKey string,
setThirdPartyExtendable bool, fileOptionsParams *FileOptionsParameters, ticket string,
clients ...string,
) (hash string, nonce int64, err error) {
if ownerID == "" {
ownerID = client.Id()
Expand Down Expand Up @@ -163,7 +163,6 @@ func UpdateAllocation(
updateAllocationRequest["set_third_party_extendable"] = setThirdPartyExtendable
updateAllocationRequest["owner_signing_public_key"] = ownerSigninPublicKey
updateAllocationRequest["file_options_changed"], updateAllocationRequest["file_options"] = calculateAllocationFileOptions(alloc.FileOptions, fileOptionsParams)
updateAllocationRequest["auth_round_expiry"] = authRoundExpiry

if ticket != "" {

Expand All @@ -187,7 +186,7 @@ func UpdateAllocation(
Name: transaction.STORAGESC_UPDATE_ALLOCATION,
InputArgs: updateAllocationRequest,
}
hash, _, nonce, _, err = storageSmartContractTxnValue(sn, lock)
hash, _, nonce, _, err = StorageSmartContractTxnValue(sn, lock, clients...)
return
}

Expand All @@ -210,7 +209,7 @@ func GetUpdateAllocTicket(allocationID, userID, operationType string, roundExpir
// - providerID: provider ID
// - value: value to lock
// - fee: transaction fee
func StakePoolLock(providerType ProviderType, providerID string, value, fee uint64) (hash string, nonce int64, err error) {
func StakePoolLock(providerType ProviderType, providerID string, value, fee uint64, clients ...string) (hash string, nonce int64, err error) {
if !client.IsSDKInitialized() {
return "", 0, sdkNotInitialized
}
Expand Down Expand Up @@ -247,7 +246,7 @@ func StakePoolLock(providerType ProviderType, providerID string, value, fee uint
return "", 0, errors.Newf("stake_pool_lock", "unsupported provider type: %v", providerType)
}

hash, _, nonce, _, err = transaction.SmartContractTxnValueFeeWithRetry(scAddress, sn, value, fee, true)
hash, _, nonce, _, err = transaction.SmartContractTxnValueFeeWithRetry(scAddress, sn, value, fee, true, clients...)
return
}

Expand Down
Loading
Loading