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

feat: use indexer directly [JS-842] #1069

Merged
merged 41 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
771f61e
feat: refactor configs [JS-831]
shamsartem Oct 30, 2024
38455bc
fix circular dependency
shamsartem Oct 30, 2024
7a61077
Apply automatic changes
shamsartem Oct 30, 2024
2fdc977
fix
shamsartem Oct 30, 2024
7991aeb
Apply automatic changes
shamsartem Oct 30, 2024
3dc1d8d
simplify
shamsartem Oct 30, 2024
0ebac89
import only what's needed from lodash
shamsartem Oct 30, 2024
75601cf
fix?
shamsartem Oct 30, 2024
5504ab5
just in case
shamsartem Oct 30, 2024
e804ef1
Merge branch 'main' into refactor
shamsartem Oct 30, 2024
7d9c540
Merge branch 'main' into refactor
shamsartem Oct 31, 2024
da98076
make all aliases hidden from top-level of help
shamsartem Oct 31, 2024
2d4acd2
Apply automatic changes
shamsartem Oct 31, 2024
41bcde0
stop managing ocker compose config completely
shamsartem Nov 1, 2024
d49a1f9
feat: use indexer directly
shamsartem Nov 5, 2024
616479f
fix
shamsartem Nov 5, 2024
eb52c51
don't require build for linting
shamsartem Nov 5, 2024
735d792
remove irrelevant dependencies
shamsartem Nov 5, 2024
be52e49
add docker for on-each-commit
shamsartem Nov 5, 2024
8856f00
add env
shamsartem Nov 5, 2024
fba4662
change runs-on
shamsartem Nov 5, 2024
5fdd23e
add permissions?
shamsartem Nov 5, 2024
22f6ada
fix and remove stuff from docs.yml
shamsartem Nov 5, 2024
c1530c8
fix
shamsartem Nov 5, 2024
ebfeec1
add generated to prettierignore
shamsartem Nov 6, 2024
a19187e
add config promise to the Map right away to prevent possible problems…
shamsartem Nov 6, 2024
53a68b0
fix
shamsartem Nov 6, 2024
278dcad
remove rest of the clients
shamsartem Nov 12, 2024
e3401d9
Merge branch 'main' into indexer
shamsartem Nov 12, 2024
65afa0f
get cc statuses from RPC
shamsartem Nov 12, 2024
9b0c2f7
lowercase dealId
shamsartem Nov 12, 2024
43dc831
add debug log
shamsartem Nov 12, 2024
6f70f4d
try using batch read like before instead of multicall read
shamsartem Nov 12, 2024
a7ee43f
try adding timeout
shamsartem Nov 12, 2024
7f53cee
use on-chain info for cc, refactor and fix
shamsartem Nov 13, 2024
cafff89
Apply automatic changes
shamsartem Nov 13, 2024
a194ec7
take ccId from subgraph if cc from RPC is zeroHash (was removed)
shamsartem Nov 13, 2024
9be7d30
don't convert already converted peerId
shamsartem Nov 13, 2024
b7c2a47
Merge branch 'main' into indexer
shamsartem Nov 18, 2024
20cb1b5
rename left-ower Fluence Labs
shamsartem Nov 18, 2024
c354632
improve startDate and expirationDate display
shamsartem Nov 27, 2024
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
2 changes: 1 addition & 1 deletion .github/actions/replace-version/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "ncc build index.js"
},
"author": "Fluence Labs",
"author": "Cloudless Labs",
"license": "AGPL-3.0",
"dependencies": {
"@actions/core": "^1.10.0"
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/package/.prettierignore → .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ docs
node_modules
tmp
.fluence
src/lib/compiled-aqua
compiled-aqua
gqlSchema.json
gqlGenerated.ts
CHANGELOG.md
.github/workflows
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ you read and follow some basic [rules](./CONTRIBUTING.md).

## License

All software code is copyright (c) Fluence Labs, Inc. under the
All software code is copyright (c) Fluence DAO. under the
[GNU Affero General Public License version 3](./LICENSE) license.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"build": "turbo run build --cache-dir=.turbo",
"install-yarn-dependencies": "turbo run install-yarn-dependencies --cache-dir=.turbo",
"install-npm-dependencies": "turbo run install-npm-dependencies --cache-dir=.turbo",
"gen-gql-schema": "turbo run gen-gql-schema --cache-dir=.turbo",
"gql-codegen": "turbo run gql-codegen --cache-dir=.turbo",
"pack-ci": "turbo run pack-ci --cache-dir=.turbo && node ./rename-packed.js",
"pack-linux-x64": "turbo run pack-linux-x64 --cache-dir=.turbo && node ./rename-packed.js",
"pack-darwin-x64": "turbo run pack-darwin-x64 --cache-dir=.turbo && node ./rename-packed.js",
Expand Down
2 changes: 0 additions & 2 deletions packages/cli-connector/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// In Firefox: client variable can be undefined - that's why we need to use optional chaining

import { ConnectButton } from "@rainbow-me/rainbowkit";
import {
type CLIToConnectorFullMsg,
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"scripts": {
"install-yarn-dependencies": "yarn ./package install",
"install-npm-dependencies": "npm --prefix ./package/src/cli-aqua-dependencies install",
"gen-gql-schema": "yarn ./package gen-gql-schema",
"gql-codegen": "yarn ./package gql-codegen",
"before-build": "yarn ./package before-build",
"build": "yarn ./package build",
"pack-ci": "yarn ./package pack-ci",
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/package/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tmp
/.f
.env
rust-toolchain.toml
docker-compose.yaml

# recommended by Fluence
.idea
Expand All @@ -27,6 +28,8 @@ rust-toolchain.toml
# ignore compiled files
src/lib/compiled-aqua
src/lib/compiled-aqua-with-tracing
src/lib/gql/gqlGenerated.ts
src/lib/gql/gqlSchema.json
src/versions
src/aqua-dependencies
src/common.ts
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package/docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1359,10 +1359,9 @@ Exit from deal. Alias: fluence provider de
```
USAGE
$ fluence provider deal-exit [--no-input] [--env <testnet | mainnet | stage | local>] [--priv-key <private-key>]
[--deal-ids <id-1,id-2>] [--all]
[--deal-ids <id-1,id-2>]

FLAGS
--all To use all deal ids that indexer is aware of for your provider address
--deal-ids=<id-1,id-2> Comma-separated deal ids
--env=<testnet | mainnet | stage | local> Fluence Environment to use when running the command
--no-input Don't interactively ask for any input from the user
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default tseslint.config(
"Please use type-safe to string converter (e.g. numToString)",
},
{
selector: "Identifier[name='String']",
selector: "CallExpression[callee.name='String']",
message:
// cause when the variable changes type you will have no way to learn you possibly have to change it's string representation
"Please use type-safe to string converter (e.g. numToString)",
Expand Down Expand Up @@ -186,6 +186,7 @@ export default tseslint.config(
"bin/dev.js",
"resources/*",
".yarn/*",
"src/lib/gql/gqlGenerated.ts",
],
},
);
2 changes: 1 addition & 1 deletion packages/cli/package/nsis/custom-installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Section "@fluencelabs/cli CLI ${VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\fluence" \
"UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\fluence" \
"Publisher" "Fluence Labs"
"Publisher" "Cloudless Labs"

WriteRegExpandStr ${env_hkcu} "FLUENCE_OCLIF_CLIENT_HOME" "$INSTDIR\client"
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
Expand Down
17 changes: 13 additions & 4 deletions packages/cli/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bugs": "https://github.com/fluencelabs/cli/issues",
"repository": "fluencelabs/cli",
"license": "AGPL-3.0",
"author": "Fluence Labs",
"author": "Cloudless Labs",
"type": "module",
"exports": "./lib/index.js",
"types": "dist/index.d.ts",
Expand All @@ -29,6 +29,8 @@
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"find-dead-code": "ts-prune",
"gen-gql-schema": "tsx ./src/genGqlSchema.ts",
"gql-codegen": "graphql-codegen --config ./src/lib/gql/gqlCodegen.ts",
"postpack": "shx rm -f oclif.manifest.json",
"vitest-provider": "vitest run provider.test.ts",
"vitest-deal-deploy": "vitest run dealDeploy.test.ts",
Expand All @@ -45,9 +47,9 @@
"upload-darwin-x64": "oclif upload tarballs -t \"darwin-x64\" --no-xz",
"upload-darwin-arm64": "oclif upload tarballs -t \"darwin-arm64\" --no-xz",
"upload-win32-x64": "oclif upload tarballs -t \"win32-x64\" --no-xz && oclif upload win --targets \"win32-x64\"",
"download-marine-and-mrepl": "node --import tsx --no-warnings ./test/setup/downloadMarineAndMrepl.ts",
"generate-templates": "node --import tsx --no-warnings ./test/setup/generateTemplates.ts",
"local-up": "node --import tsx --no-warnings ./test/setup/localUp.ts",
"download-marine-and-mrepl": "tsx ./test/setup/downloadMarineAndMrepl.ts",
"generate-templates": "tsx ./test/setup/generateTemplates.ts",
"local-up": "tsx ./test/setup/localUp.ts",
"test": "yarn download-marine-and-mrepl && yarn generate-templates && yarn local-up && yarn vitest",
"circular": "madge --circular ./dist --exclude cli-connector",
"on-each-commit": "yarn lint-fix && yarn circular && cd docs/commands && oclif readme --no-aliases && yarn gen-config-docs",
Expand Down Expand Up @@ -85,6 +87,9 @@
"ethers": "6.7.1",
"express": "4.21.1",
"filenamify": "6.0.0",
"graphql": "^16.9.0",
"graphql-request": "^7.1.2",
"graphql-tag": "^2.12.6",
"inquirer": "9.2.20",
"ipfs-http-client": "60.0.1",
"lodash-es": "4.17.21",
Expand All @@ -104,6 +109,10 @@
"devDependencies": {
"@actions/core": "1.11.1",
"@aws-sdk/lib-storage": "^3.501.0",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/typescript": "^4.1.1",
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "^4.3.1",
"@tsconfig/node22": "^22.0.0",
"@tsconfig/strictest": "^2.0.5",
"@types/debug": "4.1.12",
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/package/src/commands/deal/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ import {
formatAquaLogsHeader,
formatAquaLogs,
} from "../../lib/helpers/formatAquaLogs.js";
import {
LOGS_RESOLVE_SUBNET_ERROR_START,
stringifyUnknown,
} from "../../lib/helpers/utils.js";
import { stringifyUnknown } from "../../lib/helpers/stringifyUnknown.js";
import { LOGS_RESOLVE_SUBNET_ERROR_START } from "../../lib/helpers/utils.js";
import {
disconnectFluenceClient,
initFluenceClient,
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/package/src/commands/deal/workers-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ export default class WorkersRemove extends BaseCommand<typeof WorkersRemove> {
args["WORKER-IDS"] ??
(await input({
message: "Enter comma-separated worker ids",
validate: (v: string) => {
return commaSepStrToArr(v).length > 0;
validate(v: string) {
return (
commaSepStrToArr(v).length > 0 ||
"Please provide at least one worker id"
);
},
})),
);

if (workerIds.length === 0) {
commandObj.error("No worker ids provided");
}

for (const workerId of workerIds) {
await sign({
title: `Remove worker ${workerId} from deal`,
Expand Down
22 changes: 15 additions & 7 deletions packages/cli/package/src/commands/provider/cc-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/

import { BaseCommand } from "../../baseCommand.js";
import { jsonStringify } from "../../common.js";
import {
printCommitmentsInfo,
printCommitmentsInfoJSON,
getDetailedCommitmentsInfoGroupedByStatus,
stringifyDetailedCommitmentsInfo,
} from "../../lib/chain/commitment.js";
import { commandObj } from "../../lib/commandObj.js";
import { CHAIN_FLAGS, CC_FLAGS, JSON_FLAG } from "../../lib/const.js";
import { aliasesText } from "../../lib/helpers/aliasesText.js";
import { initCli } from "../../lib/lifeCycle.js";
Expand All @@ -36,10 +38,16 @@ export default class CCInfo extends BaseCommand<typeof CCInfo> {
async run(): Promise<void> {
const { flags } = await initCli(this, await this.parse(CCInfo));

if (flags.json) {
await printCommitmentsInfoJSON(flags);
} else {
await printCommitmentsInfo(flags);
}
const ccInfo = await getDetailedCommitmentsInfoGroupedByStatus(flags);

commandObj.log(
flags.json
? jsonStringify(
ccInfo.flatMap(({ CCs }) => {
return CCs;
}),
)
: stringifyDetailedCommitmentsInfo(ccInfo),
);
}
}
107 changes: 78 additions & 29 deletions packages/cli/package/src/commands/provider/deal-exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Flags } from "@oclif/core";
import type { Contracts } from "@fluencelabs/deal-ts-clients";

import { BaseCommand } from "../../baseCommand.js";
import { getProviderDeals } from "../../lib/chain/deals.js";
import { commandObj } from "../../lib/commandObj.js";
import {
CHAIN_FLAGS,
DEAL_IDS_FLAG,
Expand All @@ -27,8 +27,10 @@ import {
import {
getContracts,
getSignerAddress,
multicallRead,
populateTx,
signBatch,
type MulticallReadItem,
} from "../../lib/dealClient.js";
import { aliasesText } from "../../lib/helpers/aliasesText.js";
import { commaSepStrToArr } from "../../lib/helpers/utils.js";
Expand All @@ -41,51 +43,98 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
static override flags = {
...CHAIN_FLAGS,
...DEAL_IDS_FLAG,
all: Flags.boolean({
default: false,
description:
"To use all deal ids that indexer is aware of for your provider address",
}),
// TODO: When we have a way to get all deal ids for a provider address
// all: Flags.boolean({
// default: false,
// description:
// "To use all deal ids that indexer is aware of for your provider address",
// }),
};

async run(): Promise<void> {
const { flags } = await initCli(this, await this.parse(DealExit));
const { contracts } = await getContracts();
const signerAddress = await getSignerAddress();

const dealIds = flags.all
? await getProviderDeals()
: commaSepStrToArr(
flags[DEAL_IDS_FLAG_NAME] ??
(await input({
message: "Enter comma-separated deal ids",
})),
const dealIds =
// flags.all
// ? await getProviderDeals()
// :
commaSepStrToArr(
flags[DEAL_IDS_FLAG_NAME] ??
(await input({
message: "Enter comma-separated deal ids",
validate(input: string) {
return (
commaSepStrToArr(input).length > 0 ||
"Please enter at least one deal id"
);
},
})),
);

if (dealIds.length === 0) {
return commandObj.error("No deal ids provided");
}

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const workersFromRPC = (await multicallRead(
dealIds.map((id): MulticallReadItem => {
const deal = contracts.getDeal(id);
return {
target: id,
callData: deal.interface.encodeFunctionData("getWorkers"),
decode(returnData) {
return deal.interface.decodeFunctionResult(
"getWorkers",
returnData,
);
},
};
}),
)) as Awaited<ReturnType<ReturnType<Contracts["getDeal"]>["getWorkers"]>>[];

const workers = dealIds.flatMap((id, i) => {
const deal = contracts.getDeal(id);
const workers = workersFromRPC[i];

if (workers === undefined) {
commandObj.warn(
`Was not able to get workers for deal ${id} from chain. Skipping...`,
);

const workers = (
await Promise.all(
dealIds.map(async (id) => {
const deal = contracts.getDeal(id);
return (await deal.getWorkers()).map((worker) => {
return { deal, worker };
});
}),
)
).flat();
return [];
}

return workers
.filter((worker) => {
return worker.provider.toLowerCase() === signerAddress;
})
.map((worker) => {
return { worker, deal };
});
});

const [firstWorker, ...restWorkers] = workers;

if (firstWorker === undefined) {
return commandObj.error(
`No workers found for address ${signerAddress} and deal ids: ${dealIds.join(", ")}`,
);
}

await signBatch(
`Remove the following workers from deals:\n\n${workers
.map(({ worker: { onchainId } }) => {
return onchainId;
})
.join("\n")}`,
workers
.filter(({ worker }) => {
return worker.provider.toLowerCase() === signerAddress;
})
.map(({ deal, worker: { onchainId } }) => {
[
populateTx(firstWorker.deal.removeWorker, firstWorker.worker.onchainId),
...restWorkers.map(({ deal, worker: { onchainId } }) => {
return populateTx(deal.removeWorker, onchainId);
}),
],
);
}
}
Loading
Loading