Skip to content

Commit 13df73a

Browse files
authored
Merge pull request #175 from fleet-sdk/add-tx-parsing
Add Box and Transaction deserialization
2 parents 242bb62 + d6fa564 commit 13df73a

32 files changed

+1035
-197
lines changed

.changeset/cyan-wasps-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fleet-sdk/serializer": patch
3+
---
4+
5+
Add `deserializeBox` function

.changeset/eleven-horses-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fleet-sdk/serializer": patch
3+
---
4+
5+
Add `deserializeTransaction` function

.changeset/floppy-wings-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fleet-sdk/common": patch
3+
---
4+
5+
Add offset support to `startsWith`

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
"pnpm": {
5151
"requiredScripts": [
5252
"build"
53+
],
54+
"onlyBuiltDependencies": [
55+
"esbuild"
5356
]
5457
}
5558
}

packages/common/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const FEE_CONTRACT =
2+
"1005040004000e36100204a00b08cd0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ea02d192a39a8cc7a701730073011001020402d19683030193a38cc7b2a57300000193c2b2a57301007473027303830108cdeeac93b1a57304";
3+
export const RECOMMENDED_MIN_FEE_VALUE = BigInt(1100000);

packages/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from "./utils";
22
export * from "./types";
33
export * from "./models/collection";
44
export * from "./error";
5+
export * from "./constants";

packages/common/src/utils/array.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ describe("startsWith()", () => {
297297
expect(startsWith(array, array)).toBeTruthy();
298298
});
299299

300+
it("Should return true if starts with target with offset", () => {
301+
// index: 0, 1, 2, 3, 4, 5, 6, 7
302+
const array = [1, 2, 4, 5, 6, 7, 8, 9];
303+
304+
expect(startsWith(array, [2, 4], 1)).toBeTruthy();
305+
expect(startsWith(array, [6, 7], 4)).toBeTruthy();
306+
expect(startsWith(array, [9, 10], 7)).toBeFalsy();
307+
expect(startsWith(array, [1], 0)).toBeTruthy();
308+
expect(startsWith(array, array)).toBeTruthy();
309+
});
310+
300311
it("Should return false for not starts with target", () => {
301312
const array = [1, 2, 4, 5, 0];
302313

packages/common/src/utils/array.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,16 @@ export function areEqualBy<T>(
205205
* startsWith(array, target2); // false
206206
* ```
207207
*/
208-
export function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
209-
if (array === target) {
210-
return true;
211-
}
212-
213-
if (target.length > array.length) {
214-
return false;
215-
}
208+
export function startsWith<T>(
209+
array: ArrayLike<T>,
210+
target: ArrayLike<T>,
211+
offset = 0
212+
): boolean {
213+
if (array === target) return true;
214+
if (target.length > array.length) return false;
216215

217216
for (let i = 0; i < target.length; i++) {
218-
if (target[i] !== array[i]) {
219-
return false;
220-
}
217+
if (target[i] !== array[i + offset]) return false;
221218
}
222219

223220
return true;
@@ -239,16 +236,10 @@ export function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolea
239236
* ```
240237
*/
241238
export function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean {
242-
if (array === target) {
243-
return true;
244-
}
245-
246-
if (target.length > array.length) {
247-
return false;
248-
}
239+
if (array === target) return true;
240+
if (target.length > array.length) return false;
249241

250242
const offset = array.length - target.length;
251-
252243
for (let i = target.length - 1; i >= 0; i--) {
253244
if (target[i] !== array[i + offset]) {
254245
return false;

packages/core/src/builder/pluginContext.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
33
import { NotAllowedTokenBurning } from "../errors";
44
import { OutputBuilder } from "./outputBuilder";
55
import { createPluginContext, type FleetPluginContext } from "./pluginContext";
6-
import { RECOMMENDED_MIN_FEE_VALUE, TransactionBuilder } from "./transactionBuilder";
6+
import { TransactionBuilder } from "./transactionBuilder";
7+
import { RECOMMENDED_MIN_FEE_VALUE } from "@fleet-sdk/common";
78

89
describe("Plugin context", () => {
910
const creationHeight = 894169;

packages/core/src/builder/transactionBuilder.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ import {
2020
OutputBuilder,
2121
SAFE_MIN_BOX_VALUE
2222
} from "./outputBuilder";
23-
import {
24-
FEE_CONTRACT,
25-
RECOMMENDED_MIN_FEE_VALUE,
26-
TransactionBuilder
27-
} from "./transactionBuilder";
23+
import { TransactionBuilder } from "./transactionBuilder";
2824
import { mockUTxO } from "packages/mock-chain/src";
25+
import { FEE_CONTRACT, RECOMMENDED_MIN_FEE_VALUE } from "@fleet-sdk/common";
2926

3027
const height = 844540;
3128
const a1 = {

0 commit comments

Comments
 (0)