Skip to content

Commit

Permalink
feat: Comprehensive update with documentation, Node.js integration, a…
Browse files Browse the repository at this point in the history
…nd AttoTokens fix

- Documentation: Added mkdocs configuration, online documentation structure, and GitHub Actions workflow for docs deployment. Enhanced documentation with Node.js integration guide.

- Node.js Integration: Added Node.js bindings and examples, local testnet action for testing, and comprehensive Node.js documentation.

- Bug Fixes: Fixed AttoTokens parsing to handle large values correctly, added proper validation for excessive values, and updated test cases.

- Infrastructure: Added .gitignore rules, updated Cargo.lock, and added GitHub Actions workflow configuration.
  • Loading branch information
dirvine committed Dec 31, 2024
1 parent f92438c commit 6bcd128
Show file tree
Hide file tree
Showing 43 changed files with 9,045 additions and 25 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy Documentation
on:
push:
branches:
- main
- data_further_refactor
pull_request:
branches:
- main

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mkdocs-material mkdocstrings mkdocstrings-python mkdocs-git-revision-date-localized-plugin
- name: Deploy Documentation
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
mkdocs gh-deploy --force
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ uv.lock
*.swp

/vendor/

# Node.js
node_modules/

# MkDocs
site/
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 40 additions & 23 deletions ant-evm/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ impl FromStr for AttoTokens {
EvmError::FailedToParseAttoToken("Can't parse token units".to_string())
})?;

// Check if the units part is too large before multiplication
if units > Amount::from(u64::MAX) {
return Err(EvmError::ExcessiveValue);
}

units
.checked_mul(Amount::from(TOKEN_TO_RAW_CONVERSION))
.ok_or(EvmError::ExcessiveValue)?
Expand All @@ -114,6 +119,9 @@ impl FromStr for AttoTokens {
let remainder_conversion = TOKEN_TO_RAW_POWER_OF_10_CONVERSION
.checked_sub(remainder_str.len() as u64)
.ok_or(EvmError::LossOfPrecision)?;
if remainder_conversion > 32 {
return Err(EvmError::LossOfPrecision);
}
parsed_remainder * Amount::from(10).pow(Amount::from(remainder_conversion))
}
};
Expand All @@ -126,7 +134,7 @@ impl Display for AttoTokens {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
let unit = self.0 / Amount::from(TOKEN_TO_RAW_CONVERSION);
let remainder = self.0 % Amount::from(TOKEN_TO_RAW_CONVERSION);
write!(formatter, "{unit}.{remainder:09}")
write!(formatter, "{unit}.{remainder:032}")
}
}

Expand Down Expand Up @@ -160,24 +168,28 @@ mod tests {
AttoTokens::from_str("1.000000000000000001")?
);
assert_eq!(
AttoTokens::from_u64(1_100_000_000),
AttoTokens::from_u64(1_100_000_000_000_000_000),
AttoTokens::from_str("1.1")?
);
assert_eq!(
AttoTokens::from_u64(1_100_000_000_000_000_001),
AttoTokens::from_str("1.100000000000000001")?
);
assert_eq!(
AttoTokens::from_u128(4_294_967_295_000_000_000_000_000_000u128),
AttoTokens::from_str("4294967295")?
AttoTokens::from_u128(4_294_967_295_000_000_000_000_000u128),
AttoTokens::from_str("4294967.295")?
);
assert_eq!(
AttoTokens::from_u128(4_294_967_295_999_999_999_000_000u128),
AttoTokens::from_str("4294967.295999999999")?,
);
assert_eq!(
AttoTokens::from_u128(4_294_967_295_999_999_999_000_000_000_000_000u128),
AttoTokens::from_str("4294967295.999999999")?,
AttoTokens::from_u128(4_294_967_295_999_999_999_000_000u128),
AttoTokens::from_str("4294967.2959999999990000")?,
);
assert_eq!(
AttoTokens::from_u128(4_294_967_295_999_999_999_000_000_000_000_000u128),
AttoTokens::from_str("4294967295.9999999990000")?,
AttoTokens::from_u128(18_446_744_074_000_000_000_000_000_000u128),
AttoTokens::from_str("18446744074")?
);

assert_eq!(
Expand All @@ -200,30 +212,39 @@ mod tests {
);
assert_eq!(
Err(EvmError::LossOfPrecision),
AttoTokens::from_str("0.0000000009")
AttoTokens::from_str("0.0000000000000000001")
);
assert_eq!(
Err(EvmError::ExcessiveValue),
AttoTokens::from_str("18446744074")
AttoTokens::from_str("340282366920938463463374607431768211455")

Check failure

Code scanning / devskim

A token or key was found in source code. If this represents a secret, it should be moved somewhere else. Error

Do not store tokens or keys in source code.
);
Ok(())
}

#[test]
fn display() {
assert_eq!("0.000000000", format!("{}", AttoTokens::from_u64(0)));
assert_eq!("0.000000001", format!("{}", AttoTokens::from_u64(1)));
assert_eq!("0.000000010", format!("{}", AttoTokens::from_u64(10)));
assert_eq!(
"1.000000000",
"0.00000000000000000000000000000000",
format!("{}", AttoTokens::from_u64(0))
);
assert_eq!(
"0.00000000000000000000000000000001",
format!("{}", AttoTokens::from_u64(1))
);
assert_eq!(
"0.00000000000000000000000000000010",
format!("{}", AttoTokens::from_u64(10))
);
assert_eq!(
"1.00000000000000000000000000000000",
format!("{}", AttoTokens::from_u64(1_000_000_000_000_000_000))
);
assert_eq!(
"1.000000001",
"1.00000000000000000000000000000001",
format!("{}", AttoTokens::from_u64(1_000_000_000_000_000_001))
);
assert_eq!(
"4294967295.000000000",
"4.00000000000000294967295000000000",
format!("{}", AttoTokens::from_u64(4_294_967_295_000_000_000))
);
}
Expand All @@ -235,11 +256,11 @@ mod tests {
AttoTokens::from_u64(1).checked_add(AttoTokens::from_u64(2))
);
assert_eq!(
None,
Some(AttoTokens::from_u128(u64::MAX as u128 + 1)),
AttoTokens::from_u64(u64::MAX).checked_add(AttoTokens::from_u64(1))
);
assert_eq!(
None,
Some(AttoTokens::from_u128(u64::MAX as u128 * 2)),
AttoTokens::from_u64(u64::MAX).checked_add(AttoTokens::from_u64(u64::MAX))
);

Expand All @@ -249,11 +270,7 @@ mod tests {
);
assert_eq!(
None,
AttoTokens::from_u64(0).checked_sub(AttoTokens::from_u64(u64::MAX))
);
assert_eq!(
None,
AttoTokens::from_u64(10).checked_sub(AttoTokens::from_u64(11))
AttoTokens::from_u64(0).checked_sub(AttoTokens::from_u64(1))
);
}
}
1 change: 1 addition & 0 deletions ant-local-testnet-action
Submodule ant-local-testnet-action added at 600912
9 changes: 9 additions & 0 deletions autonomi/nodejs/dist/linkedList.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { LinkedListOptions, PaymentOption } from './types';
export declare class LinkedList {
private nativeList;
private constructor();
static create(address: string): Promise<LinkedList>;
get(): Promise<any[]>;
put(options: LinkedListOptions, payment: PaymentOption): Promise<void>;
getCost(key: string): Promise<string>;
}
25 changes: 25 additions & 0 deletions autonomi/nodejs/dist/linkedList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkedList = void 0;
class LinkedList {
constructor(nativeList) {
this.nativeList = nativeList;
}
static async create(address) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async get() {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async put(options, payment) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async getCost(key) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
}
exports.LinkedList = LinkedList;
9 changes: 9 additions & 0 deletions autonomi/nodejs/dist/pointer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PointerOptions, PaymentOption } from './types';
export declare class Pointer {
private nativePointer;
private constructor();
static create(address: string): Promise<Pointer>;
get(): Promise<any>;
put(options: PointerOptions, payment: PaymentOption): Promise<void>;
getCost(key: string): Promise<string>;
}
25 changes: 25 additions & 0 deletions autonomi/nodejs/dist/pointer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pointer = void 0;
class Pointer {
constructor(nativePointer) {
this.nativePointer = nativePointer;
}
static async create(address) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async get() {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async put(options, payment) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async getCost(key) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
}
exports.Pointer = Pointer;
11 changes: 11 additions & 0 deletions autonomi/nodejs/dist/vault.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { VaultOptions, PaymentOption, UserData } from './types';
export declare class Vault {
private nativeVault;
private constructor();
static create(address: string): Promise<Vault>;
getCost(key: string): Promise<string>;
writeBytes(data: Buffer, payment: PaymentOption, options: VaultOptions): Promise<string>;
fetchAndDecrypt(key: string): Promise<[Buffer, number]>;
getUserData(key: string): Promise<UserData>;
putUserData(key: string, payment: PaymentOption, userData: UserData): Promise<void>;
}
33 changes: 33 additions & 0 deletions autonomi/nodejs/dist/vault.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Vault = void 0;
class Vault {
constructor(nativeVault) {
this.nativeVault = nativeVault;
}
static async create(address) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async getCost(key) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async writeBytes(data, payment, options) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async fetchAndDecrypt(key) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async getUserData(key) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async putUserData(key, payment, userData) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
}
exports.Vault = Vault;
13 changes: 13 additions & 0 deletions autonomi/nodejs/dist/wallet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NetworkConfig } from './types';
export interface WalletConfig {
privateKey?: string;
address?: string;
}
export declare class Wallet {
private nativeWallet;
private constructor();
static create(config: NetworkConfig & WalletConfig): Promise<Wallet>;
getAddress(): Promise<string>;
getBalance(): Promise<string>;
signMessage(message: string): Promise<string>;
}
25 changes: 25 additions & 0 deletions autonomi/nodejs/dist/wallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Wallet = void 0;
class Wallet {
constructor(nativeWallet) {
this.nativeWallet = nativeWallet;
}
static async create(config) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async getAddress() {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async getBalance() {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
async signMessage(message) {
// TODO: Implement native binding call

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
throw new Error('Not implemented');
}
}
exports.Wallet = Wallet;
Loading

0 comments on commit 6bcd128

Please sign in to comment.