Skip to content

Commit 4cb7ece

Browse files
Merge pull request #58 from blockfrost/chore/tx-submit-invalidBefore
chore: add invalidBefore in submit test
2 parents 729fa03 + 23f3595 commit 4cb7ece

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/tx-builder/helpers/compose-transaction.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface BlockchainParameters {
1515
| 'max_tx_size'
1616
>;
1717
currentSlot: number;
18+
invalidBefore?: number;
1819
}
1920
export const composeTransaction = (
2021
address: string,
@@ -56,6 +57,12 @@ export const composeTransaction = (
5657

5758
txBuilder.set_ttl(ttl);
5859

60+
if (params.invalidBefore !== undefined) {
61+
txBuilder.set_validity_start_interval_bignum(
62+
CardanoWasm.BigNum.from_str(params.invalidBefore.toString()),
63+
);
64+
}
65+
5966
// Add output to the tx
6067
txBuilder.add_output(
6168
CardanoWasm.TransactionOutput.new(

src/tx-builder/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const buildTx = async (options: {
2929
blockfrostClient: BlockFrostAPI;
3030
network: Network;
3131
blockchainParameters?: BlockchainParameters;
32+
invalidBefore?: number;
3233
}) => {
3334
const { MNEMONIC, OUTPUT_AMOUNT, environment } = await init();
3435
const { blockfrostClient, blockchainParameters } = options;
@@ -68,6 +69,7 @@ export const buildTx = async (options: {
6869
const { txBody } = composeTransaction(address, address, OUTPUT_AMOUNT, utxos, {
6970
protocolParams: protocolParameters,
7071
currentSlot: currentSlot!,
72+
invalidBefore: options.invalidBefore,
7173
});
7274

7375
// Sign transaction

src/tx-builder/test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getConfig } from '../config.js';
1616
* @param options.fetchParametersFromPublicAPI - If true, fetches blockchain parameters from public Blockfrost API instead of the configured backend. Defaults to false.
1717
* @param options.verifyTxUsingPublicAPI - If true, verifies transaction confirmation using public Blockfrost API instead of the configured backend. Defaults to false.
1818
* @param options.blockfrostAPIUrl - Custom Blockfrost API URL to use when fetchParametersFromPublicAPI or verifyTxUsingPublicAPI is true. If not provided, uses the default public Blockfrost API.
19+
* @param options.invalidBefore - Optional slot number. If set, the transaction will not be valid before this slot.
1920
*/
2021
export const submitTest = async (
2122
network: Network,
@@ -25,6 +26,7 @@ export const submitTest = async (
2526
fetchParametersFromPublicAPI?: boolean;
2627
verifyTxUsingPublicAPI?: boolean;
2728
blockfrostAPIUrl?: string;
29+
invalidBefore?: number;
2830
},
2931
) => {
3032
const envConfig = getConfig();
@@ -56,6 +58,7 @@ export const submitTest = async (
5658
network,
5759
blockchainParameters: options?.blockchainParameters,
5860
blockfrostClient: publicBFClient ?? localBFClient,
61+
invalidBefore: options?.invalidBefore,
5962
});
6063
const signedTxJson = signedTx.to_js_value();
6164

@@ -99,7 +102,7 @@ export const submitTest = async (
99102
fees: signedTxJson.body.fee,
100103
deposit: '0',
101104
size: expect.any(Number),
102-
invalid_before: null,
105+
invalid_before: options?.invalidBefore ? String(options.invalidBefore) : null,
103106
invalid_hereafter: signedTxJson.body.ttl,
104107
utxo_count: signedTxJson.body.outputs.length + signedTxJson.body.inputs.length,
105108
withdrawal_count: 0,

0 commit comments

Comments
 (0)