From f4a4425f7855c6e47ad1c87a8a6192950459b6b3 Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Thu, 18 Jan 2024 20:17:07 +0800 Subject: [PATCH] fix backward compatibility for `Numberu64` and `Numberu32` --- js/src/bindings.ts | 18 +++++++++--------- js/src/devnet.ts | 6 +++--- js/src/instructions.ts | 4 ++-- js/src/int.ts | 8 ++++---- js/src/twitter_bindings.ts | 17 +++++++---------- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/js/src/bindings.ts b/js/src/bindings.ts index cbbbb28e..49b3a82c 100644 --- a/js/src/bindings.ts +++ b/js/src/bindings.ts @@ -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, @@ -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, ); @@ -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, @@ -577,7 +577,7 @@ export const updateRecordInstruction = async ( const ix = updateInstruction( NAME_PROGRAM_ID, pubkey, - new Numberu32(BigInt(0)), + new Numberu32(0), serialized, owner, ); @@ -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, @@ -846,7 +846,7 @@ export const updateSolRecordInstruction = async ( const ix = updateInstruction( NAME_PROGRAM_ID, pubkey, - new Numberu32(BigInt(0)), + new Numberu32(0), serialized, signer, ); diff --git a/js/src/devnet.ts b/js/src/devnet.ts index 1fcc9446..7c0cb43a 100644 --- a/js/src/devnet.ts +++ b/js/src/devnet.ts @@ -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, @@ -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, ); diff --git a/js/src/instructions.ts b/js/src/instructions.ts index a040c6dd..94aaac48 100644 --- a/js/src/instructions.ts +++ b/js/src/instructions.ts @@ -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(), @@ -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, ]; diff --git a/js/src/int.ts b/js/src/int.ts index 265f1bbb..6120f9ac 100644 --- a/js/src/int.ts +++ b/js/src/int.ts @@ -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); } /** @@ -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); } /** diff --git a/js/src/twitter_bindings.ts b/js/src/twitter_bindings.ts index b18505af..80633d84 100644 --- a/js/src/twitter_bindings.ts +++ b/js/src/twitter_bindings.ts @@ -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 @@ -94,7 +94,7 @@ export async function changeTwitterRegistryData( updateInstruction( NAME_PROGRAM_ID, twitterHandleRegistryKey, - new Numberu32(BigInt(offset)), + new Numberu32(offset), input_data, verifiedPubkey, ), @@ -400,14 +400,11 @@ 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, @@ -415,7 +412,7 @@ export async function createReverseTwitterRegistry( updateInstruction( NAME_PROGRAM_ID, reverseRegistryKey, - new Numberu32(BigInt(0)), + new Numberu32(0), Buffer.from(reverseTwitterRegistryStateBuff), TWITTER_VERIFICATION_AUTHORITY, ),