Skip to content
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
21 changes: 9 additions & 12 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
[package]

[package]
name = "splitnaira-contracts"
version = "0.1.0"
edition = "2021"
description = "Soroban smart contracts for SplitNaira — royalty splitting on Stellar"
description = "Soroban smart contracts for SplitNaira — royalty splitting on Stellar"
license = "MIT"
repository = "https://github.com/Split-Naira/SplitNaira"

[lib]
crate-type = ["cdylib", "rlib"]
name = "splitnaira_contract"
path = "lib.rs"
crate-type = ["cdylib", "rlib"]

# reliability_tests.rs is registered via #[cfg(test)] mod in lib.rs
# and is automatically included in: cargo test --features testutils
# reliability_tests.rs is registered through #[cfg(test)] in lib.rs.
# Run tests with: cargo test --features testutils
[features]
testutils = ["soroban-sdk/testutils"]

[dependencies]
# Pinned to an exact version to prevent silent breakage from minor/patch bumps.
# Soroban minor versions can change storage cost models, instruction limits, or
# XDR encoding in ways that break deployed contracts.
# To upgrade: test on testnet, update both entries below and Cargo.lock, then
# document the new version in contracts/README.md.
# Keep Soroban SDK pinned to an exact version to avoid unexpected changes
# to contract behavior, storage costs, instruction limits, or XDR encoding.
# When upgrading, update Cargo.lock and validate against testnet.
soroban-sdk = { version = "=20.5.0" }

[dev-dependencies]
Expand All @@ -42,4 +40,3 @@ lto = true
[profile.release-with-logs]
inherits = "release"
debug-assertions = true

58 changes: 39 additions & 19 deletions contracts/scripts/analyze-contract.mjs
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@

#!/usr/bin/env node

/**
* Lightweight static analysis for the SplitNaira Soroban contract.
* Reports public function count, error codes, and event types without
* requiring a live Soroban node.
*
* Usage: node contracts/scripts/analyze-contract.mjs
* Reports the number of public functions, error codes, and event types
* without requiring a live Soroban node.
*
* Usage:
* node contracts/scripts/analyze-contract.mjs
*/

import { readFileSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
const CONTRACT_ROOT = resolve(SCRIPT_DIR, "..");

function read(file) {
return readFileSync(resolve(root, file), "utf8");
/**
* Reads a contract file relative to the contracts directory.
*
* @param {string} file - Relative path to the file to read.
* @returns {string} The file contents as UTF-8 text.
*/
function readContractFile(file) {
const filePath = resolve(CONTRACT_ROOT, file);
return readFileSync(filePath, "utf8");
}

function count(src, re) {
return (src.match(re) ?? []).length;
/**
* Counts matches of a regular expression in a source string.
*
* @param {string} source - Source text to analyze.
* @param {RegExp} pattern - Pattern used to identify matching occurrences.
* @returns {number} The total number of matches.
*/
function countMatches(source, pattern) {
return (source.match(pattern) ?? []).length;
}

const lib = read("lib.rs");
const errors = read("errors.rs");
const events = read("events.rs");
const contractSource = readContractFile("lib.rs");
const errorSource = readContractFile("errors.rs");
const eventSource = readContractFile("events.rs");

const fns = count(lib, /pub fn /g);
const errCodes = count(errors, /= \d+,/g);
const evTypes = count(events, /pub struct /g);
const publicFunctionCount = countMatches(contractSource, /pub fn /g);
const errorCodeCount = countMatches(errorSource, /= \d+,/g);
const eventTypeCount = countMatches(eventSource, /pub struct /g);

console.log("Contract surface analysis");
console.log("Contract Surface Analysis");
console.log("--------------------------");
console.log(`Public functions : ${fns}`);
console.log(`Error codes : ${errCodes}`);
console.log(`Event types : ${evTypes}`);
console.log(`Public functions : ${publicFunctionCount}`);
console.log(`Error codes : ${errorCodeCount}`);
console.log(`Event types : ${eventTypeCount}`);
Loading