Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major Update of Borsh #65

Merged
merged 35 commits into from
Aug 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8f0b620
indexed by class name instead of the class itself
gagdiez Jul 14, 2023
6e514ab
serializer 1.0
gagdiez Jul 19, 2023
7b3fe19
Implemented deserializer
gagdiez Jul 20, 2023
8fba23d
Fixed indentation
gagdiez Jul 20, 2023
9cd1a01
Added schema validation
gagdiez Jul 21, 2023
6137793
minor improvements
gagdiez Jul 21, 2023
a8a0e83
added more tests
gagdiez Jul 21, 2023
7d46f8b
added more tests
gagdiez Jul 21, 2023
5e89593
added more tests
gagdiez Jul 21, 2023
c64fd81
updated readme
gagdiez Jul 21, 2023
fb64d67
minor fix to examples
gagdiez Jul 21, 2023
da7ef6b
bump in version
gagdiez Jul 21, 2023
67c75f4
minor update to README.md
gagdiez Jul 21, 2023
0367248
minor update to README.md
gagdiez Jul 21, 2023
04b13b3
trigger actions
gagdiez Jul 21, 2023
ad6eeb0
Removed unnecesary packages + fixed lint
gagdiez Jul 21, 2023
f0ee708
simplified buffer
gagdiez Jul 21, 2023
e2a8310
added base encode/decode
gagdiez Jul 21, 2023
019d58e
implemented enums and removed deserializing of classes
gagdiez Jul 25, 2023
b50bc1f
better organized testing
gagdiez Jul 26, 2023
49b96a2
exported schema
gagdiez Jul 26, 2023
a47e7ff
Added forgotten schemas to schema type
gagdiez Jul 26, 2023
b34a106
allowing numbers in BN
gagdiez Jul 26, 2023
7204e49
schema now leads serialization order
gagdiez Jul 26, 2023
dd1cbb4
bump version
gagdiez Jul 26, 2023
d580c8c
feat: allow strings in BN
gagdiez Jul 26, 2023
d452862
feat: more tests & checkSchema flag
gagdiez Jul 28, 2023
988fb57
fix: made compatible to ES5
gagdiez Jul 28, 2023
263e902
updated readme
gagdiez Jul 28, 2023
b97b6e7
feat: building cjs & esm
gagdiez Jul 31, 2023
dbebcd7
feat: cjs & esm working versions
gagdiez Aug 1, 2023
22a824c
removed BN.js & bs58
gagdiez Aug 2, 2023
fb89acf
simplified tests
gagdiez Aug 2, 2023
2384755
small change in bigint method
gagdiez Aug 3, 2023
e1881a0
added compatibility with BN
gagdiez Aug 3, 2023
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
Prev Previous commit
Next Next commit
Fixed indentation
gagdiez committed Jul 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8fba23d6e3b8dcf6f47b900f0395ec764336f3a4
2 changes: 1 addition & 1 deletion borsh-ts/buffer.ts
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ export class DecodeBuffer {
throw new Error(`Unsupported integer type: ${type}`);
}
this.offset += size;
return ret;
return ret;
}

consume_bytes(size: number): ArrayBuffer {
4 changes: 2 additions & 2 deletions borsh-ts/deserialize.ts
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ export class BorshDeserializer {

decode_array(schema: ArrayType): Array<any> {
const result = [];
const len = schema.array.len? schema.array.len : this.decode_integer('u32') as number;
const len = schema.array.len ? schema.array.len : this.decode_integer('u32') as number;

for (let i = 0; i < len; ++i) {
result.push(this.decode(schema.array.type));
@@ -114,6 +114,6 @@ export class BorshDeserializer {
for (const key in schema.struct) {
result[key] = this.decode(schema.struct[key]);
}
return classType? new classType(result) : result;
return classType ? new classType(result) : result;
}
}
4 changes: 2 additions & 2 deletions borsh-ts/test/deserialize.test.js
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ function check_decode(expected, schema, buffer, classType) {
if (expected && typeof (expected) === 'object' && 'eq' in expected) {
expect(expected.eq(decoded)).toBe(true);
} else {
if(schema === 'f32'){
if (schema === 'f32') {
expect(decoded).toBeCloseTo(expected);
}else{
} else {
expect(decoded).toEqual(expected);
}
}
2 changes: 1 addition & 1 deletion borsh-ts/test/serialize.test.js
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ test('serialize arrays', async () => {
check_encode(new ArrayBuffer(2), { array: { type: 'u8' } }, [2, 0, 0, 0, 0, 0]);

const buffer = new ArrayBuffer(2);
new Uint8Array(buffer).set([1,2]);
new Uint8Array(buffer).set([1, 2]);
check_encode(buffer, { array: { type: 'u8', len: 2 } }, [1, 2]);
});