Skip to content

Commit

Permalink
build(deps): bump borsh from 0.7.0 to 2.0.0 (#5890)
Browse files Browse the repository at this point in the history
* build(deps): bump borsh from 0.7.0 to 2.0.0

Bumps [borsh](https://github.com/near/borsh-js) from 0.7.0 to 2.0.0.
- [Release notes](https://github.com/near/borsh-js/releases)
- [Commits](near/borsh-js@v0.7.0...v2.0.0)

---
updated-dependencies:
- dependency-name: borsh
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix for new borsh version

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jon Cinque <[email protected]>
  • Loading branch information
dependabot[bot] and joncinque authored Dec 1, 2023
1 parent eeb1ca9 commit 71e9818
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 50 deletions.
1 change: 0 additions & 1 deletion account-compression/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@metaplex-foundation/beet": "^0.7.1",
"@metaplex-foundation/beet-solana": "^0.4.0",
"bn.js": "^5.2.1",
"borsh": "^0.7.0",
"js-sha3": "^0.9.2",
"typescript-collections": "^1.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion name-service/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"dependencies": {
"@solana/web3.js": "^1.87.6",
"bn.js": "^5.1.3",
"borsh": "^0.7.0"
"borsh": "^2.0.0"
},
"mocha": {
"require": [
Expand Down
41 changes: 17 additions & 24 deletions name-service/js/src/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Connection, PublicKey } from '@solana/web3.js';
import { deserializeUnchecked, Schema } from 'borsh';
import { deserialize, Schema } from 'borsh';

type InitArgs = {
parentName: Uint8Array;
owner: Uint8Array;
class: Uint8Array;
};

export class NameRegistryState {
static HEADER_LEN = 96;
Expand All @@ -8,24 +14,14 @@ export class NameRegistryState {
class: PublicKey;
data: Buffer | undefined;

static schema: Schema = new Map([
[
NameRegistryState,
{
kind: 'struct',
fields: [
['parentName', [32]],
['owner', [32]],
['class', [32]],
],
},
],
]);
constructor(obj: {
parentName: Uint8Array;
owner: Uint8Array;
class: Uint8Array;
}) {
static schema: Schema = {
struct: {
parentName: { array: { type: 'u8', len: 32 } },
owner: { array: { type: 'u8', len: 32 } },
class: { array: { type: 'u8', len: 32 } },
},
};
constructor(obj: InitArgs) {
this.parentName = new PublicKey(obj.parentName);
this.owner = new PublicKey(obj.owner);
this.class = new PublicKey(obj.class);
Expand All @@ -43,11 +39,8 @@ export class NameRegistryState {
throw new Error('Invalid name account provided');
}

const res: NameRegistryState = deserializeUnchecked(
this.schema,
NameRegistryState,
nameAccount.data,
);
const deserialized = deserialize(this.schema, nameAccount.data) as InitArgs;
const res = new NameRegistryState(deserialized);

res.data = nameAccount.data?.slice(this.HEADER_LEN);

Expand Down
30 changes: 11 additions & 19 deletions name-service/js/src/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
SystemProgram,
TransactionInstruction,
} from '@solana/web3.js';
import { deserialize, deserializeUnchecked, Schema, serialize } from 'borsh';
import { deserialize, Schema, serialize } from 'borsh';

import { deleteNameRegistry, NAME_PROGRAM_ID } from './bindings';
import {
Expand Down Expand Up @@ -291,11 +291,10 @@ export async function getTwitterHandleandRegistryKeyViaFilters(
for (const f of filteredAccounts) {
if (f.accountInfo.data.length > NameRegistryState.HEADER_LEN + 32) {
const data = f.accountInfo.data.slice(NameRegistryState.HEADER_LEN);
const state: ReverseTwitterRegistryState = deserialize(
const state = deserialize(
ReverseTwitterRegistryState.schema,
ReverseTwitterRegistryState,
data,
);
) as ReverseTwitterRegistryState;
return [state.twitterHandle, new PublicKey(state.twitterRegistryKey)];
}
}
Expand Down Expand Up @@ -351,18 +350,12 @@ export class ReverseTwitterRegistryState {
twitterRegistryKey: Uint8Array;
twitterHandle: string;

static schema: Schema = new Map([
[
ReverseTwitterRegistryState,
{
kind: 'struct',
fields: [
['twitterRegistryKey', [32]],
['twitterHandle', 'string'],
],
},
],
]);
static schema: Schema = {
struct: {
twitterRegistryKey: { array: { type: 'u8', len: 32 } },
twitterHandle: 'string',
},
};
constructor(obj: { twitterRegistryKey: Uint8Array; twitterHandle: string }) {
this.twitterRegistryKey = obj.twitterRegistryKey;
this.twitterHandle = obj.twitterHandle;
Expand All @@ -380,11 +373,10 @@ export class ReverseTwitterRegistryState {
throw new Error('Invalid reverse Twitter account provided');
}

const res: ReverseTwitterRegistryState = deserializeUnchecked(
const res = deserialize(
this.schema,
ReverseTwitterRegistryState,
reverseTwitterAccount.data.slice(NameRegistryState.HEADER_LEN),
);
) as ReverseTwitterRegistryState;

return res;
}
Expand Down
11 changes: 6 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71e9818

Please sign in to comment.