Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions packages/payments-engine/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
// src/index.ts
var index_exports = {};
__export(index_exports, {
createTransactionBuilder: () => createTransactionBuilder,
StellarService: () => StellarService,
buildChannelCloseTransaction: () => buildChannelCloseTransaction,
buildSignedTransaction: () => buildSignedTransaction,
Expand All @@ -44,6 +45,7 @@ __export(index_exports, {
sendStellarPayment: () => sendStellarPayment
});
module.exports = __toCommonJS(index_exports);
var import_stellar_sdk = require("stellar-sdk");

// src/stellar.service.ts
var StellarSdk = __toESM(require("stellar-sdk"));
Expand Down Expand Up @@ -297,6 +299,23 @@ var StellarService = class {
}
};

// src/index.ts
var stellarService = new StellarService();
function createTransactionBuilder(source, server) {
const networkPassphrase = server.networkPassphrase || "";
return new import_stellar_sdk.TransactionBuilder(source, {
fee: import_stellar_sdk.BASE_FEE,
// FIX: Use the imported root BASE_FEE constant directly
networkPassphrase
});
}
async function sendStellarPayment(to, amount, asset) {
return stellarService.sendFunds(to, amount.toString(), asset === "XLM" ? void 0 : asset);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createTransactionBuilder,
// src/payment-channel.ts
// src/build-transaction-params.ts
var StellarSdk2 = __toESM(require("stellar-sdk"));
function normalizeSourceAccount(account) {
Expand Down
19 changes: 19 additions & 0 deletions packages/payments-engine/dist/index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// src/index.ts
import { TransactionBuilder as TransactionBuilder2, BASE_FEE as BASE_FEE2 } from "stellar-sdk";

// src/stellar.service.ts
import * as StellarSdk from "stellar-sdk";
function parsePaymentMemo(memo) {
Expand Down Expand Up @@ -250,6 +253,22 @@ var StellarService = class {
}
};

// src/index.ts
var stellarService = new StellarService();
function createTransactionBuilder(source, server) {
const networkPassphrase = server.networkPassphrase || "";
return new TransactionBuilder2(source, {
fee: BASE_FEE2,
// FIX: Use the imported root BASE_FEE constant directly
networkPassphrase
});
}
async function sendStellarPayment(to, amount, asset) {
return stellarService.sendFunds(to, amount.toString(), asset === "XLM" ? void 0 : asset);
}
export {
createTransactionBuilder,
// src/payment-channel.ts
// src/build-transaction-params.ts
import * as StellarSdk2 from "stellar-sdk";
function normalizeSourceAccount(account) {
Expand Down
27 changes: 27 additions & 0 deletions packages/payments-engine/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { Account, Horizon, TransactionBuilder, Networks } from 'stellar-sdk';
import { sendStellarPayment, createTransactionBuilder } from './index';

const mockSendFunds = vi.hoisted(() => vi.fn());
const mockCreateAssetPayment = vi.hoisted(() => vi.fn());
Expand All @@ -11,6 +13,31 @@ vi.mock('./stellar.service', () => {
};
});

describe('createTransactionBuilder', () => {
it('creates a builder with testnet passphrase from server instance', () => {
const source = new Account('GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF', '1');
const testnetPassphrase = Networks.TESTNET;
const server = { networkPassphrase: testnetPassphrase } as unknown as Horizon.Server;

const builder = createTransactionBuilder(source, server);

expect(builder).toBeInstanceOf(TransactionBuilder);
// @ts-ignore - accessing private field for verification
expect(builder.networkPassphrase).toBe(testnetPassphrase);
});

it('creates a builder with public passphrase from server instance', () => {
const source = new Account('GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF', '1');
const publicPassphrase = Networks.PUBLIC;
const server = { networkPassphrase: publicPassphrase } as unknown as Horizon.Server;

const builder = createTransactionBuilder(source, server);

expect(builder).toBeInstanceOf(TransactionBuilder);
// @ts-ignore - accessing private field for verification
expect(builder.networkPassphrase).toBe(publicPassphrase);
});
});
import { sendStellarPayment, createAssetPayment } from './index';

describe('sendStellarPayment', () => {
Expand Down
19 changes: 19 additions & 0 deletions packages/payments-engine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import { Account, Horizon, TransactionBuilder, BASE_FEE } from 'stellar-sdk';
import { StellarService } from './stellar.service';
import { StellarService, type AssetPaymentParams, type PaymentResult } from './stellar.service';

const stellarService = new StellarService();

/**
* Creates and configures a Stellar TransactionBuilder with default settings.
*
* @param source The source Account initiating the transaction.
* @param server The Horizon server instance used to fetch network configuration.
* @returns A configured TransactionBuilder ready for operations.
*/
export function createTransactionBuilder(source: Account, server: Horizon.Server): TransactionBuilder {
// Grab it defensively depending on your exact SDK version structure
const networkPassphrase = (server as any).networkPassphrase || '';

return new TransactionBuilder(source, {
fee: BASE_FEE, // FIX: Use the imported root BASE_FEE constant directly
networkPassphrase,
});
}

export async function sendStellarPayment(
to: string,
amount: number,
Expand Down
Loading