Skip to content

Commit

Permalink
fix backward compatibility for Numberu64 and Numberu32
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 committed Jan 18, 2024
1 parent 9eb34dc commit f4a4425
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
18 changes: 9 additions & 9 deletions js/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export async function createNameRegistry(
nameOwner,
payerKey,
hashed_name,
new Numberu64(BigInt(balance)),
new Numberu32(BigInt(space)),
new Numberu64(balance),
new Numberu32(space),
nameClass,
parentName,
nameParentOwner,
Expand Down Expand Up @@ -155,7 +155,7 @@ export async function updateNameRegistryData(
const updateInstr = updateInstruction(
NAME_PROGRAM_ID,
nameAccountKey,
new Numberu32(BigInt(offset)),
new Numberu32(offset),
input_data,
signer,
);
Expand Down Expand Up @@ -492,8 +492,8 @@ export const createRecordInstruction = async (
owner,
payer,
hashed,
new Numberu64(BigInt(lamports)),
new Numberu32(BigInt(space)),
new Numberu64(lamports),
new Numberu32(space),
undefined,
parent,
owner,
Expand Down Expand Up @@ -577,7 +577,7 @@ export const updateRecordInstruction = async (
const ix = updateInstruction(
NAME_PROGRAM_ID,
pubkey,
new Numberu32(BigInt(0)),
new Numberu32(0),
serialized,
owner,
);
Expand Down Expand Up @@ -802,8 +802,8 @@ export const createSolRecordInstruction = async (
signer,
payer,
hashed,
new Numberu64(BigInt(lamports)),
new Numberu32(BigInt(space)),
new Numberu64(lamports),
new Numberu32(space),
undefined,
parent,
signer,
Expand Down Expand Up @@ -846,7 +846,7 @@ export const updateSolRecordInstruction = async (
const ix = updateInstruction(
NAME_PROGRAM_ID,
pubkey,
new Numberu32(BigInt(0)),
new Numberu32(0),
serialized,
signer,
);
Expand Down
6 changes: 3 additions & 3 deletions js/src/devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ async function createNameRegistry(
nameOwner,
payerKey,
hashed_name,
new Numberu64(BigInt(balance)),
new Numberu32(BigInt(space)),
new Numberu64(balance),
new Numberu32(space),
nameClass,
parentName,
nameParentOwner,
Expand Down Expand Up @@ -296,7 +296,7 @@ async function updateNameRegistryData(
const updateInstr = updateInstruction(
constants.NAME_PROGRAM_ID,
nameAccountKey,
new Numberu32(BigInt(offset)),
new Numberu32(offset),
input_data,
signer,
);
Expand Down
4 changes: 2 additions & 2 deletions js/src/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function createInstruction(
): TransactionInstruction {
const buffers = [
Buffer.from(Int8Array.from([0])),
new Numberu32(BigInt(hashed_name.length)).toBuffer(),
new Numberu32(hashed_name.length).toBuffer(),
hashed_name,
lamports.toBuffer(),
space.toBuffer(),
Expand Down Expand Up @@ -111,7 +111,7 @@ export function updateInstruction(
const buffers = [
Buffer.from(Int8Array.from([1])),
offset.toBuffer(),
new Numberu32(BigInt(input_data.length)).toBuffer(),
new Numberu32(input_data.length).toBuffer(),
input_data,
];

Expand Down
8 changes: 4 additions & 4 deletions js/src/int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ErrorType, SNSError } from "./error";
export class Numberu32 {
value: bigint;

constructor(value: bigint) {
this.value = value;
constructor(value: number | string | bigint) {
this.value = BigInt(value);
}

/**
Expand Down Expand Up @@ -43,8 +43,8 @@ export class Numberu32 {
export class Numberu64 {
value: bigint;

constructor(value: bigint) {
this.value = value;
constructor(value: number | string | bigint) {
this.value = BigInt(value);
}

/**
Expand Down
17 changes: 7 additions & 10 deletions js/src/twitter_bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export async function createVerifiedTwitterRegistry(
verifiedPubkey,
payerKey,
hashedTwitterHandle,
new Numberu64(BigInt(lamports)),
new Numberu32(BigInt(space)),
new Numberu64(lamports),
new Numberu32(space),
undefined,
TWITTER_ROOT_PARENT_REGISTRY_KEY,
TWITTER_VERIFICATION_AUTHORITY, // Twitter authority acts as owner of the parent for all user-facing registries
Expand Down Expand Up @@ -94,7 +94,7 @@ export async function changeTwitterRegistryData(
updateInstruction(
NAME_PROGRAM_ID,
twitterHandleRegistryKey,
new Numberu32(BigInt(offset)),
new Numberu32(offset),
input_data,
verifiedPubkey,
),
Expand Down Expand Up @@ -400,22 +400,19 @@ export async function createReverseTwitterRegistry(
payerKey,
hashedVerifiedPubkey,
new Numberu64(
BigInt(
await connection.getMinimumBalanceForRentExemption(
reverseTwitterRegistryStateBuff.length +
NameRegistryState.HEADER_LEN,
),
await connection.getMinimumBalanceForRentExemption(
reverseTwitterRegistryStateBuff.length + NameRegistryState.HEADER_LEN,
),
),
new Numberu32(BigInt(reverseTwitterRegistryStateBuff.length)),
new Numberu32(reverseTwitterRegistryStateBuff.length),
TWITTER_VERIFICATION_AUTHORITY, // Twitter authority acts as class for all reverse-lookup registries
TWITTER_ROOT_PARENT_REGISTRY_KEY, // Reverse registries are also children of the root
TWITTER_VERIFICATION_AUTHORITY,
),
updateInstruction(
NAME_PROGRAM_ID,
reverseRegistryKey,
new Numberu32(BigInt(0)),
new Numberu32(0),
Buffer.from(reverseTwitterRegistryStateBuff),
TWITTER_VERIFICATION_AUTHORITY,
),
Expand Down

0 comments on commit f4a4425

Please sign in to comment.