From 6e7539957cce5e3d726578ebb6df7a8e13857ad1 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Thu, 28 Mar 2024 00:31:02 -0400 Subject: [PATCH] added BatchManifestAllaccounts --- blockchain/bl_manifest.go | 29 +++---- blockchain/interface.go | 166 +++++++++++++++++++++----------------- blox/blox.go | 2 +- 3 files changed, 105 insertions(+), 92 deletions(-) diff --git a/blockchain/bl_manifest.go b/blockchain/bl_manifest.go index 9d578ac..09fc8d2 100644 --- a/blockchain/bl_manifest.go +++ b/blockchain/bl_manifest.go @@ -85,7 +85,7 @@ func (bl *FxBlockchain) ManifestStore(ctx context.Context, to peer.ID, r Manifes } } -func (bl *FxBlockchain) HandleManifestAvailableBatch(ctx context.Context, poolIDString string, account string, links []ipld.Link) ([]ipld.Link, error) { +func (bl *FxBlockchain) HandleManifestAvailableAllaccountsBatch(ctx context.Context, poolIDString string, links []ipld.Link) ([]ipld.Link, error) { var availableLinks []ipld.Link poolID, err := strconv.Atoi(poolIDString) if err != nil { @@ -100,18 +100,17 @@ func (bl *FxBlockchain) HandleManifestAvailableBatch(ctx context.Context, poolID cids = append(cids, link.String()) } - reqBody := ReplicateRequest{ - Cids: cids, - Account: account, - PoolID: poolID, + reqBody := AvailableAllaccountsBatchRequest{ + Cids: cids, + PoolID: poolID, } - log.Debugw("HandleManifestAvailableBatch", "reqBody", reqBody) + log.Debugw("HandleManifestAvailableAllaccountsBatch", "reqBody", reqBody) req, err := json.Marshal(reqBody) if err != nil { return nil, fmt.Errorf("failed to serialize request: %w", err) } - response, statusCode, err := bl.callBlockchain(ctx, "POST", actionManifestAvailableBatch, req) + response, statusCode, err := bl.callBlockchain(ctx, "POST", actionManifestAvailableAllaccountsBatch, req) if err != nil { return nil, fmt.Errorf("blockchain call failed: %w", err) } @@ -119,22 +118,20 @@ func (bl *FxBlockchain) HandleManifestAvailableBatch(ctx context.Context, poolID return nil, fmt.Errorf("unexpected status code: %d", statusCode) } - var resp ReplicateResponse + var resp BatchManifestAllaccountsResponse if err := json.Unmarshal(response, &resp); err != nil { return nil, fmt.Errorf("failed to parse response: %w", err) } - log.Debugw("HandleManifestAvailableBatch", "resp", resp) + log.Debugw("HandleManifestAvailableAllaccountsBatch", "resp", resp) // Filter for available manifests. for _, manifest := range resp.Manifests { - if manifest.ReplicationAvailable > 0 { - c, err := cid.Decode(manifest.Cid) - if err != nil { - // Log or handle the error based on your application's logging strategy. - continue // Skipping invalid CIDs. - } - availableLinks = append(availableLinks, cidlink.Link{Cid: c}) + c, err := cid.Decode(manifest.Cid) + if err != nil { + // Log or handle the error based on your application's logging strategy. + continue // Skipping invalid CIDs. } + availableLinks = append(availableLinks, cidlink.Link{Cid: c}) } return availableLinks, nil diff --git a/blockchain/interface.go b/blockchain/interface.go index ee443d7..1118f6e 100644 --- a/blockchain/interface.go +++ b/blockchain/interface.go @@ -10,31 +10,32 @@ import ( ) const ( - actionSeeded = "account-seeded" - actionAccountExists = "account-exists" - actionAccountCreate = "account-create" - actionAccountFund = "account-fund" - actionAccountBalance = "account-balance" - actionAssetsBalance = "asset-balance" - actionTransferToMumbai = "fula-mumbai-convert_tokens" - actionTransferToGoerli = "fula-goerli-convert_tokens" - actionPoolCreate = "fula-pool-create" - actionPoolJoin = "fula-pool-join" - actionPoolCancelJoin = "fula-pool-cancel_join" - actionPoolRequests = "fula-pool-poolrequests" - actionPoolList = "fula-pool" - actionPoolUserList = "fula-pool-users" - actionPoolVote = "fula-pool-vote" - actionPoolLeave = "fula-pool-leave" - actionManifestUpload = "fula-manifest-upload" - actionManifestStore = "fula-manifest-storage" - actionManifestBatchStore = "fula-manifest-batch_storage" - actionManifestBatchUpload = "fula-manifest-batch_upload" - actionManifestAvailable = "fula-manifest-available" - actionManifestRemove = "fula-manifest-remove" - actionManifestRemoveStorer = "fula-manifest-remove_storer" - actionManifestRemoveStored = "fula-manifest-remove_storing_manifest" - actionManifestAvailableBatch = "fula-manifest-available_batch" + actionSeeded = "account-seeded" + actionAccountExists = "account-exists" + actionAccountCreate = "account-create" + actionAccountFund = "account-fund" + actionAccountBalance = "account-balance" + actionAssetsBalance = "asset-balance" + actionTransferToMumbai = "fula-mumbai-convert_tokens" + actionTransferToGoerli = "fula-goerli-convert_tokens" + actionPoolCreate = "fula-pool-create" + actionPoolJoin = "fula-pool-join" + actionPoolCancelJoin = "fula-pool-cancel_join" + actionPoolRequests = "fula-pool-poolrequests" + actionPoolList = "fula-pool" + actionPoolUserList = "fula-pool-users" + actionPoolVote = "fula-pool-vote" + actionPoolLeave = "fula-pool-leave" + actionManifestUpload = "fula-manifest-upload" + actionManifestStore = "fula-manifest-storage" + actionManifestBatchStore = "fula-manifest-batch_storage" + actionManifestBatchUpload = "fula-manifest-batch_upload" + actionManifestAvailable = "fula-manifest-available" + actionManifestRemove = "fula-manifest-remove" + actionManifestRemoveStorer = "fula-manifest-remove_storer" + actionManifestRemoveStored = "fula-manifest-remove_storing_manifest" + actionManifestAvailableBatch = "fula-manifest-available_batch" + actionManifestAvailableAllaccountsBatch = "fula-manifest-available_allaccounts_batch" //Hardware actionBloxFreeSpace = "blox-free-space" @@ -60,6 +61,11 @@ type ReplicateRequest struct { PoolID int `json:"pool_id"` } +type AvailableAllaccountsBatchRequest struct { + Cids []string `json:"cids"` + PoolID int `json:"pool_id"` +} + type ReplicateResponse struct { Manifests []BatchManifest `json:"manifests"` } @@ -69,6 +75,14 @@ type BatchManifest struct { ReplicationAvailable int `json:"replication_available"` } +type BatchManifestAllaccountsResponse struct { + Manifests []BatchManifestAllaccounts `json:"manifests"` +} + +type BatchManifestAllaccounts struct { + Cid string `json:"cid"` +} + type LinkWithLimit struct { Link ipld.Link Limit int @@ -413,31 +427,32 @@ type Blockchain interface { } var requestTypes = map[string]reflect.Type{ - actionSeeded: reflect.TypeOf(SeededRequest{}), - actionAccountExists: reflect.TypeOf(AccountExistsRequest{}), - actionAccountCreate: reflect.TypeOf(AccountCreateRequest{}), - actionAccountFund: reflect.TypeOf(AccountFundRequest{}), - actionPoolCreate: reflect.TypeOf(PoolCreateRequest{}), - actionPoolJoin: reflect.TypeOf(PoolJoinRequest{}), - actionPoolRequests: reflect.TypeOf(PoolRequestsRequest{}), - actionPoolCancelJoin: reflect.TypeOf(PoolCancelJoinRequest{}), - actionPoolList: reflect.TypeOf(PoolListRequest{}), - actionPoolUserList: reflect.TypeOf(PoolUserListRequest{}), - actionPoolVote: reflect.TypeOf(PoolVoteRequest{}), - actionPoolLeave: reflect.TypeOf(PoolLeaveRequest{}), - actionManifestUpload: reflect.TypeOf(ManifestUploadRequest{}), - actionManifestStore: reflect.TypeOf(ManifestStoreRequest{}), - actionManifestBatchStore: reflect.TypeOf(ManifestBatchStoreRequest{}), - actionManifestBatchUpload: reflect.TypeOf(ManifestBatchUploadRequest{}), - actionManifestAvailable: reflect.TypeOf(ManifestAvailableRequest{}), - actionManifestAvailableBatch: reflect.TypeOf(ReplicateRequest{}), - actionManifestRemove: reflect.TypeOf(ManifestRemoveRequest{}), - actionManifestRemoveStorer: reflect.TypeOf(ManifestRemoveStorerRequest{}), - actionManifestRemoveStored: reflect.TypeOf(ManifestRemoveStoredRequest{}), - actionAssetsBalance: reflect.TypeOf(AssetsBalanceRequest{}), - actionTransferToGoerli: reflect.TypeOf(TransferToFulaRequest{}), - actionTransferToMumbai: reflect.TypeOf(TransferToFulaRequest{}), - actionReplicateInPool: reflect.TypeOf(ReplicateRequest{}), + actionSeeded: reflect.TypeOf(SeededRequest{}), + actionAccountExists: reflect.TypeOf(AccountExistsRequest{}), + actionAccountCreate: reflect.TypeOf(AccountCreateRequest{}), + actionAccountFund: reflect.TypeOf(AccountFundRequest{}), + actionPoolCreate: reflect.TypeOf(PoolCreateRequest{}), + actionPoolJoin: reflect.TypeOf(PoolJoinRequest{}), + actionPoolRequests: reflect.TypeOf(PoolRequestsRequest{}), + actionPoolCancelJoin: reflect.TypeOf(PoolCancelJoinRequest{}), + actionPoolList: reflect.TypeOf(PoolListRequest{}), + actionPoolUserList: reflect.TypeOf(PoolUserListRequest{}), + actionPoolVote: reflect.TypeOf(PoolVoteRequest{}), + actionPoolLeave: reflect.TypeOf(PoolLeaveRequest{}), + actionManifestUpload: reflect.TypeOf(ManifestUploadRequest{}), + actionManifestStore: reflect.TypeOf(ManifestStoreRequest{}), + actionManifestBatchStore: reflect.TypeOf(ManifestBatchStoreRequest{}), + actionManifestBatchUpload: reflect.TypeOf(ManifestBatchUploadRequest{}), + actionManifestAvailable: reflect.TypeOf(ManifestAvailableRequest{}), + actionManifestAvailableBatch: reflect.TypeOf(ReplicateRequest{}), + actionManifestAvailableAllaccountsBatch: reflect.TypeOf(AvailableAllaccountsBatchRequest{}), + actionManifestRemove: reflect.TypeOf(ManifestRemoveRequest{}), + actionManifestRemoveStorer: reflect.TypeOf(ManifestRemoveStorerRequest{}), + actionManifestRemoveStored: reflect.TypeOf(ManifestRemoveStoredRequest{}), + actionAssetsBalance: reflect.TypeOf(AssetsBalanceRequest{}), + actionTransferToGoerli: reflect.TypeOf(TransferToFulaRequest{}), + actionTransferToMumbai: reflect.TypeOf(TransferToFulaRequest{}), + actionReplicateInPool: reflect.TypeOf(ReplicateRequest{}), //Hardware actionBloxFreeSpace: reflect.TypeOf(wifi.BloxFreeSpaceRequest{}), @@ -455,31 +470,32 @@ var requestTypes = map[string]reflect.Type{ } var responseTypes = map[string]reflect.Type{ - actionSeeded: reflect.TypeOf(SeededResponse{}), - actionAccountExists: reflect.TypeOf(AccountExistsResponse{}), - actionAccountCreate: reflect.TypeOf(AccountCreateResponse{}), - actionAccountFund: reflect.TypeOf(AccountFundResponse{}), - actionPoolCreate: reflect.TypeOf(PoolCreateResponse{}), - actionPoolJoin: reflect.TypeOf(PoolJoinResponse{}), - actionPoolRequests: reflect.TypeOf(PoolRequestsResponse{}), - actionPoolCancelJoin: reflect.TypeOf(PoolCancelJoinResponse{}), - actionPoolList: reflect.TypeOf(PoolListResponse{}), - actionPoolUserList: reflect.TypeOf(PoolUserListResponse{}), - actionPoolVote: reflect.TypeOf(PoolVoteResponse{}), - actionPoolLeave: reflect.TypeOf(PoolLeaveResponse{}), - actionManifestUpload: reflect.TypeOf(ManifestUploadResponse{}), - actionManifestStore: reflect.TypeOf(ManifestStoreResponse{}), - actionManifestBatchStore: reflect.TypeOf(ManifestBatchStoreResponse{}), - actionManifestBatchUpload: reflect.TypeOf(ManifestBatchUploadResponse{}), - actionManifestAvailable: reflect.TypeOf(ManifestAvailableResponse{}), - actionManifestAvailableBatch: reflect.TypeOf(ReplicateResponse{}), - actionManifestRemove: reflect.TypeOf(ManifestRemoveResponse{}), - actionManifestRemoveStorer: reflect.TypeOf(ManifestRemoveStorerResponse{}), - actionManifestRemoveStored: reflect.TypeOf(ManifestRemoveStoredResponse{}), - actionAssetsBalance: reflect.TypeOf(AssetsBalanceResponse{}), - actionTransferToGoerli: reflect.TypeOf(TransferToFulaResponse{}), - actionTransferToMumbai: reflect.TypeOf(TransferToFulaResponse{}), - actionReplicateInPool: reflect.TypeOf(ReplicateResponse{}), + actionSeeded: reflect.TypeOf(SeededResponse{}), + actionAccountExists: reflect.TypeOf(AccountExistsResponse{}), + actionAccountCreate: reflect.TypeOf(AccountCreateResponse{}), + actionAccountFund: reflect.TypeOf(AccountFundResponse{}), + actionPoolCreate: reflect.TypeOf(PoolCreateResponse{}), + actionPoolJoin: reflect.TypeOf(PoolJoinResponse{}), + actionPoolRequests: reflect.TypeOf(PoolRequestsResponse{}), + actionPoolCancelJoin: reflect.TypeOf(PoolCancelJoinResponse{}), + actionPoolList: reflect.TypeOf(PoolListResponse{}), + actionPoolUserList: reflect.TypeOf(PoolUserListResponse{}), + actionPoolVote: reflect.TypeOf(PoolVoteResponse{}), + actionPoolLeave: reflect.TypeOf(PoolLeaveResponse{}), + actionManifestUpload: reflect.TypeOf(ManifestUploadResponse{}), + actionManifestStore: reflect.TypeOf(ManifestStoreResponse{}), + actionManifestBatchStore: reflect.TypeOf(ManifestBatchStoreResponse{}), + actionManifestBatchUpload: reflect.TypeOf(ManifestBatchUploadResponse{}), + actionManifestAvailable: reflect.TypeOf(ManifestAvailableResponse{}), + actionManifestAvailableBatch: reflect.TypeOf(ReplicateResponse{}), + actionManifestAvailableAllaccountsBatch: reflect.TypeOf(BatchManifestAllaccountsResponse{}), + actionManifestRemove: reflect.TypeOf(ManifestRemoveResponse{}), + actionManifestRemoveStorer: reflect.TypeOf(ManifestRemoveStorerResponse{}), + actionManifestRemoveStored: reflect.TypeOf(ManifestRemoveStoredResponse{}), + actionAssetsBalance: reflect.TypeOf(AssetsBalanceResponse{}), + actionTransferToGoerli: reflect.TypeOf(TransferToFulaResponse{}), + actionTransferToMumbai: reflect.TypeOf(TransferToFulaResponse{}), + actionReplicateInPool: reflect.TypeOf(ReplicateResponse{}), //Hardware actionBloxFreeSpace: reflect.TypeOf(wifi.BloxFreeSpaceResponse{}), diff --git a/blox/blox.go b/blox/blox.go index 19874eb..5149e01 100644 --- a/blox/blox.go +++ b/blox/blox.go @@ -728,7 +728,7 @@ func (p *Blox) Start(ctx context.Context) error { // Call HandleManifestBatchStore method if len(storedLinks) > 0 { // Check if the manifests are available to be stored or not - availableLinks, err := p.bl.HandleManifestAvailableBatch(shortCtx, p.topicName, nodeAccount, storedLinks) + availableLinks, err := p.bl.HandleManifestAvailableAllaccountsBatch(shortCtx, p.topicName, storedLinks) if err != nil { log.Errorw("Error checking available manifests", "err", err) continue // Or handle the error appropriately