Skip to content

Commit 55d90ac

Browse files
committed
Refactor function signatures for node-litesvm
1 parent 903ecce commit 55d90ac

File tree

7 files changed

+33
-34
lines changed

7 files changed

+33
-34
lines changed

‎Cargo.lock‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ itertools = "0.14"
2323
libsecp256k1 = "0.6.0"
2424
litesvm = { path = "crates/litesvm", version = "0.6" }
2525
log = "0.4"
26-
napi = { version = "3.2.3", default-features = false }
27-
napi-derive = "3.2.3"
26+
napi = { version = "3.2.4", default-features = false }
27+
napi-derive = "3.2.4"
2828
qualifier_attr = "0.2.2"
2929
serde = "1.0"
3030
smallvec = "1.13"

‎crates/node-litesvm/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"devDependencies": {
2626
"@algolia/client-search": ">= 4.9.1 < 6",
27-
"@napi-rs/cli": "^3.1.4",
27+
"@napi-rs/cli": "^3.1.5",
2828
"@solana/spl-token": "^0.4.13",
2929
"@swc/core": "^1.10.7",
3030
"@types/markdown-it": "^14.1.0",

‎crates/node-litesvm/src/feature_set.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use {
22
crate::{to_string_js, util::convert_pubkey},
33
agave_feature_set::FeatureSet as FeatureSetOriginal,
4-
napi::bindgen_prelude::*,
54
};
65

76
#[derive(Debug, Clone)]
@@ -21,12 +20,12 @@ impl FeatureSet {
2120
}
2221

2322
#[napi]
24-
pub fn is_active(&self, feature_id: Uint8Array) -> bool {
23+
pub fn is_active(&self, feature_id: &[u8]) -> bool {
2524
self.0.is_active(&convert_pubkey(feature_id))
2625
}
2726

2827
#[napi]
29-
pub fn activated_slot(&self, feature_id: Uint8Array) -> Option<u64> {
28+
pub fn activated_slot(&self, feature_id: &[u8]) -> Option<u64> {
3029
self.0.activated_slot(&convert_pubkey(feature_id))
3130
}
3231
}

‎crates/node-litesvm/src/lib.rs‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,21 @@ impl LiteSvm {
180180

181181
#[napi]
182182
/// Returns all information associated with the account of the provided pubkey.
183-
pub fn get_account(&self, pubkey: Uint8Array) -> Option<Account> {
183+
pub fn get_account(&self, pubkey: &[u8]) -> Option<Account> {
184184
self.0.get_account(&convert_pubkey(pubkey)).map(Account)
185185
}
186186

187187
#[napi]
188188
/// Sets all information associated with the account of the provided pubkey.
189-
pub fn set_account(&mut self, pubkey: Uint8Array, data: &Account) -> Result<()> {
189+
pub fn set_account(&mut self, pubkey: &[u8], data: &Account) -> Result<()> {
190190
self.0
191191
.set_account(convert_pubkey(pubkey), data.0.clone())
192192
.map_err(|e| to_js_error(e, "Failed to set account"))
193193
}
194194

195195
#[napi]
196196
/// Gets the balance of the provided account pubkey.
197-
pub fn get_balance(&self, pubkey: Uint8Array) -> Option<u64> {
197+
pub fn get_balance(&self, pubkey: &[u8]) -> Option<u64> {
198198
self.0.get_balance(&convert_pubkey(pubkey))
199199
}
200200

@@ -206,15 +206,15 @@ impl LiteSvm {
206206

207207
#[napi(ts_return_type = "TransactionMetadata | FailedTransactionMetadata | null")]
208208
/// Gets a transaction from the transaction history.
209-
pub fn get_transaction(&self, signature: Uint8Array) -> Option<TransactionResult> {
209+
pub fn get_transaction(&self, signature: &[u8]) -> Option<TransactionResult> {
210210
self.0
211-
.get_transaction(&Signature::try_from(signature.as_ref()).unwrap())
211+
.get_transaction(&Signature::try_from(signature).unwrap())
212212
.map(|x| convert_transaction_result(x.clone()))
213213
}
214214

215215
#[napi(ts_return_type = "TransactionMetadata | FailedTransactionMetadata | null")]
216216
/// Airdrops the account with the lamports specified.
217-
pub fn airdrop(&mut self, pubkey: Uint8Array, lamports: BigInt) -> Result<TransactionResult> {
217+
pub fn airdrop(&mut self, pubkey: &[u8], lamports: BigInt) -> Result<TransactionResult> {
218218
Ok(convert_transaction_result(self.0.airdrop(
219219
&convert_pubkey(pubkey),
220220
bigint_to_u64(&lamports)?,
@@ -223,7 +223,7 @@ impl LiteSvm {
223223

224224
#[napi]
225225
/// Adds am SBF program to the test environment from the file specified.
226-
pub fn add_program_from_file(&mut self, program_id: Uint8Array, path: String) -> Result<()> {
226+
pub fn add_program_from_file(&mut self, program_id: &[u8], path: String) -> Result<()> {
227227
self.0
228228
.add_program_from_file(convert_pubkey(program_id), path)
229229
.map_err(|e| {
@@ -236,7 +236,7 @@ impl LiteSvm {
236236

237237
#[napi]
238238
/// Adds am SBF program to the test environment.
239-
pub fn add_program(&mut self, program_id: Uint8Array, program_bytes: &[u8]) -> Result<()> {
239+
pub fn add_program(&mut self, program_id: &[u8], program_bytes: &[u8]) -> Result<()> {
240240
self.0
241241
.add_program(convert_pubkey(program_id), program_bytes)
242242
.map_err(|e| {
@@ -248,29 +248,29 @@ impl LiteSvm {
248248
}
249249

250250
#[napi(ts_return_type = "TransactionMetadata | FailedTransactionMetadata")]
251-
pub fn send_legacy_transaction(&mut self, tx_bytes: Uint8Array) -> TransactionResult {
252-
let tx: Transaction = deserialize(&tx_bytes).unwrap();
251+
pub fn send_legacy_transaction(&mut self, tx_bytes: &[u8]) -> TransactionResult {
252+
let tx: Transaction = deserialize(tx_bytes).unwrap();
253253
let res = self.0.send_transaction(tx);
254254
convert_transaction_result(res)
255255
}
256256

257257
#[napi(ts_return_type = "TransactionMetadata | FailedTransactionMetadata")]
258-
pub fn send_versioned_transaction(&mut self, tx_bytes: Uint8Array) -> TransactionResult {
259-
let tx: VersionedTransaction = deserialize(&tx_bytes).unwrap();
258+
pub fn send_versioned_transaction(&mut self, tx_bytes: &[u8]) -> TransactionResult {
259+
let tx: VersionedTransaction = deserialize(tx_bytes).unwrap();
260260
let res = self.0.send_transaction(tx);
261261
convert_transaction_result(res)
262262
}
263263

264264
#[napi(ts_return_type = "SimulatedTransactionInfo | FailedTransactionMetadata")]
265-
pub fn simulate_legacy_transaction(&mut self, tx_bytes: Uint8Array) -> SimulateResult {
266-
let tx: Transaction = deserialize(&tx_bytes).unwrap();
265+
pub fn simulate_legacy_transaction(&mut self, tx_bytes: &[u8]) -> SimulateResult {
266+
let tx: Transaction = deserialize(tx_bytes).unwrap();
267267
let res = self.0.simulate_transaction(tx);
268268
convert_sim_result(res)
269269
}
270270

271271
#[napi(ts_return_type = "SimulatedTransactionInfo | FailedTransactionMetadata")]
272-
pub fn simulate_versioned_transaction(&mut self, tx_bytes: Uint8Array) -> SimulateResult {
273-
let tx: VersionedTransaction = deserialize(&tx_bytes).unwrap();
272+
pub fn simulate_versioned_transaction(&mut self, tx_bytes: &[u8]) -> SimulateResult {
273+
let tx: VersionedTransaction = deserialize(tx_bytes).unwrap();
274274
let res = self.0.simulate_transaction(tx);
275275
convert_sim_result(res)
276276
}

‎crates/node-litesvm/src/util.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use {napi::bindgen_prelude::*, solana_hash::Hash, solana_pubkey::Pubkey, std::str::FromStr};
22

3-
pub(crate) fn convert_pubkey(address: Uint8Array) -> Pubkey {
4-
Pubkey::try_from(address.as_ref()).unwrap()
3+
pub(crate) fn convert_pubkey(address: &[u8]) -> Pubkey {
4+
Pubkey::try_from(address).unwrap()
55
}
66

77
pub(crate) fn try_parse_hash(raw: &str) -> Result<Hash> {

‎crates/node-litesvm/yarn.lock‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@
525525
"@jridgewell/resolve-uri" "^3.0.3"
526526
"@jridgewell/sourcemap-codec" "^1.4.10"
527527

528-
"@napi-rs/cli@^3.1.4":
529-
version "3.1.4"
530-
resolved "https://registry.yarnpkg.com/@napi-rs/cli/-/cli-3.1.4.tgz#13000ad4fab5a8f4ad39145ad352c64511367c83"
531-
integrity sha512-XwYu7XB9KfL0ChFc90j9/XQJzbSGlMa5Alhgx7J13r+hxo/INS0lp1jRy1dQa7pb7Tr7fPLX6fR6JH78qfXqqg==
528+
"@napi-rs/cli@^3.1.5":
529+
version "3.1.5"
530+
resolved "https://registry.yarnpkg.com/@napi-rs/cli/-/cli-3.1.5.tgz#6c3c297b3b0e7b1ad08393f124e438e8c930dae7"
531+
integrity sha512-Wn6ZPw27qJiEWglGjkaAa70AHuLtyPya6FvjINYJ5U20uvbRhoB0Ta2+bFTAFfUb9R+wvuFvog9JQdy65OmFAQ==
532532
dependencies:
533533
"@inquirer/prompts" "^7.4.0"
534534
"@napi-rs/cross-toolchain" "^1.0.0"

0 commit comments

Comments
 (0)