Skip to content

Commit

Permalink
Replace stellar-sdk with @stellar/stellar-sdk (#337)
Browse files Browse the repository at this point in the history
* Replace stellar-sdk with @stellar/stellar-sdk

* Update test

* Update test

* Update GH Action

* Fix ledger fetching

* Fix test

* Disabled lumens catchup tests
  • Loading branch information
quietbits authored Jun 3, 2024
1 parent a93b01f commit 1ab2154
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 221 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: yarn install
Expand Down
4 changes: 2 additions & 2 deletions backend/__tests__/lumens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe("ledgers", () => {
});
});

describe("catchup", () => {
xdescribe("catchup", () => {
jest.setTimeout(50000);

afterAll((done) => {
Expand Down Expand Up @@ -255,7 +255,6 @@ describe("ledgers", () => {

expect(JSON.parse(cachedLedgers as string)).toEqual([
{
date: "2022-1-12 00:00:00",
data: {
end: "2022-01-12T14:45:30Z",
operation_count: 781390,
Expand All @@ -265,6 +264,7 @@ describe("ledgers", () => {
transaction_failure: 147582,
transaction_success: 255436,
},
date: "2022-1-12 00:00:00",
},
]);
expect(cachedPagingToken).toEqual("168147471422193664");
Expand Down
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@google-cloud/bigquery": "^5.11.0",
"@stellar/stellar-sdk": "^11.1.0",
"@stellar/stellar-sdk": "^12.0.0-rc.3",
"@types/express": "^4.17.13",
"@types/express-http-proxy": "^1.6.3",
"@types/morgan": "^1.9.3",
Expand All @@ -31,7 +31,6 @@
"ts-node": "^10.5.0"
},
"devDependencies": {
"jest": "^29.7.0",
"@babel/core": "^7.24.5",
"@babel/plugin-transform-runtime": "^7.24.3",
"@babel/preset-env": "^7.24.5",
Expand All @@ -42,6 +41,7 @@
"@types/node": "^17.0.21",
"@types/urijs": "^1.19.25",
"babel-jest": "^29.7.0",
"jest": "^29.7.0",
"nodemon": "^2.0.15",
"ts-jest": "^28.0.1",
"typescript": "^4.5.5"
Expand Down
18 changes: 9 additions & 9 deletions backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1626,10 +1626,10 @@
resolved "https://registry.yarnpkg.com/@stellar/js-xdr/-/js-xdr-3.1.1.tgz#be0ff90c8a861d6e1101bca130fa20e74d5599bb"
integrity sha512-3gnPjAz78htgqsNEDkEsKHKosV2BF2iZkoHCNxpmZwUxiPsw+2VaXMed8RRMe0rGk3d5GZe7RrSba8zV80J3Ag==

"@stellar/stellar-base@^11.0.1":
version "11.1.0"
resolved "https://registry.yarnpkg.com/@stellar/stellar-base/-/stellar-base-11.1.0.tgz#4b561776cb102a87828379cd1ac5d3ce96db4fb3"
integrity sha512-nMg7QSpFqCZFq3Je/lG12+DY18y01QHRNyCxvjM8i4myS9tPRMDq7zqGcd215BGbCJxenckiOW45YJjQjzdcMQ==
"@stellar/stellar-base@^12.0.0-rc.1":
version "12.0.0-rc.1"
resolved "https://registry.yarnpkg.com/@stellar/stellar-base/-/stellar-base-12.0.0-rc.1.tgz#1c290b36eff54cb6492ce7b5f8de523488a276ba"
integrity sha512-Nm2WeqAnhfsZ2ETTttIJy8epgxGb03EXmWkcmxhyRd0us0qz++i0ry/cSnWaNYDWKipZTuepITUc4nM7o/s1tA==
dependencies:
"@stellar/js-xdr" "^3.1.1"
base32.js "^0.1.0"
Expand All @@ -1640,12 +1640,12 @@
optionalDependencies:
sodium-native "^4.1.1"

"@stellar/stellar-sdk@^11.1.0":
version "11.3.0"
resolved "https://registry.yarnpkg.com/@stellar/stellar-sdk/-/stellar-sdk-11.3.0.tgz#7cb010651846a07e1853e0fe30e430ece4da340b"
integrity sha512-i+heopibJNRA7iM8rEPz0AXphBPYvy2HDo8rxbDwWpozwCfw8kglP9cLkkhgJe8YicgLrdExz/iQZaLpqLC+6w==
"@stellar/stellar-sdk@^12.0.0-rc.3":
version "12.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@stellar/stellar-sdk/-/stellar-sdk-12.0.0-rc.3.tgz#d3e283731302baaba47ae069eff89bf325369859"
integrity sha512-FYO+F8VokXjP3Mu+OQtK0GrJWWvwf1+DL3n3aOi6M5H6EwJ6bp/yAOtfnClx6vqzzvpMbWveYABn8U9QNpcHww==
dependencies:
"@stellar/stellar-base" "^11.0.1"
"@stellar/stellar-base" "^12.0.0-rc.1"
axios "^1.6.8"
bignumber.js "^9.1.2"
eventsource "^2.0.2"
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@reduxjs/toolkit": "^1.7.1",
"@stellar/design-system": "^0.7.0",
"@stellar/frontend-helpers": "^2.1.3",
"@stellar/stellar-sdk": "^12.0.0-rc.3",
"@svgr/webpack": "^6.2.1",
"assert": "^2.0.0",
"bignumber.js": "^9.0.2",
Expand All @@ -48,7 +49,6 @@
"react-router-dom": "^6.2.1",
"recharts": "^2.1.9",
"redux": "^4.1.2",
"stellar-sdk": "^10.1.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"tslib": "^2.3.1",
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/ducks/feeStats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StellarSdk from "stellar-sdk";
import { Horizon } from "@stellar/stellar-sdk";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";

import { RootState } from "config/store";
Expand All @@ -20,8 +20,7 @@ export const fetchFeeStatsDataAction = createAsyncThunk<
{ rejectValue: RejectMessage; state: RootState }
>("feeStats/fetchFeeStatsDataAction", async (_, { rejectWithValue }) => {
try {
const server = new StellarSdk.Server(networkConfig[Network.MAINNET].url);

const server = new Horizon.Server(networkConfig[Network.MAINNET].url);
const response = await server.feeStats();

return response;
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/ducks/ledgers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StellarSdk from "stellar-sdk";
import { Horizon } from "@stellar/stellar-sdk";
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import BigNumber from "bignumber.js";

Expand Down Expand Up @@ -54,7 +54,7 @@ export const fetchLedgersAction = createAsyncThunk<
Network,
{ rejectValue: RejectMessage; state: RootState }
>("ledgers/fetchLedgersAction", async (network, { rejectWithValue }) => {
const server = new StellarSdk.Server(networkConfig[network].url);
const server = new Horizon.Server(networkConfig[network].url);

try {
const ledgerResponse = await server
Expand Down Expand Up @@ -177,14 +177,14 @@ export const startLedgerStreamingAction = createAsyncThunk<
isStreaming: true,
};
}
const server = new StellarSdk.Server(networkConfig[network].url);
const server = new Horizon.Server(networkConfig[network].url);

try {
ledgerStreamRunner = server
.ledgers()
.cursor("now")
.stream({
onmessage: (ledger: LedgerRecord) => {
onmessage: (ledger: any) => {
const { lastLedgerRecords } = ledgersSelector(getState());

if (!lastLedgerRecords[0]) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/ducks/lumenSupply.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StellarSdk from "stellar-sdk";
import { Horizon } from "@stellar/stellar-sdk";
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import BigNumber from "bignumber.js";

Expand Down Expand Up @@ -31,7 +31,7 @@ export const fetchLumenSupplyAction = createAsyncThunk<
let nonCirculating;

if (network === Network.TESTNET) {
const server = new StellarSdk.Server(networkConfig[network].url);
const server = new Horizon.Server(networkConfig[network].url);
const { balances } = await server.loadAccount(FRIENDBOT_PUBLIC_ADDRESS);

total = new BigNumber(FRIENDBOT_STARTING_BALANCE);
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/ducks/operations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import StellarSdk from "stellar-sdk";
import { Horizon } from "@stellar/stellar-sdk";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";

import {
Expand All @@ -22,15 +22,16 @@ export const fetchLastOperationsAction = createAsyncThunk<
"operations/fetchLastOperationsAction",
async (network, { rejectWithValue }) => {
try {
const server = new StellarSdk.Server(networkConfig[network].url);
const server = new Horizon.Server(networkConfig[network].url);

const operations = await server
.operations()
.order("desc")
.limit(10)
.call();

const { records } = operations as OperationsResponse;
// Need to convert to unknown first because there is not enough overlap
const { records } = operations as unknown as OperationsResponse;

const result = records.map((record) => {
const timeAgo = getDateDiffSeconds(
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/helpers/getErrorString.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Horizon } from "stellar-sdk";
import { Horizon } from "@stellar/stellar-sdk";

interface ErrorTextObject {
[key: string]: string;
Expand Down Expand Up @@ -122,8 +122,9 @@ export function getErrorCodes(err: any): string[] {
// first, try to parse the errors in extras
// eslint-disable-next-line camelcase
if (e?.data?.extras?.result_codes) {
const { result_codes: resultCodes }: Horizon.TransactionFailedExtras =
e.data.extras;
const {
result_codes: resultCodes,
}: Horizon.HorizonApi.TransactionFailedExtras = e.data.extras;

if (resultCodes.operations) {
const codes = resultCodes.operations;
Expand Down
62 changes: 4 additions & 58 deletions frontend/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Horizon } from "@stellar/stellar-sdk";

export enum Network {
MAINNET = "mainnet",
TESTNET = "testnet",
Expand Down Expand Up @@ -182,27 +184,7 @@ export type Incident = {
startedAt: string;
};

export type LedgerRecord = {
id: string;
hash: string;
sequence: number;
/* eslint-disable camelcase */
paging_token: string;
prev_hash: string;
successful_transaction_count: number;
failed_transaction_count: number;
operation_count: number;
tx_set_operation_count: number;
closed_at: string;
total_coins: string;
fee_pool: string;
base_fee_in_stroops: number;
base_reserve_in_stroops: number;
max_tx_set_size: number;
protocol_version: number;
header_xdr: string;
/* eslint-enable camelcase */
};
export type LedgerRecord = Horizon.ServerApi.LedgerRecord;

export type LedgerItem = {
sequenceNumber: number;
Expand Down Expand Up @@ -325,43 +307,7 @@ export interface FeesResponse {
primaryValue: string;
}

export interface FeeStatsData {
last_ledger: number;
last_ledger_base_fee: number;
ledger_capacity_usage: number;
fee_charged: {
max: number;
min: number;
mode: number;
p10: number;
p20: number;
p30: number;
p40: number;
p50: number;
p60: number;
p70: number;
p80: number;
p90: number;
p95: number;
p99: number;
};
max_fee: {
max: number;
min: number;
mode: number;
p10: number;
p20: number;
p30: number;
p40: number;
p50: number;
p60: number;
p70: number;
p80: number;
p90: number;
p95: number;
p99: number;
};
}
export type FeeStatsData = Horizon.HorizonApi.FeeStatsResponse;

export interface AverageTransactionFeeData {
month: FeesResponse[];
Expand Down
Loading

0 comments on commit 1ab2154

Please sign in to comment.