Skip to content

Commit 2040a14

Browse files
committed
Refactor NEAR transaction handling in FireblocksService (#251)
* Refactor NEAR transaction handling in FireblocksService - Renamed to for clarity and updated its implementation to create transactions without waiting for completion. - Introduced a new method to handle transaction completion separately. - Added a new method that combines the creation and completion steps for NEAR transactions. - Updated documentation comments to reflect the changes in method functionality. * bump version
1 parent 4345ff1 commit 2040a14

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kilnfi/sdk",
3-
"version": "4.2.20",
3+
"version": "4.2.21",
44
"autor": "Kiln <[email protected]> (https://kiln.fi)",
55
"license": "BUSL-1.1",
66
"description": "JavaScript sdk for Kiln API",

src/fireblocks.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ export class FireblocksService {
183183
};
184184
}
185185

186-
/**
187-
* Sign a ATOM transaction on Fireblocks
188-
*/
189186
/**
190187
* Create an ATOM transaction in Fireblocks without waiting for completion
191188
*/
@@ -1449,17 +1446,14 @@ export class FireblocksService {
14491446
}
14501447

14511448
/**
1452-
* Sign a Near transaction on Fireblocks
1449+
* Create a NEAR transaction in Fireblocks without waiting for completion
14531450
*/
1454-
async signNearTx(
1451+
async createNearTx(
14551452
integration: FireblocksIntegration,
14561453
tx: components['schemas']['NEARTx'],
14571454
assetId: 'NEAR_TEST' | 'NEAR',
14581455
note?: string,
1459-
): Promise<{
1460-
signed_tx: { data: components['schemas']['NEARSignedTx'] };
1461-
fireblocks_tx: TransactionResponse;
1462-
}> {
1456+
): Promise<TransactionResponse> {
14631457
const payload = {
14641458
rawMessageData: {
14651459
messages: [
@@ -1472,8 +1466,23 @@ export class FireblocksService {
14721466

14731467
const fbSigner = this.getSigner(integration);
14741468
const fbNote = note ? note : 'NEAR tx from @kilnfi/sdk';
1475-
const fbTx = await fbSigner.sign(payload, assetId, fbNote);
1476-
const signature = fbTx.signedMessages?.[0]?.signature?.fullSig;
1469+
return await fbSigner.createTransaction(payload, assetId, fbNote);
1470+
}
1471+
1472+
/**
1473+
* Wait for a NEAR transaction to complete and prepare it for broadcast
1474+
*/
1475+
async waitForNearTxCompletion(
1476+
integration: FireblocksIntegration,
1477+
tx: components['schemas']['NEARTx'],
1478+
fbTx: TransactionResponse,
1479+
): Promise<{
1480+
signed_tx: { data: components['schemas']['NEARSignedTx'] };
1481+
fireblocks_tx: TransactionResponse;
1482+
}> {
1483+
const fbSigner = this.getSigner(integration);
1484+
const completedTx = await fbSigner.waitForTxCompletion(fbTx);
1485+
const signature = completedTx.signedMessages?.[0]?.signature?.fullSig;
14771486

14781487
if (!signature) {
14791488
throw new Error(ERRORS.MISSING_SIGNATURE);
@@ -1496,6 +1505,22 @@ export class FireblocksService {
14961505
};
14971506
}
14981507

1508+
/**
1509+
* Sign a NEAR transaction on Fireblocks (combines createNearTx and waitForNearTxCompletion)
1510+
*/
1511+
async signNearTx(
1512+
integration: FireblocksIntegration,
1513+
tx: components['schemas']['NEARTx'],
1514+
assetId: 'NEAR_TEST' | 'NEAR',
1515+
note?: string,
1516+
): Promise<{
1517+
signed_tx: { data: components['schemas']['NEARSignedTx'] };
1518+
fireblocks_tx: TransactionResponse;
1519+
}> {
1520+
const fbTx = await this.createNearTx(integration, tx, assetId, note);
1521+
return await this.waitForNearTxCompletion(integration, tx, fbTx);
1522+
}
1523+
14991524
/**
15001525
* Sign a Trx transaction on Fireblocks
15011526
*/

0 commit comments

Comments
 (0)