diff --git a/core/conf/config_test.go b/core/conf/config_test.go index 8762195bd..b07f99410 100644 --- a/core/conf/config_test.go +++ b/core/conf/config_test.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 995a45954..2cbbdb9f0 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -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" diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index f319cf968..8e1aeb900 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -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 } diff --git a/play.go b/play.go index c88634db9..87703aba1 100644 --- a/play.go +++ b/play.go @@ -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) diff --git a/wasmsdk/allocation.go b/wasmsdk/allocation.go index 25aae7861..2285670d6 100644 --- a/wasmsdk/allocation.go +++ b/wasmsdk/allocation.go @@ -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, @@ -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, @@ -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) diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 1162f2342..89b35f456 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -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 @@ -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 } diff --git a/zboxcore/sdk/blobber_operations.go b/zboxcore/sdk/blobber_operations.go index fa15777d9..d6f93f22a 100644 --- a/zboxcore/sdk/blobber_operations.go +++ b/zboxcore/sdk/blobber_operations.go @@ -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 { @@ -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 } @@ -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 } @@ -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() @@ -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 != "" { @@ -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 } @@ -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 } @@ -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 } diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 40fdb954b..3d7651c10 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -804,11 +804,11 @@ type CreateAllocationOptions struct { // - options is the options struct instance for creating the allocation. // // returns the hash of the new_allocation_request transaction, the nonce of the transaction, the transaction object and an error if any. -func CreateAllocationWith(options CreateAllocationOptions) ( +func CreateAllocationWith(options CreateAllocationOptions, clients ...string) ( string, int64, *transaction.Transaction, error) { - return CreateAllocationForOwner(client.Id(), - client.PublicKey(), options.DataShards, options.ParityShards, + return CreateAllocationForOwner(client.Id(clients...), + client.PublicKey(clients...), options.DataShards, options.ParityShards, options.Size, options.ReadPrice, options.WritePrice, options.Lock, options.BlobberIds, options.BlobberAuthTickets, options.ThirdPartyExtendable, options.IsEnterprise, options.Force, options.FileOptionsParams, options.AuthRoundExpiry) } @@ -983,7 +983,7 @@ func GetFreeAllocationBlobbers(request map[string]interface{}) ([]string, error) // - totalLimit is the total limit of the assigner for all free allocation requests. // // returns the hash of the transaction, the nonce of the transaction and an error if any. -func AddFreeStorageAssigner(name, publicKey string, individualLimit, totalLimit float64) (string, int64, error) { +func AddFreeStorageAssigner(name, publicKey string, individualLimit, totalLimit float64, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -999,7 +999,7 @@ func AddFreeStorageAssigner(name, publicKey string, individualLimit, totalLimit Name: transaction.ADD_FREE_ALLOCATION_ASSIGNER, InputArgs: input, } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } @@ -1009,7 +1009,7 @@ func AddFreeStorageAssigner(name, publicKey string, individualLimit, totalLimit // - allocID is the id of the allocation. // // returns the hash of the transaction, the nonce of the transaction and an error if any. -func FinalizeAllocation(allocID string) (hash string, nonce int64, err error) { +func FinalizeAllocation(allocID string, clients ...string) (hash string, nonce int64, err error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1017,7 +1017,7 @@ func FinalizeAllocation(allocID string) (hash string, nonce int64, err error) { Name: transaction.STORAGESC_FINALIZE_ALLOCATION, InputArgs: map[string]interface{}{"allocation_id": allocID}, } - hash, _, nonce, _, err = storageSmartContractTxn(sn) + hash, _, nonce, _, err = StorageSmartContractTxn(sn, clients...) return } @@ -1026,7 +1026,7 @@ func FinalizeAllocation(allocID string) (hash string, nonce int64, err error) { // - allocID is the id of the allocation. // // returns the hash of the transaction, the nonce of the transaction and an error if any. -func CancelAllocation(allocID string) (hash string, nonce int64, err error) { +func CancelAllocation(allocID string, clients ...string) (hash string, nonce int64, err error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1034,7 +1034,7 @@ func CancelAllocation(allocID string) (hash string, nonce int64, err error) { Name: transaction.STORAGESC_CANCEL_ALLOCATION, InputArgs: map[string]interface{}{"allocation_id": allocID}, } - hash, _, nonce, _, err = storageSmartContractTxn(sn) + hash, _, nonce, _, err = StorageSmartContractTxn(sn, clients...) return } @@ -1052,7 +1052,7 @@ const ( // KillProvider kills a blobber or a validator (txn: `storagesc.kill_blobber` or `storagesc.kill_validator`) // - providerId is the id of the provider. // - providerType` is the type of the provider, either 3 for `ProviderBlobber` or 4 for `ProviderValidator. -func KillProvider(providerId string, providerType ProviderType) (string, int64, error) { +func KillProvider(providerId string, providerType ProviderType, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1071,14 +1071,14 @@ func KillProvider(providerId string, providerType ProviderType) (string, int64, default: return "", 0, fmt.Errorf("kill provider type %v not implimented", providerType) } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } // ShutdownProvider shuts down a blobber or a validator (txn: `storagesc.shutdown_blobber` or `storagesc.shutdown_validator`) // - providerId is the id of the provider. // - providerType` is the type of the provider, either 3 for `ProviderBlobber` or 4 for `ProviderValidator. -func ShutdownProvider(providerType ProviderType, providerID string) (string, int64, error) { +func ShutdownProvider(providerType ProviderType, providerID string, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1098,14 +1098,14 @@ func ShutdownProvider(providerType ProviderType, providerID string) (string, int default: return "", 0, fmt.Errorf("shutdown provider type %v not implimented", providerType) } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } // CollectRewards collects the rewards for a provider (txn: `storagesc.collect_reward`) // - providerId is the id of the provider. // - providerType is the type of the provider. -func CollectRewards(providerId string, providerType ProviderType) (string, int64, error) { +func CollectRewards(providerId string, providerType ProviderType, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1145,7 +1145,7 @@ func CollectRewards(providerId string, providerType ProviderType) (string, int64 // - newOwnerPublicKey is the public key of the new owner. // // returns the hash of the transaction, the nonce of the transaction and an error if any. -func TransferAllocation(allocationId, newOwner, newOwnerPublicKey string) (string, int64, error) { +func TransferAllocation(allocationId, newOwner, newOwnerPublicKey string, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1172,13 +1172,13 @@ func TransferAllocation(allocationId, newOwner, newOwnerPublicKey string) (strin Name: transaction.STORAGESC_UPDATE_ALLOCATION, InputArgs: allocationRequest, } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } // UpdateBlobberSettings updates the settings of a blobber (txn: `storagesc.update_blobber_settings`) // - blob is the update blobber request inputs. -func UpdateBlobberSettings(blob *UpdateBlobber) (resp string, nonce int64, err error) { +func UpdateBlobberSettings(blob *UpdateBlobber, clients ...string) (resp string, nonce int64, err error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1186,13 +1186,13 @@ func UpdateBlobberSettings(blob *UpdateBlobber) (resp string, nonce int64, err e Name: transaction.STORAGESC_UPDATE_BLOBBER_SETTINGS, InputArgs: blob, } - resp, _, nonce, _, err = storageSmartContractTxn(sn) + resp, _, nonce, _, err = StorageSmartContractTxn(sn, clients...) return } // UpdateValidatorSettings updates the settings of a validator (txn: `storagesc.update_validator_settings`) // - v is the update validator request inputs. -func UpdateValidatorSettings(v *UpdateValidator) (resp string, nonce int64, err error) { +func UpdateValidatorSettings(v *UpdateValidator, clients ...string) (resp string, nonce int64, err error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1201,13 +1201,13 @@ func UpdateValidatorSettings(v *UpdateValidator) (resp string, nonce int64, err Name: transaction.STORAGESC_UPDATE_VALIDATOR_SETTINGS, InputArgs: v.ConvertToValidationNode(), } - resp, _, nonce, _, err = storageSmartContractTxn(sn) + resp, _, nonce, _, err = StorageSmartContractTxn(sn, clients...) return } // ResetBlobberStats resets the stats of a blobber (txn: `storagesc.reset_blobber_stats`) // - rbs is the reset blobber stats dto, contains the blobber id and its stats. -func ResetBlobberStats(rbs *ResetBlobberStatsDto) (string, int64, error) { +func ResetBlobberStats(rbs *ResetBlobberStatsDto, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1216,7 +1216,7 @@ func ResetBlobberStats(rbs *ResetBlobberStatsDto) (string, int64, error) { Name: transaction.STORAGESC_RESET_BLOBBER_STATS, InputArgs: rbs, } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } @@ -1224,7 +1224,7 @@ type StorageNodeIdField struct { Id string `json:"id"` } -func ResetBlobberVersion(snId *StorageNodeIdField) (string, int64, error) { +func ResetBlobberVersion(snId *StorageNodeIdField, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1233,11 +1233,11 @@ func ResetBlobberVersion(snId *StorageNodeIdField) (string, int64, error) { Name: transaction.STORAGESC_RESET_BLOBBER_VERSION, InputArgs: snId, } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } -func InsertKilledProviderID(snId *StorageNodeIdField) (string, int64, error) { +func InsertKilledProviderID(snId *StorageNodeIdField, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1246,11 +1246,11 @@ func InsertKilledProviderID(snId *StorageNodeIdField) (string, int64, error) { Name: transaction.STORAGESC_INSERT_KILLED_PROVIDER_ID, InputArgs: snId, } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } -func ResetAllocationStats(allocationId string) (string, int64, error) { +func ResetAllocationStats(allocationId string, clients ...string) (string, int64, error) { if !client.IsSDKInitialized() { return "", 0, sdkNotInitialized } @@ -1259,27 +1259,21 @@ func ResetAllocationStats(allocationId string) (string, int64, error) { Name: transaction.STORAGESC_RESET_ALLOCATION_STATS, InputArgs: allocationId, } - hash, _, n, _, err := storageSmartContractTxn(sn) + hash, _, n, _, err := StorageSmartContractTxn(sn, clients...) return hash, n, err } -func StorageSmartContractTxn(sn transaction.SmartContractTxnData) ( +func StorageSmartContractTxn(sn transaction.SmartContractTxnData, clients ...string) ( hash, out string, nonce int64, txn *transaction.Transaction, err error) { - return storageSmartContractTxnValue(sn, 0) + return StorageSmartContractTxnValue(sn, 0, clients...) } -func storageSmartContractTxn(sn transaction.SmartContractTxnData) ( - hash, out string, nonce int64, txn *transaction.Transaction, err error) { - - return storageSmartContractTxnValue(sn, 0) -} - -func storageSmartContractTxnValue(sn transaction.SmartContractTxnData, value uint64) ( +func StorageSmartContractTxnValue(sn transaction.SmartContractTxnData, value uint64, clients ...string) ( hash, out string, nonce int64, txn *transaction.Transaction, err error) { // Fee is set during sdk initialization. - return transaction.SmartContractTxnValueFeeWithRetry(STORAGE_SCADDRESS, sn, value, client.TxnFee(), true) + return transaction.SmartContractTxnValueFeeWithRetry(STORAGE_SCADDRESS, sn, value, client.TxnFee(), true, clients...) } func CommitToFabric(metaTxnData, fabricConfigJSON string) (string, error) { diff --git a/zcncore/execute_transactions.go b/zcncore/execute_transactions.go index 5a75ddde8..eb12b3f9d 100644 --- a/zcncore/execute_transactions.go +++ b/zcncore/execute_transactions.go @@ -114,6 +114,13 @@ func MinerScUpdateGlobals(input interface{}, client ...string) (hash, out string } +func StorageSCAddBlobber(input interface{}, client ...string) (hash, out string, nonce int64, txn *transaction.Transaction, err error) { + return transaction.SmartContractTxn(StorageSmartContractAddress, transaction.SmartContractTxnData{ + Name: transaction.STORAGESC_ADD_BLOBBER, + InputArgs: input, + }, true, client...) +} + func StorageScUpdateConfig(input interface{}, client ...string) (hash, out string, nonce int64, txn *transaction.Transaction, err error) { return transaction.SmartContractTxn(StorageSmartContractAddress, transaction.SmartContractTxnData{ Name: transaction.STORAGESC_UPDATE_SETTINGS, @@ -214,6 +221,18 @@ func Send(toClientID string, tokens uint64, desc string, client ...string) (hash InputArgs: SendTxnData{Note: desc}, }, tokens, true, client...) } +func SendWithCustomFee(toClientID string, tokens, fee uint64, desc string, client ...string) (hash, out string, nonce int64, txn *transaction.Transaction, err error) { + if len(client) == 0 { + client = append(client, "") + client = append(client, toClientID) + } else { + client = append(client, toClientID) + } + return transaction.SmartContractTxnValueFee(MinerSmartContractAddress, transaction.SmartContractTxnData{ + Name: "transfer", + InputArgs: SendTxnData{Note: desc}, + }, tokens, fee, true, client...) +} func Faucet(tokens uint64, input string, client ...string) (hash, out string, nonce int64, txn *transaction.Transaction, err error) { return transaction.SmartContractTxnValue(FaucetSmartContractAddress, transaction.SmartContractTxnData{ diff --git a/zcncore/get_data.go b/zcncore/get_data.go index d5a7eeaba..d332804d9 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -172,7 +172,7 @@ func getTokenUSDRate() (float64, error) { } // getWallet get a wallet object from a wallet string -func getWallet(walletStr string) (*zcncrypto.Wallet, error) { +func GetWalletZcncore(walletStr string) (*zcncrypto.Wallet, error) { var w zcncrypto.Wallet err := json.Unmarshal([]byte(walletStr), &w) if err != nil { @@ -196,10 +196,6 @@ func (p Params) Query() string { return "?" + params.Encode() } -func withParams(uri string, params Params) string { //nolint:unused - return uri + params.Query() -} - // GetBlobberSnapshots obtains list of allocations of a blobber. // Blobber snapshots are historical records of the blobber instance to track its change over time and serve graph requests, // which are requests that need multiple data points, distributed over an interval of time, usually to plot them on a @@ -295,6 +291,23 @@ func GetLatestFinalizedMagicBlock() (m *block.MagicBlock, err error) { return resp.MagicBlock, nil } +// GetLatestFinalizedBlock gets latest finalized block +func GetLatestFinalizedBlock() (*block.Block, error) { + res, err := client.MakeSCRestAPICall("", GET_LATEST_FINALIZED, nil, "") + if err != nil { + return nil, err + } + + var resp block.Block + + err = json.Unmarshal(res, &resp) + if err != nil { + return nil, err + } + + return &resp, nil +} + // GetMinerSCUserInfo retrieve user stake pools for the providers related to the Miner SC (miners/sharders). // - clientID: user's wallet id func GetMinerSCUserInfo(clientID string) ([]byte, error) { diff --git a/zcncore/wallet.go b/zcncore/wallet.go index f564819e1..4c06fb2ee 100644 --- a/zcncore/wallet.go +++ b/zcncore/wallet.go @@ -10,7 +10,7 @@ import ( // GetWallet get a wallet object from a wallet string func GetWallet(walletStr string) (*zcncrypto.Wallet, error) { - return getWallet(walletStr) + return GetWalletZcncore(walletStr) } // Deprecated: use Sign() method in zcncrypto.Wallet