Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Comprehensive update with documentation, Node.js integration, a… #2585

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@
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 @@
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 @@
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 @@
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 @@
);
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 @@
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 @@
);
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))
);
}
}
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
Loading