Skip to content

Commit

Permalink
Add imp for stellar
Browse files Browse the repository at this point in the history
  • Loading branch information
Salim-belkhir committed Dec 18, 2024
1 parent 00cf86d commit 96e407c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function buildOptimisticOperation(
transactionSequenceNumber: transactionSequenceNumber?.plus(1).toNumber(),
extra: {
ledgerOpType: type,
blockTime: new Date(),
},
};

Expand Down
10 changes: 10 additions & 0 deletions libs/coin-modules/coin-stellar/src/logic/listOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export type Operation = {
value: bigint;
fee: bigint;
blockHeight: number;
block?: {
hash: string;
time: Date;
height: number;
};
senders: string[];
recipients: string[];
date: Date;
Expand Down Expand Up @@ -42,6 +47,11 @@ const convertToCoreOperation = (address: string) => (operation: StellarOperation
value: BigInt(operation.value.toString()),
fee: BigInt(operation.fee.toString()),
blockHeight: operation.blockHeight!,
block: {
hash: operation.blockHash!,
time: operation.extra.blockTime,
height: operation.blockHeight!,
},
senders: operation.senders,
recipients: operation.recipients,
date: operation.date,
Expand Down
16 changes: 13 additions & 3 deletions libs/coin-modules/coin-stellar/src/network/horizon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,24 @@ Horizon.AxiosClient.interceptors.response.use(response => {
// FIXME: workaround for the Stellar SDK not using the correct URL: the "next" URL
// included in server responses points to the node itself instead of our reverse proxy...
// (https://github.com/stellar/js-stellar-sdk/issues/637)

function fixURL(url: string): string {
const u = new URL(url);
u.host = new URL(coinConfig.getCoinConfig().explorer.url).host;
return u.toString();
}

const next_href = response?.data?._links?.next?.href;

if (next_href) {
const next = new URL(next_href);
next.host = new URL(coinConfig.getCoinConfig().explorer.url).host;
response.data._links.next.href = next.toString();
response.data._links.next.href = fixURL(next_href);
}

response?.data?._embedded?.records?.forEach((r: any) => {
const href = r.transaction?._links?.ledger?.href;
if (href) r.transaction._links.ledger.href = fixURL(href);
});

return response;
});

Expand Down
4 changes: 3 additions & 1 deletion libs/coin-modules/coin-stellar/src/network/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ async function formatOperation(
addr: string,
): Promise<StellarOperation> {
const transaction = await rawOperation.transaction();
const { hash: blockHash, closed_at: blockTime } = await transaction.ledger();
const type = getOperationType(rawOperation, addr);
const value = getValue(rawOperation, transaction, type);
const recipients = getRecipients(rawOperation);
Expand All @@ -103,9 +104,10 @@ async function formatOperation(
recipients,
transactionSequenceNumber: Number(transaction.source_account_sequence),
hasFailed: !rawOperation.transaction_successful,
blockHash: null,
blockHash: blockHash,
extra: {
ledgerOpType: type,
blockTime: new Date(blockTime),
},
};

Expand Down
1 change: 1 addition & 0 deletions libs/coin-modules/coin-stellar/src/types/bridge.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function createFixtureOperation(operation?: Partial<StellarOperation>): S
let extra: StellarOperationExtra = {
assetAmount: operation?.extra?.assetAmount || undefined,
ledgerOpType: operation?.extra?.ledgerOpType || "IN",
blockTime: operation?.extra?.blockTime || faker.date.past(),
};
if (operation?.extra?.pagingToken) {
extra = {
Expand Down
1 change: 1 addition & 0 deletions libs/coin-modules/coin-stellar/src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export type StellarOperationExtra = {
assetAmount?: string | undefined;
ledgerOpType: OperationType;
memo?: string;
blockTime: Date;
};

export type StellarAccount = Account;

0 comments on commit 96e407c

Please sign in to comment.