radix-utils 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -177,6 +177,73 @@ Executes Promise.all with retry logic and exponential backoff.
177
177
 
178
178
  **Returns:** `Promise<T[]>`
179
179
 
180
+ ### Transaction Functions
181
+
182
+ #### `getEventFromTransaction(gatewayApi, txId, eventName)`
183
+
184
+ Extracts a specific event from a transaction's detailed events.
185
+
186
+ **Parameters:**
187
+
188
+ - `gatewayApi`: GatewayApiClient instance
189
+ - `txId`: String - Transaction intent hash
190
+ - `eventName`: String - Name of the event to extract
191
+
192
+ **Returns:** `Promise<DetailedEventsItem>`
193
+
194
+ **Example:**
195
+
196
+ ```typescript
197
+ const event = await getEventFromTransaction(
198
+ gatewayApi,
199
+ 'txid_rdx1...',
200
+ 'WithdrawEvent'
201
+ );
202
+ console.log('Event data:', event);
203
+ ```
204
+
205
+ #### `getEventKeyValuesFromTransaction(gatewayApi, txId, eventName)`
206
+
207
+ Extracts key-value pairs from a specific event in a transaction.
208
+
209
+ **Parameters:**
210
+
211
+ - `gatewayApi`: GatewayApiClient instance
212
+ - `txId`: String - Transaction intent hash
213
+ - `eventName`: String - Name of the event to extract
214
+
215
+ **Returns:** `Promise<Record<string, string>>`
216
+
217
+ **Example:**
218
+
219
+ ```typescript
220
+ const keyValues = await getEventKeyValuesFromTransaction(
221
+ gatewayApi,
222
+ 'txid_rdx1...',
223
+ 'TransferEvent'
224
+ );
225
+ console.log('Amount:', keyValues.amount);
226
+ console.log('Recipient:', keyValues.recipient);
227
+ ```
228
+
229
+ #### `extractValuesFromTxEvent(event)`
230
+
231
+ Extracts key-value pairs from a transaction event's fields.
232
+
233
+ **Parameters:**
234
+
235
+ - `event`: DetailedEventsItem - The event object to extract values from
236
+
237
+ **Returns:** `Record<string, string>`
238
+
239
+ **Example:**
240
+
241
+ ```typescript
242
+ const event = await getEventFromTransaction(gatewayApi, txId, 'MyEvent');
243
+ const values = extractValuesFromTxEvent(event);
244
+ console.log('Extracted values:', values);
245
+ ```
246
+
180
247
  ## TypeScript Types
181
248
 
182
249
  The library exports comprehensive TypeScript types:
@@ -264,6 +331,15 @@ For issues and feature requests, please use the GitHub issue tracker.
264
331
 
265
332
  ## Changelog
266
333
 
334
+ ### 1.2.0
335
+
336
+ - Added transaction event handling utilities
337
+ - Added `getEventFromTransaction` function for extracting specific events from transactions
338
+ - Added `getEventKeyValuesFromTransaction` function for simplified key-value extraction
339
+ - Added `extractValuesFromTxEvent` function for parsing event field data
340
+ - Added comprehensive test coverage for transaction functionality
341
+ - Updated documentation with transaction utility examples
342
+
267
343
  ### 1.1.0
268
344
 
269
345
  - Added `fetchWalletBalances` function for comprehensive wallet balance fetching
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './types';
2
2
  export { BN, retryPromiseAll } from './utils/decimal';
3
3
  export { calculateEstimatedUnlockDate } from './utils/date';
4
4
  export { fetchWalletBalances } from './utils/wallet';
5
+ export { getEventFromTransaction, getEventKeyValuesFromTransaction, extractValuesFromTxEvent, } from './utils/transaction';
5
6
  export { fetchValidatorInfo, checkResourceInUsersFungibleAssets, computeValidatorFeeFactor, } from './validators';
6
7
  export type { ValidatorInfo, ValidatorVaults, UnlockingRewards, UnlockingReward, NewFeeFactor, FeeFactor, ResourceCheckResult, LedgerStateVersion, WalletBalances, FungibleBalances, NonFungibleBalances, FungibleBalance, NonFungibleBalance, } from './types';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,EAAE,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EACL,kBAAkB,EAClB,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,EAAE,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,kBAAkB,EAClB,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.computeValidatorFeeFactor = exports.checkResourceInUsersFungibleAssets = exports.fetchValidatorInfo = exports.fetchWalletBalances = exports.calculateEstimatedUnlockDate = exports.retryPromiseAll = exports.BN = void 0;
17
+ exports.computeValidatorFeeFactor = exports.checkResourceInUsersFungibleAssets = exports.fetchValidatorInfo = exports.extractValuesFromTxEvent = exports.getEventKeyValuesFromTransaction = exports.getEventFromTransaction = exports.fetchWalletBalances = exports.calculateEstimatedUnlockDate = exports.retryPromiseAll = exports.BN = void 0;
18
18
  // Export types
19
19
  __exportStar(require("./types"), exports);
20
20
  // Export utility functions
@@ -25,6 +25,10 @@ var date_1 = require("./utils/date");
25
25
  Object.defineProperty(exports, "calculateEstimatedUnlockDate", { enumerable: true, get: function () { return date_1.calculateEstimatedUnlockDate; } });
26
26
  var wallet_1 = require("./utils/wallet");
27
27
  Object.defineProperty(exports, "fetchWalletBalances", { enumerable: true, get: function () { return wallet_1.fetchWalletBalances; } });
28
+ var transaction_1 = require("./utils/transaction");
29
+ Object.defineProperty(exports, "getEventFromTransaction", { enumerable: true, get: function () { return transaction_1.getEventFromTransaction; } });
30
+ Object.defineProperty(exports, "getEventKeyValuesFromTransaction", { enumerable: true, get: function () { return transaction_1.getEventKeyValuesFromTransaction; } });
31
+ Object.defineProperty(exports, "extractValuesFromTxEvent", { enumerable: true, get: function () { return transaction_1.extractValuesFromTxEvent; } });
28
32
  // Export validator functions
29
33
  var validators_1 = require("./validators");
30
34
  Object.defineProperty(exports, "fetchValidatorInfo", { enumerable: true, get: function () { return validators_1.fetchValidatorInfo; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,eAAe;AACf,0CAAwB;AAExB,2BAA2B;AAC3B,2CAAsD;AAA7C,6FAAA,EAAE,OAAA;AAAE,0GAAA,eAAe,OAAA;AAC5B,qCAA4D;AAAnD,oHAAA,4BAA4B,OAAA;AACrC,yCAAqD;AAA5C,6GAAA,mBAAmB,OAAA;AAE5B,6BAA6B;AAC7B,2CAIsB;AAHpB,gHAAA,kBAAkB,OAAA;AAClB,gIAAA,kCAAkC,OAAA;AAClC,uHAAA,yBAAyB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,eAAe;AACf,0CAAwB;AAExB,2BAA2B;AAC3B,2CAAsD;AAA7C,6FAAA,EAAE,OAAA;AAAE,0GAAA,eAAe,OAAA;AAC5B,qCAA4D;AAAnD,oHAAA,4BAA4B,OAAA;AACrC,yCAAqD;AAA5C,6GAAA,mBAAmB,OAAA;AAC5B,mDAI6B;AAH3B,sHAAA,uBAAuB,OAAA;AACvB,+HAAA,gCAAgC,OAAA;AAChC,uHAAA,wBAAwB,OAAA;AAG1B,6BAA6B;AAC7B,2CAIsB;AAHpB,gHAAA,kBAAkB,OAAA;AAClB,gIAAA,kCAAkC,OAAA;AAClC,uHAAA,yBAAyB,OAAA"}
@@ -0,0 +1,5 @@
1
+ import { DetailedEventsItem, GatewayApiClient } from '@radixdlt/babylon-gateway-api-sdk';
2
+ export declare const getEventFromTransaction: (gatewayApi: GatewayApiClient, txId: string, eventName: string) => Promise<DetailedEventsItem>;
3
+ export declare const getEventKeyValuesFromTransaction: (gatewayApi: GatewayApiClient, txId: string, eventName: string) => Promise<Record<string, string>>;
4
+ export declare const extractValuesFromTxEvent: (event: DetailedEventsItem) => Record<string, string>;
5
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAE3C,eAAO,MAAM,uBAAuB,GAClC,YAAY,gBAAgB,EAC5B,MAAM,MAAM,EACZ,WAAW,MAAM,gCAuBlB,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAC3C,YAAY,gBAAgB,EAC5B,MAAM,MAAM,EACZ,WAAW,MAAM,oCAIlB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,OAAO,kBAAkB,2BAkBjE,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractValuesFromTxEvent = exports.getEventKeyValuesFromTransaction = exports.getEventFromTransaction = void 0;
4
+ const getEventFromTransaction = async (gatewayApi, txId, eventName) => {
5
+ const txDetails = await gatewayApi.transaction.innerClient.transactionCommittedDetails({
6
+ transactionCommittedDetailsRequest: {
7
+ intent_hash: txId,
8
+ opt_ins: { detailed_events: true },
9
+ },
10
+ });
11
+ const allEvents = txDetails.transaction.receipt?.detailed_events;
12
+ if (!allEvents) {
13
+ throw new Error('No events found in transaction receipt');
14
+ }
15
+ const event = allEvents.find((e) => e.identifier.event === eventName);
16
+ if (!event) {
17
+ throw new Error(`Event '${eventName}' not found in transaction receipt`);
18
+ }
19
+ return event;
20
+ };
21
+ exports.getEventFromTransaction = getEventFromTransaction;
22
+ const getEventKeyValuesFromTransaction = async (gatewayApi, txId, eventName) => {
23
+ const event = await (0, exports.getEventFromTransaction)(gatewayApi, txId, eventName);
24
+ return (0, exports.extractValuesFromTxEvent)(event);
25
+ };
26
+ exports.getEventKeyValuesFromTransaction = getEventKeyValuesFromTransaction;
27
+ const extractValuesFromTxEvent = (event) => {
28
+ const programmatic_json = event.payload.programmatic_json;
29
+ const keyValues = {};
30
+ if (programmatic_json.fields) {
31
+ programmatic_json.fields.forEach((field) => {
32
+ keyValues[field.field_name] = field.value;
33
+ });
34
+ }
35
+ return keyValues;
36
+ };
37
+ exports.extractValuesFromTxEvent = extractValuesFromTxEvent;
38
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AAKO,MAAM,uBAAuB,GAAG,KAAK,EAC1C,UAA4B,EAC5B,IAAY,EACZ,SAAiB,EACjB,EAAE;IACF,MAAM,SAAS,GACb,MAAM,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,2BAA2B,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AC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAlBW,QAAA,wBAAwB,4BAkBnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radix-utils",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Utility functions for Radix DLT blockchain development",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",