Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit c05f445

Browse files
authored
Minor fixes in name-service (#1895)
* Fix reverse twitter registries and program space allocation * Small fixes and address update * Fix the package name
1 parent 81f0b9a commit c05f445

File tree

9 files changed

+288
-259
lines changed

9 files changed

+288
-259
lines changed

name-service/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ js/dist
1919
js/lib
2020
js/docs
2121
js/src/secret.ts
22+
js/src/test.ts

name-service/js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"main": "dist/index.js",
1919
"types": "dist/index.d.ts",
2020
"scripts": {
21-
"dev": "tsc && node --trace-warnings dist/test.js",
21+
"dev": "tsc && node --trace-warnings dist/transfer.js",
2222
"build": "tsc",
2323
"prepublish": "tsc",
2424
"lint": "yarn pretty && eslint .",
@@ -55,6 +55,7 @@
5555
"@solana/web3.js": "^1.11.0",
5656
"bip32": "^2.0.6",
5757
"bn.js": "^5.1.3",
58+
"borsh": "^0.4.0",
5859
"bs58": "4.0.1",
5960
"buffer-layout": "^1.2.0",
6061
"core-util-is": "^1.0.2",

name-service/js/src/bindings.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const NAME_PROGRAM_ID = new PublicKey(
2626
'namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX'
2727
);
2828
export const HASH_PREFIX = 'SPL Name Service';
29-
export const VERIFICATION_AUTHORITY_OFFSET = 64;
3029

3130
////////////////////////////////////////////////////////////
3231
/**
@@ -59,8 +58,6 @@ export async function createNameRegistry(
5958
parentName
6059
);
6160

62-
space += 96; // Accounting for the Registry State Header
63-
6461
const balance = lamports
6562
? lamports
6663
: await connection.getMinimumBalanceForRentExemption(space);

name-service/js/src/state.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
11
import { Connection, PublicKey } from '@solana/web3.js';
2+
import { deserializeUnchecked, Schema } from 'borsh';
23

34
export class NameRegistryState {
5+
static HEADER_LEN = 96;
46
parentName: PublicKey;
57
owner: PublicKey;
68
class: PublicKey;
7-
data: Buffer;
9+
data: Buffer | undefined;
810

11+
static schema: Schema = new Map([
12+
[
13+
NameRegistryState,
14+
{
15+
kind: 'struct',
16+
fields: [
17+
['parentName', [32]],
18+
['owner', [32]],
19+
['class', [32]],
20+
],
21+
},
22+
],
23+
]);
924
constructor(obj: {
1025
parentName: Uint8Array;
1126
owner: Uint8Array;
1227
class: Uint8Array;
13-
data: Uint8Array;
1428
}) {
1529
this.parentName = new PublicKey(obj.parentName);
1630
this.owner = new PublicKey(obj.owner);
1731
this.class = new PublicKey(obj.class);
18-
this.data = Buffer.from(obj.data);
1932
}
2033

21-
static deserialize(buffer: Buffer): NameRegistryState {
22-
return new NameRegistryState({
23-
parentName: buffer.slice(0, 32),
24-
owner: buffer.slice(32, 64),
25-
class: buffer.slice(64, 96),
26-
data: buffer.slice(96, buffer.length),
27-
});
28-
}
29-
30-
static async retrieve(
34+
public static async retrieve(
3135
connection: Connection,
3236
nameAccountKey: PublicKey
3337
): Promise<NameRegistryState> {
34-
const nameAccount = await connection.getAccountInfo(
38+
let nameAccount = await connection.getAccountInfo(
3539
nameAccountKey,
3640
'processed'
3741
);
3842
if (!nameAccount) {
3943
throw new Error('Invalid name account provided');
4044
}
4145

42-
const res: NameRegistryState = NameRegistryState.deserialize(
46+
let res: NameRegistryState = deserializeUnchecked(
47+
this.schema,
48+
NameRegistryState,
4349
nameAccount.data
4450
);
51+
52+
res.data = nameAccount.data?.slice(this.HEADER_LEN);
53+
4554
return res;
4655
}
4756
}

name-service/js/src/test.ts

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)