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

build(deps): bump borsh from 0.7.0 to 2.0.0 #5890

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.