Skip to content

Commit

Permalink
revert: mirror node queries changes (#2328)
Browse files Browse the repository at this point in the history
* revert changes

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

* update: workflow

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

* update: workflow

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

* update: status codes

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

* update: status codes

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

* chore: correct status code name

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

* update: tests

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

* update: test

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>

---------

Signed-off-by: svetoslav-nikol0v <svetoslav.nikolov@limechain.tech>
  • Loading branch information
svetoslav-nikol0v authored Jun 12, 2024
1 parent 1963a89 commit 484f0f9
Show file tree
Hide file tree
Showing 54 changed files with 950 additions and 1,584 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,38 +156,38 @@ jobs:
id: start-local-node
if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }}
run: |
${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d --network-tag=0.49.7 --balance=100000
${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d -network local --balance=100000
# Wait for the network to fully start
sleep 30
- name: Run Hedera SDK Integration Tests Codecov
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:integration:codecov

- name: Stop the local node
id: stop-local-node
if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop

- name: Build @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task build

- name: Unit Test @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit

- name: Codecov @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit:codecov

- name: Unit Test @hashgraph/sdk
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }}
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit

- name: Codecov @hashgraph/sdk
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit:codecov

- name: Stop the local node
id: stop-local-node
if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop
23 changes: 0 additions & 23 deletions src/Executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import HttpError from "./http/HttpError.js";
* @typedef {import("./Signer.js").Signer} Signer
* @typedef {import("./PublicKey.js").default} PublicKey
* @typedef {import("./logger/Logger.js").default} Logger
* @typedef {import("./LedgerId.js").default} LedgerId
*/

/**
Expand Down Expand Up @@ -135,20 +134,6 @@ export default class Executable {
* @type {Logger | null}
*/
this._logger = null;

/**
* List of mirror network nodes with which execution will be attempted.
* @protected
* @type {string[]}
*/
this._mirrorNetworkNodes = [];

/**
* Current LedgerId of the network with which execution will be attempted.
* @protected
* @type {LedgerId | null}
*/
this._ledgerId = null;
}

/**
Expand Down Expand Up @@ -526,14 +511,6 @@ export default class Executable {
* @returns {Promise<OutputT>}
*/
async execute(client, requestTimeout) {
// Set list of mirror network nodes with
// which execution will be attempted
this._mirrorNetworkNodes = client.mirrorNetwork;

// Set current LedgerId of the network with
// which execution will be attempted
this._ledgerId = client.ledgerId;

// If the logger on the request is not set, use the logger in client
// (if set, otherwise do not use logger)
this._logger =
Expand Down
18 changes: 18 additions & 0 deletions src/Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,10 @@ export default class Status {
return "INVALID_ENDPOINT";
case Status.GossipEndpointsExceededLimit:
return "GOSSIP_ENDPOINTS_EXCEEDED_LIMIT";
case Status.ServiceEndpointsExceededLimit:
return "SERVICE_ENDPOINTS_EXCEEDED_LIMIT";
case Status.InvalidIpv4Address:
return "INVALID_IPV4_ADDRESS";
default:
return `UNKNOWN (${this._code})`;
}
Expand Down Expand Up @@ -1297,6 +1301,10 @@ export default class Status {
return Status.InvalidEndpoint;
case 352:
return Status.GossipEndpointsExceededLimit;
case 356:
return Status.ServiceEndpointsExceededLimit;
case 357:
return Status.InvalidIpv4Address;
default:
throw new Error(
`(BUG) Status.fromCode() does not handle code: ${code}`,
Expand Down Expand Up @@ -2909,3 +2917,13 @@ Status.InvalidEndpoint = new Status(351);
* The number of gossip endpoints exceeds the limit
*/
Status.GossipEndpointsExceededLimit = new Status(352);

/**
* The number of service endpoints exceeds the limit
*/
Status.ServiceEndpointsExceededLimit = new Status(356)

/*
* The IPv4 address is invalid
*/
Status.InvalidIpv4Address = new Status(357)
10 changes: 10 additions & 0 deletions src/account/AccountBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,18 @@ export default class AccountBalance {
*/
this.hbars = props.hbars;

/**
* @deprecated - Use the mirror node API https://docs.hedera.com/guides/docs/mirror-node-api/rest-api#api-v1-accounts instead
* @readonly
*/
// eslint-disable-next-line deprecation/deprecation
this.tokens = props.tokens;

/**
* @deprecated - Use the mirror node API https://docs.hedera.com/guides/docs/mirror-node-api/rest-api#api-v1-accounts instead
* @readonly
*/
// eslint-disable-next-line deprecation/deprecation
this.tokenDecimals = props.tokenDecimals;

Object.freeze(this);
Expand Down
75 changes: 6 additions & 69 deletions src/account/AccountBalanceQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import Query, { QUERY_REGISTRY } from "../query/Query.js";
import AccountId from "./AccountId.js";
import ContractId from "../contract/ContractId.js";
import AccountBalance from "./AccountBalance.js";
import MirrorNodeService from "../network/MirrorNodeService.js";
import MirrorNodeGateway from "../network/MirrorNodeGateway.js";

/**
* @namespace proto
Expand All @@ -33,7 +31,6 @@ import MirrorNodeGateway from "../network/MirrorNodeGateway.js";
* @typedef {import("@hashgraph/proto").proto.IResponseHeader} HashgraphProto.proto.IResponseHeader
* @typedef {import("@hashgraph/proto").proto.ICryptoGetAccountBalanceQuery} HashgraphProto.proto.ICryptoGetAccountBalanceQuery
* @typedef {import("@hashgraph/proto").proto.ICryptoGetAccountBalanceResponse} HashgraphProto.proto.ICryptoGetAccountBalanceResponse
* @typedef {import("@hashgraph/proto").proto.ITokenBalance} HashgraphProto.proto.ITokenBalance
*/

/**
Expand Down Expand Up @@ -72,13 +69,6 @@ export default class AccountBalanceQuery extends Query {
*/
this._contractId = null;

/**
* @private
* @description Delay in ms if is necessary to wait for the mirror node to update the account balance
* @type {number}
*/
this._timeout = 0;

if (props.accountId != null) {
this.setAccountId(props.accountId);
}
Expand Down Expand Up @@ -159,16 +149,6 @@ export default class AccountBalanceQuery extends Query {
return this;
}

/**
*
* @param {number} timeout
* @returns {this}
*/
setTimeout(timeout) {
this._timeout = timeout;
return this;
}

/**
* @protected
* @override
Expand Down Expand Up @@ -230,56 +210,13 @@ export default class AccountBalanceQuery extends Query {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapResponse(response, nodeAccountId, request) {
return new Promise((resolve, reject) => {
const mirrorNodeGateway = MirrorNodeGateway.forNetwork(
this._mirrorNetworkNodes,
this._ledgerId,
const cryptogetAccountBalance =
/** @type {HashgraphProto.proto.ICryptoGetAccountBalanceResponse} */ (
response.cryptogetAccountBalance
);
const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway);

const cryptogetAccountBalanceFromConsensusNode =
/** @type {HashgraphProto.proto.ICryptoGetAccountBalanceResponse} */ (
response.cryptogetAccountBalance
);

if (cryptogetAccountBalanceFromConsensusNode.accountID) {
const accountIdFromConsensusNode = AccountId._fromProtobuf(
cryptogetAccountBalanceFromConsensusNode.accountID,
);

mirrorNodeService
.setTimeout(this._timeout)
.getTokenBalancesForAccount(
accountIdFromConsensusNode.num.toString(),
)
.then(
(
/** @type {HashgraphProto.proto.ITokenBalance[]} */ tokenBalances,
) => {
if (
cryptogetAccountBalanceFromConsensusNode?.tokenBalances &&
tokenBalances
) {
// Reset the array to avoid duplicates
cryptogetAccountBalanceFromConsensusNode.tokenBalances.length = 0;
// Add the token balances from the mirror node to the response from the consensus node
cryptogetAccountBalanceFromConsensusNode.tokenBalances.push(
...tokenBalances,
);

resolve(
AccountBalance._fromProtobuf(
cryptogetAccountBalanceFromConsensusNode,
),
);
}
},
)
.catch((error) => {
reject(error);
});
}
});
return Promise.resolve(
AccountBalance._fromProtobuf(cryptogetAccountBalance),
);
}

/**
Expand Down
84 changes: 10 additions & 74 deletions src/account/AccountInfoQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import AccountId from "./AccountId.js";
import AccountInfo from "./AccountInfo.js";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Hbar from "../Hbar.js";
import MirrorNodeService from "../network/MirrorNodeService.js";
import MirrorNodeGateway from "../network/MirrorNodeGateway.js";

/**
* @namespace proto
Expand All @@ -35,13 +33,11 @@ import MirrorNodeGateway from "../network/MirrorNodeGateway.js";
* @typedef {import("@hashgraph/proto").proto.CryptoGetInfoResponse.IAccountInfo} HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo
* @typedef {import("@hashgraph/proto").proto.ICryptoGetInfoQuery} HashgraphProto.proto.ICryptoGetInfoQuery
* @typedef {import("@hashgraph/proto").proto.ICryptoGetInfoResponse} HashgraphProto.proto.ICryptoGetInfoResponse
* @typedef {import("@hashgraph/proto").proto.ITokenRelationship} HashgraphProto.proto.ITokenRelationship
*/

/**
* @typedef {import("../channel/Channel.js").default} Channel
* @typedef {import("../client/Client.js").default<*, *>} Client
* @typedef {import("../account/TokenRelationship.js").default} TokenRelationship
*/

/**
Expand All @@ -60,17 +56,9 @@ export default class AccountInfoQuery extends Query {
* @type {?AccountId}
*/
this._accountId = null;

if (props.accountId != null) {
this.setAccountId(props.accountId);
}

/**
* @private
* @description Delay in ms if is necessary to wait for the mirror node to update the account info
* @type {number}
*/
this._timeout = 0;
}

/**
Expand Down Expand Up @@ -122,16 +110,6 @@ export default class AccountInfoQuery extends Query {
}
}

/**
*
* @param {number} timeout
* @returns {this}
*/
setTimeout(timeout) {
this._timeout = timeout;
return this;
}

/**
* @override
* @internal
Expand Down Expand Up @@ -178,60 +156,18 @@ export default class AccountInfoQuery extends Query {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_mapResponse(response, nodeAccountId, request) {
return new Promise((resolve, reject) => {
const mirrorNodeGateway = MirrorNodeGateway.forNetwork(
this._mirrorNetworkNodes,
this._ledgerId,
const info =
/** @type {HashgraphProto.proto.ICryptoGetInfoResponse} */ (
response.cryptoGetInfo
);

const mirrorNodeService = new MirrorNodeService(mirrorNodeGateway);

const accountInfoFromConsensusNode =
/** @type {HashgraphProto.proto.ICryptoGetInfoResponse} */ (
response.cryptoGetInfo
);

if (
accountInfoFromConsensusNode.accountInfo &&
accountInfoFromConsensusNode.accountInfo.accountID
) {
const accountIdFromConsensusNode = AccountId._fromProtobuf(
accountInfoFromConsensusNode.accountInfo.accountID,
);

mirrorNodeService
.setTimeout(this._timeout)
.getTokenRelationshipsForAccount(
accountIdFromConsensusNode.num.toString(),
)
.then((tokensRelationships) => {
if (
accountInfoFromConsensusNode.accountInfo
?.tokenRelationships &&
tokensRelationships
) {
// Reset the array to avoid duplicates
accountInfoFromConsensusNode.accountInfo.tokenRelationships.length = 0;

// Add the token relationships from the mirror node to the response from the consensus node
accountInfoFromConsensusNode.accountInfo.tokenRelationships.push(
...tokensRelationships,
);
}

resolve(
AccountInfo._fromProtobuf(
/** @type {HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo} */ (
accountInfoFromConsensusNode.accountInfo
),
),
);
})
.catch((error) => {
reject(error);
});
}
});
return Promise.resolve(
AccountInfo._fromProtobuf(
/** @type {HashgraphProto.proto.CryptoGetInfoResponse.IAccountInfo} */ (
info.accountInfo
),
),
);
}

/**
Expand Down
Loading

0 comments on commit 484f0f9

Please sign in to comment.