Skip to content

Commit

Permalink
Migrate to iota-sdk (#789)
Browse files Browse the repository at this point in the history
* chore: Swap iota.js for iota-sdk. Address easily fixable import errors [WiP]

* chore(iota-sdk): Fix client.pluginFetch

* chore(iota-sdk): Fix parsing of Uint8Array in plugin fetch

* chore(iota-sdk): Fix all errors for 'api'
+ Moved some missing utils from iota.js into explorer under utils/stardust/utils.ts

* chore(iota-sdk): Fix all import errors on client [WiP]

* chore: Fix MilestonePayload parsing (api) + Switch client dep to bindings/wasm

* chore: Switch to npm @iota/sdk dependency + Fixes

* chore: Refactor from getType getter to readonly field everywhere

* chore: Use sdk-wasm on client

* chore: Replace all getter accesses to models with direct readonly field accesses

* feat: Use iota-sdk 1.1-rc.1 + Fix Block page

* feat: Fix Visualizer stream for iota-sdk

* feat: Fix searching with "tag"

* feat: Fix other query endpoints

* feat: Fix participation plugin fetch

* fix: Fix imports + Honour Network.isEnabled + Remove unused file

* fix: Reset block state on blockId change

* chore: Remove unneeded dependencies from client

* chore: Make loglevel verbose in api/Dockerfile to debug CI

* chore: Use debian instead of alpine in Dockerfile + Bump required node version to 16.20

* chore: Fix Dockerfile

* chore: Revert latest Dockerfile changes and add rust install step

* chore: Update Dockerfile

* chore: Make Dockerfile less bashy

* chore: Update Dockerfile rustup install

* chore: Retry Dockerfile with debian

* chore: Test if we even need cmake and build-base (api/Dockerfile)

* feat: Remove utils.js dependency for stardust (Converter and HexHelper copied locally for convenience)

* feat: Rename stardust lib dependency to @iota/sdk (api/client)

* feat: Remove dependency on crypto.js-stardust (steal Bleak2b)

* fix: Remove log-level arg from Dockerfile

* fix: imports and formatting

* chore: Bump api/client version

---------

Co-authored-by: Branko Bosnic <[email protected]>
  • Loading branch information
msarcev and brancoder authored Oct 30, 2023
1 parent c2a92e1 commit e43f490
Show file tree
Hide file tree
Showing 146 changed files with 3,865 additions and 1,487 deletions.
4 changes: 2 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:16-alpine
FROM node:16.20.2-bullseye

## Include the build tools for any npm packages that rebuild
RUN apk --no-cache add git curl python3 build-base cmake
RUN apt install git curl python3

# Working DIR
WORKDIR /usr/src/app
Expand Down
715 changes: 477 additions & 238 deletions api/package-lock.json

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "explorer-api",
"description": "API for Tangle Explorer",
"version": "3.2.0",
"version": "3.3.0",
"author": "Martyn Janes <[email protected]>",
"repository": {
"type": "git",
Expand All @@ -22,22 +22,19 @@
"start": "node ./dist/index"
},
"engines": {
"node": ">=14 <=16.16"
"node": ">=14 <=16.20"
},
"dependencies": {
"@google-cloud/logging-winston": "^5.3.0",
"@iota/core": "^1.0.0-beta.30",
"@iota/crypto.js": "^1.8.6",
"@iota/crypto.js-stardust": "npm:@iota/[email protected]",
"@iota/identity-wasm": "^0.5.0-dev.6",
"@iota/identity-wasm-0.4": "npm:@iota/identity-wasm@^0.4.3",
"@iota/identity-wasm-0.7": "npm:@iota/identity-wasm@^0.7.0-alpha.6",
"@iota/iota.js-chrysalis": "npm:@iota/iota.js@^1.8.6",
"@iota/iota.js-stardust": "npm:@iota/[email protected]",
"@iota/sdk": "1.1.1",
"@iota/mqtt.js": "^1.8.6",
"@iota/mqtt.js-stardust": "npm:@iota/[email protected]",
"@iota/util.js": "^1.8.6",
"@iota/util.js-stardust": "npm:@iota/[email protected]",
"@iota/validators": "^1.0.0-beta.30",
"@types/moment": "^2.13.0",
"@types/node-cron": "^3.0.2",
Expand All @@ -63,7 +60,7 @@
"@types/express": "^4.17.13",
"@types/jest": "^29.2.3",
"@types/jszip": "^3.4.1",
"@types/node": "^16.10.3",
"@types/node": "^16.18.51",
"@types/uuid": "^8.3.1",
"@types/winston": "^2.4.4",
"@typescript-eslint/eslint-plugin": "^5.36.0",
Expand Down
6 changes: 3 additions & 3 deletions api/src/initServices.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MqttClient as ChrysalisMqttClient } from "@iota/mqtt.js";
import { MqttClient as StardustMqttClient } from "@iota/mqtt.js-stardust";
import { Client as StardustMqttClient } from "@iota/sdk";
import { ServiceFactory } from "./factories/serviceFactory";
import logger from "./logger";
import { IConfiguration } from "./models/configuration/IConfiguration";
Expand Down Expand Up @@ -169,8 +169,8 @@ function initStardustServices(networkConfig: INetwork): void {
);

ServiceFactory.register(
`mqtt-${networkConfig.network}`, () => new StardustMqttClient(
networkConfig.feedEndpoint.split(";"))
`mqtt-${networkConfig.network}`,
() => new StardustMqttClient({ nodes: [networkConfig.feedEndpoint], brokerOptions: { useWs: true } })
);

ServiceFactory.register(
Expand Down
4 changes: 2 additions & 2 deletions api/src/models/api/stardust/IAddressDetailsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IOutputResponse } from "@iota/iota.js-stardust";
import { OutputResponse } from "@iota/sdk";
import { IResponse } from "../IResponse";

export interface IAddressDetailsResponse extends IResponse {
/**
* The outputs data.
*/
outputs?: IOutputResponse[];
outputs?: OutputResponse[];
}
4 changes: 2 additions & 2 deletions api/src/models/api/stardust/IAliasResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IOutputResponse } from "@iota/iota.js-stardust";
import { OutputResponse } from "@iota/sdk";
import { IResponse } from "./IResponse";

export interface IAliasResponse extends IResponse {
/**
* The alias details response.
*/
aliasDetails?: IOutputResponse;
aliasDetails?: OutputResponse;
}

2 changes: 1 addition & 1 deletion api/src/models/api/stardust/IBlockDetailsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBlockMetadata } from "@iota/iota.js-stardust";
import { IBlockMetadata } from "@iota/sdk";
import { IResponse } from "../IResponse";

export interface IBlockDetailsResponse extends IResponse {
Expand Down
4 changes: 2 additions & 2 deletions api/src/models/api/stardust/IBlockResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IBlock } from "@iota/iota.js-stardust";
import { Block } from "@iota/sdk";
import { IResponse } from "../IResponse";

export interface IBlockResponse extends IResponse {
/**
* The deserialized block.
*/
block?: IBlock;
block?: Block;
}

2 changes: 1 addition & 1 deletion api/src/models/api/stardust/INodeInfoResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INodeInfoBaseToken, IRent } from "@iota/iota.js-stardust";
import { INodeInfoBaseToken, IRent } from "@iota/sdk";
import { IResponse } from "../IResponse";

/**
Expand Down
4 changes: 2 additions & 2 deletions api/src/models/api/stardust/IOutputDetailsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IOutputResponse } from "@iota/iota.js-stardust";
import { OutputResponse } from "@iota/sdk";
import { IResponse } from "./IResponse";

export interface IOutputDetailsResponse extends IResponse {
/**
* The output data.
*/
output?: IOutputResponse;
output?: OutputResponse;
}
8 changes: 4 additions & 4 deletions api/src/models/api/stardust/ISearchResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBlock, IOutputResponse } from "@iota/iota.js-stardust";
import { Block, OutputResponse } from "@iota/sdk";
import { IResponse } from "../IResponse";
import { IBech32AddressDetails } from "./IBech32AddressDetails";
import { ITaggedOutputsResponse } from "./ITaggedOutputsResponse";
Expand All @@ -8,12 +8,12 @@ export interface ISearchResponse extends IResponse {
/**
* Block if it was found.
*/
block?: IBlock;
block?: Block;

/**
* Transaction included block.
*/
transactionBlock?: IBlock;
transactionBlock?: Block;

/**
* Address details.
Expand All @@ -23,7 +23,7 @@ export interface ISearchResponse extends IResponse {
/**
* Output if it was found (block will also be populated).
*/
output?: IOutputResponse;
output?: OutputResponse;

/**
* Basic and/or Nft tagged output ids.
Expand Down
4 changes: 2 additions & 2 deletions api/src/models/api/stardust/ITransactionDetailsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IBlock } from "@iota/iota.js-stardust";
import { Block } from "@iota/sdk";
import { IResponse } from "../IResponse";

export interface ITransactionDetailsResponse extends IResponse {
/**
* Transaction included block.
*/
block?: IBlock;
block?: Block;
}
2 changes: 1 addition & 1 deletion api/src/models/api/stardust/basic/IBasicOutputsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IOutputsResponse } from "@iota/iota.js-stardust";
import { IOutputsResponse } from "@iota/sdk";
import { IResponse } from "../../IResponse";

export interface IBasicOutputsResponse extends IResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HexEncodedString } from "@iota/iota.js-stardust";
import { HexEncodedString } from "@iota/sdk";
import { IResponse } from "../../IResponse";

export interface IBlockChildrenResponse extends IResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IResponse } from "@iota/iota.js-stardust";
import { IResponse } from "@iota/sdk";

export interface IRichAddress {
address: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IResponse } from "@iota/iota.js-stardust";
import { IResponse } from "@iota/sdk";

export interface IDistributionEntry {
addressCount: string;
Expand Down
2 changes: 1 addition & 1 deletion api/src/models/api/stardust/feed/IFeedItemMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConflictReason } from "@iota/iota.js-stardust";
import { ConflictReason } from "@iota/sdk";

export interface IFeedItemMetadata {
/**
Expand Down
20 changes: 0 additions & 20 deletions api/src/models/api/stardust/feed/IFeedSubscriptionItem.ts

This file was deleted.

6 changes: 3 additions & 3 deletions api/src/models/api/stardust/feed/IFeedUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IMilestonePayload } from "@iota/iota.js-stardust";
import { Block, MilestonePayload } from "@iota/sdk";
import { IFeedItemMetadata } from "./IFeedItemMetadata";

type IFeedBlockUpdate = string;
type IFeedBlockUpdate = Block;

interface IFeedBlockMetadataUpdate {
blockId: string;
Expand All @@ -12,7 +12,7 @@ interface IFeedMilestoneUpdate {
blockId: string;
milestoneId: string;
milestoneIndex: number;
payload: IMilestonePayload;
payload: MilestonePayload;
timestamp: number;
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/models/api/stardust/foundry/IFoundriesResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IOutputsResponse } from "@iota/iota.js-stardust";
import { IOutputsResponse } from "@iota/sdk";
import { IResponse } from "../IResponse";

export interface IFoundriesResponse extends IResponse {
Expand Down
4 changes: 2 additions & 2 deletions api/src/models/api/stardust/foundry/IFoundryResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IOutputResponse } from "@iota/iota.js-stardust";
import { OutputResponse } from "@iota/sdk";
import { IResponse } from "../IResponse";

export interface IFoundryResponse extends IResponse {
/**
* The foundry details response.
*/
foundryDetails?: IOutputResponse;
foundryDetails?: OutputResponse;
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IMilestonePayload } from "@iota/iota.js-stardust";
import { MilestonePayload } from "@iota/sdk";
import { IResponse } from "../../IResponse";

export interface IMilestoneDetailsResponse extends IResponse {
Expand All @@ -13,5 +13,5 @@ export interface IMilestoneDetailsResponse extends IResponse {
/**
* The milestone data.
*/
milestone?: IMilestonePayload;
milestone?: MilestonePayload;
}
4 changes: 2 additions & 2 deletions api/src/models/api/stardust/nft/INftDetailsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IOutputResponse } from "@iota/iota.js-stardust";
import { OutputResponse } from "@iota/sdk";
import { IResponse } from "../IResponse";

export interface INftDetailsResponse extends IResponse {
/**
* The nft details response.
*/
nftDetails?: IOutputResponse;
nftDetails?: OutputResponse;
}

2 changes: 1 addition & 1 deletion api/src/models/api/stardust/nft/INftOutputsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IOutputsResponse } from "@iota/iota.js-stardust";
import { IOutputsResponse } from "@iota/sdk";
import { IResponse } from "../../IResponse";

export interface INftOutputsResponse extends IResponse {
Expand Down
4 changes: 2 additions & 2 deletions api/src/routes/networks/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export async function get(_: IConfiguration): Promise<INetworkGetResponse> {

return {
networks: all
// Only return networks that are not hidden
// Only return networks that are not hidden and enabled
// and copy the fields needed by the client
// as we don't want to expose all the information
.filter(n => !n.isHidden).map(n => ({
.filter(n => !n.isHidden && n.isEnabled).map(n => ({
network: n.network,
label: n.label,
protocolVersion: n.protocolVersion,
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/stardust/output/tagged/get.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Converter } from "@iota/util.js-stardust";
import { ServiceFactory } from "../../../../factories/serviceFactory";
import { IBasicOutputsResponse } from "../../../../models/api/stardust/basic/IBasicOutputsResponse";
import { ITaggedOutputsRequest } from "../../../../models/api/stardust/ITaggedOutputsRequest";
import { INftOutputsResponse } from "../../../../models/api/stardust/nft/INftOutputsResponse";
import { IConfiguration } from "../../../../models/configuration/IConfiguration";
import { STARDUST } from "../../../../models/db/protocolVersion";
import { NetworkService } from "../../../../services/networkService";
import { Converter } from "../../../../utils/convertUtils";
import { StardustTangleHelper } from "../../../../utils/stardust/stardustTangleHelper";
import { ValidationHelper } from "../../../../utils/validationHelper";

Expand Down
Loading

0 comments on commit e43f490

Please sign in to comment.